Commit 099a66d6 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

tested both directions

parent 7379a2c1
Loading
Loading
Loading
Loading
+35 −23
Original line number Diff line number Diff line
@@ -25,7 +25,12 @@ $LATE_STOP_AZ = 30; // steps
// Rescan azimuth after noticed a satellite during area scan
$AZ_PLAY = 1.0;         // Hysteresis caused by mechanical play (degrees)
$AZ_RESCAN = 8;         // (degrees) around expected center
$AZ_RESCAN_STEP = 0.25; // (degrees)
$AZ_RESCAN_STEP = 0.5; // (degrees)

$EL_PLAY = 1.0;         // Hysteresis caused by mechanical play (degrees)
$EL_RESCAN = 8;         // (degrees) around expected center
$EL_RESCAN_STEP = 0.5; // (degrees)

$USABLE_FRACT =   0.6;  // use ony samples not less than this fraction of maximal
$USABLE_POW =     1.0;  // transform (maxstrengh - strengh) by applying pow - 1.2 ...1.3 may have marginal improvements
$ARGMAX_OURSIDE = 0.2;  // Allow  argmax outside of the measured range by this fraction 
@@ -98,8 +103,12 @@ if ($scan_mode){
    $Success =       $xml_state->Success;
    
    if (intval ($Success)){
        peakAzimuth($xml_state, $AZ_PLAY,$AZ_RESCAN, $AZ_RESCAN_STEP, $USABLE_FRACT, $USABLE_POW, $ARGMAX_OURSIDE);
        $Success = peakAzimuthOrElevation($xml_state, 0, $AZ_PLAY,$AZ_RESCAN, $AZ_RESCAN_STEP, $USABLE_FRACT, $USABLE_POW, $ARGMAX_OURSIDE);
        $xml_state = simplexml_load_file($motosat_url);
        if (intval ($Success)){
            $Success = peakAzimuthOrElevation($xml_state, 1, $EL_PLAY,$EL_RESCAN, $EL_RESCAN_STEP, $USABLE_FRACT, $USABLE_POW, $ARGMAX_OURSIDE);
            $xml_state = simplexml_load_file($motosat_url);
        }
    }
    
    $xml = new SimpleXMLElement("<?xml version='1.0'?><motosat/>");
@@ -147,61 +156,64 @@ header('Access-Control-Allow-Origin: *');
printf($rslt);
exit (0);

function peakAzimuth($xml_state, $az_play,$az_range, $az_step, $fract, $pow = 1.0, $argmax_outside=0.2){
function peakAzimuthOrElevation($xml_state, $el_not_az, $azel_play, $azel_range, $azel_step, $fract, $pow = 1.0, $argmax_outside=0.2){
    global $motosat_url, $dbg_file;
    if ($xml_state === null){
        $xml_state = simplexml_load_file($motosat_url);
    }
    $DishAngle =  getDishAngles ($xml_state);
    $az_start_center = $DishAngle[0];
    $motor =     $el_not_az ? 1: 0; 
    $direction = $el_not_az ? "ELEVATION" : "AZIMUTH";
    
    $azel_start_center = $DishAngle[$motor];
    //move to sart rescan azimuth minus mechanical play
    $DishAngle[0] = $az_start_center - $az_play - $az_range/2;
    $DishAngle[$motor] = $azel_start_center - $azel_play - $azel_range/2;
    moveElAzSk_degrees($DishAngle);
    $scan_strengths = Array();
    for ($az = $az_start_center - $az_range/2;
         $az < ($az_start_center + $az_range/2 + $az_step);
         $az += $az_step){
             $DishAngle[0] = $az;
    for ($azel = $azel_start_center - $azel_range/2;
         $azel < ($azel_start_center + $azel_range/2 + $azel_step);
         $azel += $azel_step){
             $DishAngle[$motor] = $azel;
             moveElAzSk_degrees($DishAngle); // to be on the safe side re-read xml
             $modem_strength= getModemStrength();
             $scan_strengths[] = $modem_strength;
     }
     if ($dbg_file !== null) {
        fprintf($dbg_file, "==== Azimuth scan strengths: ====\n");
        fprintf($dbg_file, "==== $direction scan strengths: ====\n");
        fprintf($dbg_file, print_r($scan_strengths, 1));
     }
     $rel_argmax = findMax1d($scan_strengths, $fract, $pow, $argmax_outside);
    if ($rel_argmax !== null) {
        $az_argmax = $az_start_center - $az_range / 2 + $az_step * $rel_argmax;
        $azel_argmax = $azel_start_center - $azel_range / 2 + $azel_step * $rel_argmax;
        if ($dbg_file !== null) {
            fprintf($dbg_file, "reltive argmax = %f\n", $rel_argmax);
            fprintf($dbg_file, "azimuth argmax = %f (was %f)\n", $az_argmax, $az_start_center);
            fprintf($dbg_file, "$direction argmax = %f (was %f)\n", $azel_argmax, $azel_start_center);
        }
        $DishAngle[0] = $az_argmax - $az_play;
        $DishAngle[$motor] = $azel_argmax - $azel_play;
        if ($dbg_file !== null) {
            fprintf($dbg_file, "====== Moving azimuth to compensate motor play to = %f\n", $DishAngle[0]);
            fprintf($dbg_file, "====== Moving $direction to compensate motor play to = %f\n", $DishAngle[$motor]);
        }
        
        moveElAzSk_degrees($DishAngle);
        $DishAngle[0] = $az_argmax;
        $DishAngle[$motor] = $azel_argmax;
        if ($dbg_file !== null) {
            fprintf($dbg_file, "====== Moving azimuth to argmax position = %f\n", $DishAngle[0]);
            fprintf($dbg_file, "====== Moving $direction to argmax position = %f\n", $DishAngle[$motor]);
        }
        moveElAzSk_degrees($DishAngle);
        return 1; // success
    } else {
        // for now - move back
        if ($dbg_file !== null) {
            fprintf($dbg_file, "****** Failed to find maximum, going to known position.\n");
            fprintf($dbg_file, "****** Failed to find maximum for $direction, going to known position.\n");
        }
        $DishAngle[0] = $az_start_center;
        $DishAngle[$motor] = $azel_start_center;
        moveElAzSk_degrees($DishAngle);
        return 0; // failed
    }
}



     return;
}

function findMax1d($data, $fract, $pow, $frac_outside = 0.2){
    global $dbg_file;
    $min= $data[0];