head	1.2;
access;
symbols;
locks
	root:1.2; strict;
comment	@# @;


1.2
date	2024.10.02.00.52.06;	author root;	state Exp;
branches;
next	1.1;

1.1
date	2024.10.02.00.51.30;	author root;	state Exp;
branches;
next	;


desc
@original. newer version available.
-bert
@


1.2
log
@as i found it.
replacing Navbar::default function to newer one
-bert
@
text
@#!/usr/bin/perl

use lib qw (/var/www/www.rcflightpath.com/lib);
use POSIX qw(strftime);
use CGI qw(:standard :html3 :all *table *Tr *td unescape);
use CGI::Cookie;

use Templates::Navbar;
use Templates::Header;
use Templates::Footer;

my $cgi      = CGI->new;
my $mode     = param('save') || param('clear');
$pterm       = param('pterm');
$iterm       = param('iterm');
$dterm       = param('dterm');
$observation = param('observation');
$ratio       = $pterm.':'.$dterm;
$title       = 'PID Tuning Logger';
$filepath    = '/var/www/www.rcflightpath.com/articles/pid-tuning/rotorflight/test.cgi';

if (-e 'style.css') {
  $style = 'style.css';
} elsif (-e '../style.css') {
  $style = '../style.css';
} elsif (-e '../../style.css') {
  $style = '../../style.css';
} else {
  $style = '/style.css';
}

if (($mode eq 'save')&&($pterm)&&($iterm)&&($dterm)&&($observation)) {
  my $new_cookie = CGI::Cookie->new(
      -name => "$pterm:$iterm:$dterm",
      -value => $observation,
      -expires => '+1y'
  );
  print $cgi->header(-cookie => [$new_cookie]);
} elsif (($mode eq 'clear')&&($ratio)) {
  my $new_cookie = CGI::Cookie->new(
      -name => "$pterm:$iterm:$dterm",
      -value => '',
      -expires => '-1d'
  );
  print $cgi->header(-cookie => [$new_cookie]);
} else {
  print header;
}

print  start_html(
         -title=> $title,
         -style=> {'src' => $style},
         -meta=>  {'viewport'=>'width=device-width, initial-scale=1.0','description'=>$page_desc,'keywords'=>$keywords}
       ),"\n";

print start_table({-border=>0,-margin=>0,-topmargin=>0,-cellpadding=>0,-cellspacing=>0,-width=>900}),"<!-- START MAIN TABLE -->\n",
       start_Tr,"<!-- START HEADER -->\n",
        start_td({-colspan=>2}),"\n";
         Header::print_titlebar($title,$filepath,'FFFFFF');
print   end_td,"\n",
       end_Tr,"<!-- END HEADER -->\n",
       start_Tr,"<!-- START NAVBAR -->\n",
        start_td({-valign=>'top',-rowspan=>3}),"\n";
         Navbar::default('pid');
print   end_td,"<!-- END NAVBAR -->\n",
        start_td({-valign=>'top'}),div({-id=>'main'}),"<!-- START CONTENT -->\n";
         &print_content;
print   end_td,"\n",
       end_Tr,"<!-- END CONTENT -->\n",
       start_Tr,"<!-- START FOOTER -->\n",
        start_td({-align=>'center'}),"\n";
         Footer::print_footer;
print   end_td,"\n",
       end_Tr,"<!-- END FOOTER -->\n",
      end_table,"<!-- END MAIN TABLE -->\n",
     end_html;

