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. BAPTISTE ADRIEN
    @SHINEWORK

    View full-size slide

  2. SOCKETUDP
    TCP
    PHP
    STREAM react
    EVENT
    DRONE
    Parrot

    View full-size slide

  3. COUCHES
    HAUTES
    COUCHES
    MATERIELLES
    PHYSIQUE
    RESEAU
    TRANSPORT
    SESSION
    PRESENTATION
    APPLICATION
    LIAISON DE DONNEES

    View full-size slide

  4. connecté non connecté

    View full-size slide

  5. HTTP
    SOCKET
    STREAM
    EVENT LOOP

    View full-size slide

  6. $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
    }
    }
    }

    View full-size slide

  7. Event Loop Component
    readable stream
    WRITABLE STREAM
    stream_select()

    View full-size slide

  8. $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

    View full-size slide

  9. $loop = React\EventLoop\Factory::create();
    $udpFactory = new Datagram\Factory($loop);
    $udpFactory->createClient($ip, $port)->then(function ($client) {
    $client->send(’Coucou !’);
    });
    $loop->run()
    CLIENT

    View full-size slide

  10. ACCéLéROMETRE
    caméras
    GYROSCOPES
    Magnétometre
    barometre
    E/R ULTRASONS
    SYSTeme embarqué

    View full-size slide

  11. NAVDATA
    CONTROL
    VIDEO
    CONFIG
    UDP
    TCP
    CLIENT SERVEUR

    View full-size slide

  12. 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

    View full-size slide

  13. 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));
    ...

    View full-size slide

  14. // 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

    View full-size slide

  15. AT*=, ,, ...
    PERMET D'ENVOYER DES INSTRUCTIONS DE
    CONTROLE SUR LE PORT UDP 5554 DE L'AR DRONE
    AT*REF
    AT*PCMD
    AT*CONFIG
    TYPES

    View full-size slide

  16. 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

    View full-size slide

  17. 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)

    View full-size slide

  18. DEMO
    TIME
    https://github.com/jolicode/php-ar-drone

    View full-size slide

  19. github.com/jolicode/php-ar-drone
    MERCI ! question ?
    speakerdeck.com/shinework/
    [email protected]
    PROJETS
    DES
    COOL ?
    @SHINEWORK
    joind.in/talk/view/9361
    FEED
    BACK
    SLIDES
    CODE !

    View full-size slide