Beispiel #1
0
function stop()
{
    global $serial, $DIYleftWheel, $sensors;
    //chamilonoume tachitita
    $rodastop = $GLOBALS['DIYrodastop'];
    $curmove = findregisterMove();
    if ($curmove == 'w') {
        echo "chamilono tachitita w{$rodastop}:{$rodastop} ";
        $exec = '@w' . $rodastop . ':' . $rodastop . '#';
    } elseif ($curmove == 's') {
        echo "chamilono tachitita s{$rodastop}:{$rodastop} ";
        $exec = "@s{$rodastop}:{$rodastop}#";
    } elseif ($curmove == 'a') {
        echo "chamilono tachitita a{$rodastop}:{$rodastop} ";
        $exec = "@a{$rodastop}:{$rodastop}#";
    } elseif ($curmove == 'd') {
        echo "chamilono tachitita d{$rodastop}:{$rodastop} ";
        $exec = "@d{$rodastop}:{$rodastop}#";
    }
    $serial->deviceOpen();
    $serial->sendMessage($exec);
    $serial->deviceClose();
    echo $DIYleftWheel;
    echo " sssssssssssssssssssdsdsdfgdfghgfhgfhjfgf\n";
    if ($curmove != 'q' || $curmove != '0') {
        while ($DIYleftWheel == 0) {
            sleep(0.5);
            echo 'sleeping...' . "\n";
            refreshDIYData($sensors);
        }
        registerMove('q');
        echo " parking ";
        $exec = "@q#";
        $serial->deviceOpen();
        $serial->sendMessage($exec);
        $serial->deviceClose();
    }
}
    $result = stream_select($read, $write, $except, 0);
    if ($result === false) {
        throw new Exception('stream_select failed');
    }
    if ($result === 0) {
        return false;
    }
    $data = stream_get_line($fd, 1);
    return true;
}
$flag = 1;
while (!feof($sensors)) {
    $x = "";
    if (non_block_read(STDIN, $x) && $x == 'q' || trim(file_get_contents('/tmp/controller.run')) != '1') {
        //stop();
        $exec = '@q#';
        $serial->deviceOpen();
        //  sleep(0.5);
        $serial->sendMessage($exec);
        // sleep(0.1);
        $serial->deviceClose();
        //    sleep(1);
        //sleep(1);
        break;
    }
    // Quit on F10
    //sleep(0.01);
    refreshDIYData($sensors);
    carscript();
}
echo "Main loop broke";
function rotate($m, $d)
{
    global $serial, $DIYleftWheel, $sensors, $imu, $curDirection, $head;
    if ($curDirection != 'a' || $curDirection != 'd') {
        echo "Rotate\n";
        stop();
        sleep(0.01);
        if ($curDirection == 'a') {
            $wantedMoires = $head - $m;
        } else {
            $wantedMoires = $head + $m;
        }
        $curDirection = $d;
        if ($wantedMoires < 0) {
            $wantedMoires = 360 + $wantedMoires;
        }
        //sleep(0.01);
        $exec = "@a060:063#";
        $serial->deviceOpen();
        $serial->sendMessage($exec);
        $serial->deviceClose();
        while (!($wantedMoires - 2 <= $head && $head <= $wantedMoires + 2)) {
            refreshDIYData($sensors, $imu);
            echo " wanted moires {$wantedMoires}  head {$head}  \n";
        }
        stop();
        sleep(0.01);
    }
}