sub print_content {
  print h2('PID Ratio Behavior Records'),font({-color=>'red',-size=>'+1'},'<B>Purpose:</b> For keeping track of behaviors of PID combinations used'),"\n",
        h3('Function:'),"\n",
        'Your entry will be recorded (for your record - so as not to repeat the same or similar ratio) and evaluated by this program and given an advisory if appropriate. The main purpose is to keep track of PID ratios you have already tried',p,
        h3('Instructions:'),"\n",
        'After a flight, enter your P-Term, I-Term, and D-Term for that flight into the boxes below (Left) and then enter your observations during the flight test. Keywords to use in your "Observation" (to invoke the advisory) are:',"\n",
        ul(
         li('"slow/lazy response"'),"\n",
         li('"slow/fast oscillation"'),"\n",
         li('"shudders at end of maneuver"'),"\n",
         li('"slow/lazy stops"'),"\n",
         li('"bounce after manuever"'),"\n",
         li('"does not feel locked in"'),"\n",
        ),
        p,
        start_table({-border=>1,-cellpadding=>5}),"\n",
        start_form({-action=>'index.cgi',-method=>'post',-enctype=>'multipart/form-data'}),"\n",
         Tr(th('&nbsp;'),th('Observation')),"\n",
         Tr(
          td({-align=>'right'},
           b('P'),textfield({-size=>1,-value=>$param_values{'pterm'},-name=>'pterm'}),br,
           b('I'),textfield({-size=>1,-value=>$param_values{'iterm'},-name=>'iterm'}),br,
           b('D'),textfield({-size=>1,-value=>$param_values{'dterm'},-name=>'dterm'}),br,
          ),"\n",
          td(
           textfield({-size=>51,,-value=>$param_values{'observation'},-name=>'observation'})
          ),"\n",
         ),"\n",
         Tr(td({-colspan=>2,-align=>'center'},input({-type=>'submit',-name=>'save',-value=>'save'}),input({-type=>'submit',-name=>'clear',-value=>'clear'}))),"\n",
        end_table,"\n",
        end_form;
  print br,hr,br,"\n",
        start_table({-border=>1,-width=>528}),"\n",
        Tr(th({-colspan=>2},'Your Log'),th('Advisory'));
  my $cgi     = CGI->new;
  my %cookies = CGI::Cookie->fetch;
  $keys = keys(%cookies);
  if ($keys) {
    foreach (sort keys %cookies) {
      $cookie_value = cookie($_);
      $comment = unescape($cookie_value);
      if ($comment =~ /(high.*|fast.*)oscillation/i) {
      $advisory = 'try lowering your P-Term';
      } elsif ($comment =~ /(slow.*)(.*oscillation)/i) {
        $advisory = 'lower your I-Term. If not, your P-Term. It can also be mechanical';
      } elsif ($comment =~ /(shudder)/) {
        $advisory = '<li>Increase the D-Term<li>Reduce the P-term<li>Reduce FF';
      } elsif ($comment =~ /(bounce)/) {
        $advisory = '<li>bounces indicate an adjustment needed on D-term or Feed Forward<li>Increase D-term slightly (5-10 units)<li>Reduce Feed Forward slightly (5-10 units).<li>setup 3 profiles with the original, one w/higher D, and one w/lower FF';
      } elsif ($comment =~ /(not.*|lock.*)/) {
        $advisory = 'try raising your I-Term';
      } elsif ($comment =~ /(respon.*|slow.*|lazy.*)(.*respon|.*slow)/i) {
        $advisory = 'try raising your P-Term';
      } elsif ($comment =~ /(not.*|slow.*)stop(.*enough)/i) {
        $advisory = 'try raising both your P-Term and D-Term';
      } else {
        $advisory = '&nbsp;';
      }
      next if ($_ !~ /^\d+/);
      ($pterm,$iterm,$dterm) = split/\:/,$_;
      print Tr(td("P=$pterm/I=$iterm/D=$dterm"),td($comment),td($advisory)),"\n";
    }
  }
  print end_table,"\n\n";
  print br,br,br,hr,"\n",
        b('Debug Info:'),"\n",
         ul(
          li("mode=$mode"),"\n",
          li("pterm=$pterm"),"\n",
          li("dterm=$dterm"),"\n",
          li("ratio=$ratio"),"\n",
          li("observation=$observation"),"\n",
         );
}
@


1.1
log
@Initial revision
@
text
@d3 1
d8 9
a16 5
my $cgi = CGI->new;

