Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Your PHP Can Fly

Your PHP Can Fly

Control your AR Drone over PHP. Forum PHP 2013

https://github.com/jolicode/php-ar-drone
http://joind.in/talk/view/9361

Baptiste Adrien

November 22, 2013
Tweet

Other Decks in Technology

Transcript

  1. $readble = array($stream1, $stream2); $writable = array($stream3, $stream4); $except =

    null; if (stream_select($read, $write, $except, 1)) { if ($readble) { foreach ($readble as $stream) { // process } } if ($writable) { foreach ($writable as $stream) { // process } } }
  2. $loop = React\EventLoop\Factory::create(); $socket = new React\Socket\Server($loop); $socket->on('connection', function ($conn)

    { $conn->write(’Hello ForumPHP!\n’); $conn->on('data', function ($data) use ($conn) { // Awesome instructions }); }); $socket->listen(1337); $loop->run() SERVEuR
  3. HEADER DRONE STATE SEQUENCE NUMBER VISION FLAG CHECKSUM OPTION 1

    OPTION 2 OPTION n... Les options contiennent des informations sur l’état de l’AR Drone. Chaque option est définie par un type et des valeurs. Exemple de type: - rawMeasures - visionDetect - winSpeed - videoStream
  4. unpack uint32 uint16 float32 ... HEADER DRONE STATE SEQUENCE NUMBER

    OPTION 1 VISION FLAG CHECKSUM ... ... ID SIZE DATA ID SIZE DATA ... ... ... ... int. 32 int. 32 int. 32 int. 32 int. 16 int. 16 int. 16 int. 16 int. 16 $header = unpack('V/', substr ($incomingData , 0, 4)); / / 0x55667788 $droneState = unpack('V/', substr ($incomingData , 4, 8)); $sequenceNumber = unpack('V/', substr ($incomingData , 8, 12)); $visionFlag= unpack('V/', substr ($incomingData , 12, 16)); $idOption1 = unpack('v/', substr ($incomingData , 12, 14)); $sizeOption1 = unpack('v/', substr ($incomingData , 14, 16)); ...
  5. // Décalage à gauche utile pour les masques binaires $droneStateMasks

    = array( 'flying' => (1 << 0), 'videoEnabled' => (1 << 1), 'visionEnabled' => (1 << 2), 'controlAlgorithm' => (1 << 3), 'altitudeControlAlgorithm' => (1 << 4), 'startButtonState' => (1 << 5), 'controlCommandAck' =>(1 << 6), 'cameraReady' =>(1 << 7) ); $videoIsEnable = ($droneState & $droneStateMasks[1]) ? 1 : 0; & et << pour gérer les états & | ^ ~ << >> AND OR XOR NOT LEFT SHIFT RIGHT SHIFT
  6. PERMET DE FAIRE DECOLLER & ATTERRIR LE DRONE Argument 1

    : Sequence Number Argument 2 : Integer représentant un champ de 32 bits; Lorsque bit 9 = 0 : Atterrissage Lorsque bit 9 = 1 : Décollage $ref = 0; $ref = $ref | (1 << 9); // 512 -> 1000000000 $client->send(”AT*REF=1,$ref”); // Décollage ! AT*REF=%d, %d
  7. AT*PCMD=%d,%d,%d,%d,%d,%d PERMET DE CONTROLER LES MOUVEMENTS DU DRONE Argument 1:

    Sequence Number Argument 2: Commande progressive Argument 3: Droite / gauche Argument 4: Avant / arrière Argument 5: Haut / bas Argument 6: Rotation Arguments 3 à 6 de type Float [−1..1] (orientation + vitesse)