my $mode = param('save') || param('clear');
$antecedent  = param('antecedent');
$consequent  = param('consequent');
d18 3
a20 9
$ratio = $antecedent.':'.$consequent;

$user_agent = user_agent();
$logo_font1 = '353535';
$logo_font2 = 'FFB400';
$filepath = '/var/www/www.rcflightpath.com/articles/pid-tuning/index.cgi';
$page_desc = 'HTML TAGS HERE';

charset('UTF-8');
d24 4
d32 17
d51 56
a106 76
          -title => "$title",
          -style => {'src' => $style},
          -meta=> {'viewport'=>'width=device-width, initial-scale=1.0','description'=>$page_desc}
        );

# TOP TITLE AREA

  my $mod_time = (stat($filepath))[9];
  my ($sec, $min, $hour, $mday, $mon, $year) = localtime($mod_time);

  @@months = qw /null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
  $mon++;  # Adjust month (0-based index)
  $year += 1900; chomp $year; # Adjust year (start from 1900)
  $ampm = 'a.m.';
  $ampm = 'p.m.' if ($hour > 11);
  $hour = '0'.$hour if ($hour < 10);
  $min  = '0'.$min if ($min < 10);

  print start_table({-border=>0,-cellpadding=>0,-cellspacing=>0,-topmargin=>0,-width=>'70%'}), # MAIN TABLE
          start_Tr,
            start_td({-colspan=>2}),
              div({-id=>'title'},
                center(
                  table({-border=>0,-width=>'100%',-background=>'/images/bg.png'}, # TITLE TABLE
                    Tr(
                      td({-align=>'center',-width=>180},
                        a({-href=>'/'},img({-border=>0,-height=>80,-width=>180,src=>'/images/logo6.png'}))),
                      td({-align=>'center'},
                        h1("<b><font color=white>RC</font> <font color=$logo_font2>FlightPath - $title</b>"),
                      ),
                    Tr(
                      td({-colspan=>2,-align=>'right'},font({-color=>'white'},"Updated: $months[$mon] $mday, $year @@ $hour:$min $ampm")),
                      )
                    )
                  )
                ),
              ),
            end_td, 
          end_Tr;

# LEFT SIDE NAVIGATION

  print start_Tr,
         start_td({-valign=>'top',-width=>220,-bgcolor=>'#B1A296'}), # NAVBAR HERE
          p,br,
          div({-id=>'navigation'}),
            div({-class=>'button'}),
              dd(a({-id=>'link1',-class=>'button',-onclick=>'activateButton(this)',-href=>'rotorflight?topic=start'},'PID Tuning RotorFlight')),
              dd(a({-id=>'link2',-class=>'button',-onclick=>'activateButton(this)',-href=>'/heli/configs/index.cgi?mode=pidwiz'},'PID Tuning iKON')),
              dd(a({-id=>'link2',-class=>'button',-onclick=>'activateButton(this)',-href=>'rotorflight/field_reports'},'Tuning Field Reports')),
              dd(a({-id=>'link2',-class=>'button',-onclick=>'activateButton(this)',-href=>'rotorflight/compare'},'Compare RF Configs')),
              dd(a({-id=>'link2',-class=>'button',-onclick=>'activateButton(this)',-href=>'rotorflight/dump'},'Compare RF Profiles')),
           "<script>\n
            function activateButton(button) {\n
             // Remove active class from all buttons\n
             var buttons = document.querySelectorAll('.button');\n
             buttons.forEach(function(btn) {\n
             btn.classList.remove('button-active');\n
            });\n
            // Add active class to the clicked button\n
               button.classList.add('button-active');\n
            }\n
           </script>\n";
         end_td;


# MAIN PAGE SECTION

  print start_td({-bgcolor=>'#EEE2DC',-valign=>'top'}),
        "<div id='main'>\n";

  &print_content;

  print "</div>\n",
        end_td,"\n",
        end_Tr,"\n",
d108 44
a151 1
        end_html;
@
