Merge pull request #4 from abarbier/master
Update with the react/datagram instead of clue/datagram
Esse commit está contido em:
+5
-2
@@ -6,8 +6,11 @@
|
||||
"homepage": "https://github.com/jolicode/php-ar-drone",
|
||||
"keywords": ["ar-drone", "parrot", "react", "socket"],
|
||||
"require": {
|
||||
"clue/datagram": "0.3.*",
|
||||
"react/socket-client": "0.3.*@dev"
|
||||
"react/socket-client": "0.3.*@dev",
|
||||
"react/socket" : "0.3.*",
|
||||
"react/dns" : "0.3.*",
|
||||
|
||||
"react/datagram" : "v1.0.0"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ use Joli\ArDrone\Control\UdpControl;
|
||||
use Joli\ArDrone\Navdata\Frame;
|
||||
use Joli\ArDrone\Navdata\UdpNavdata;
|
||||
use React\EventLoop\Factory AS LoopFactory;
|
||||
use Datagram\Factory AS UdpFactory;
|
||||
use React\Datagram\Factory AS UdpFactory;
|
||||
use Joli\ArDrone\Config\Config;
|
||||
|
||||
class Client extends EventEmitter {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Joli\ArDrone\Control;
|
||||
|
||||
use Evenement\EventEmitter;
|
||||
use Joli\ArDrone\Config\Config;
|
||||
use Datagram\Factory AS UdpFactory;
|
||||
use Datagram\Socket AS UdpSocket;
|
||||
use React\Datagram\Factory AS UdpFactory;
|
||||
use React\Datagram\Socket AS UdpSocket;
|
||||
|
||||
class UdpControl extends EventEmitter {
|
||||
class UdpControl extends EventEmitter
|
||||
{
|
||||
/**
|
||||
* @var \React\EventLoop\StreamSelectLoop
|
||||
*/
|
||||
@@ -42,7 +44,7 @@ class UdpControl extends EventEmitter {
|
||||
$loop = $this->loop;
|
||||
$udpControl = $this;
|
||||
|
||||
$udpFactory->createClient($this->ip, $this->port)->then(function (UdpSocket $client) use (&$loop, $udpControl) {
|
||||
$udpFactory->createClient($this->ip.':'.$this->port)->then(function (UdpSocket $client) use (&$loop, $udpControl) {
|
||||
$commandCreator = $udpControl->commandCreator;
|
||||
$ref = $udpControl->ref;
|
||||
$pcmd = $udpControl->pcmd;
|
||||
@@ -52,10 +54,12 @@ class UdpControl extends EventEmitter {
|
||||
$client->send('1');
|
||||
$client->send('1');
|
||||
|
||||
for($j = 0; $j < 5; $j++) {
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
$cmds = array();
|
||||
|
||||
array_push($cmds, $commandCreator->createConfigCommand('general:navdata_demo', 'TRUE'));
|
||||
array_push($cmds,
|
||||
$commandCreator->createConfigCommand('general:navdata_demo',
|
||||
'TRUE'));
|
||||
array_push($cmds, $commandCreator->createPcmdCommand($pcmd));
|
||||
array_push($cmds, $commandCreator->createRefCommand($ref));
|
||||
|
||||
@@ -66,16 +70,19 @@ class UdpControl extends EventEmitter {
|
||||
|
||||
// According to tests, a satisfying control of the AR.Drone 2.0 is reached
|
||||
// by sending the AT-commands every 30 ms for smooth drone movements.
|
||||
$loop->addPeriodicTimer(0.03, function() use ($client, $commandCreator, &$ref, &$pcmd, &$anim) {
|
||||
$loop->addPeriodicTimer(0.03,
|
||||
function() use ($client, $commandCreator, &$ref, &$pcmd, &$anim) {
|
||||
$cmds = array();
|
||||
|
||||
array_push($cmds, $commandCreator->createRefCommand($ref));
|
||||
array_push($cmds, $commandCreator->createPcmdCommand($pcmd));
|
||||
|
||||
if(count($anim) > 0) {
|
||||
for($i = 0; $i <= 10; $i++) {
|
||||
foreach($anim as $name => $duration) {
|
||||
array_push($cmds, $commandCreator->createConfigCommand($name, $duration));
|
||||
if (count($anim) > 0) {
|
||||
for ($i = 0; $i <= 10; $i++) {
|
||||
foreach ($anim as $name => $duration) {
|
||||
array_push($cmds,
|
||||
$commandCreator->createConfigCommand($name,
|
||||
$duration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,67 +94,80 @@ class UdpControl extends EventEmitter {
|
||||
});
|
||||
|
||||
|
||||
$udpControl->on('land', function() use (&$ref, &$pcmd) {
|
||||
$pcmd = array();
|
||||
$udpControl->on('land',
|
||||
function() use (&$ref, &$pcmd) {
|
||||
$pcmd = array();
|
||||
$ref['fly'] = false;
|
||||
});
|
||||
|
||||
$udpControl->on('ftrim', function() use (&$client, &$commandCreator) {
|
||||
$udpControl->on('ftrim',
|
||||
function() use (&$client, &$commandCreator) {
|
||||
$client->send($commandCreator->createFtrimCommand());
|
||||
});
|
||||
|
||||
$udpControl->on('takeoff', function() use (&$ref, &$pcmd) {
|
||||
$pcmd = array();
|
||||
$udpControl->on('takeoff',
|
||||
function() use (&$ref, &$pcmd) {
|
||||
$pcmd = array();
|
||||
$ref['fly'] = true;
|
||||
});
|
||||
|
||||
$udpControl->on('clockwise', function($speed = 0.5) use (&$pcmd) {
|
||||
$udpControl->on('clockwise',
|
||||
function($speed = 0.5) use (&$pcmd) {
|
||||
$pcmd['clockwise'] = $speed;
|
||||
unset($pcmd['counterClockwise']);
|
||||
});
|
||||
|
||||
$udpControl->on('counterClockwise', function($speed = 0.5) use (&$pcmd) {
|
||||
$udpControl->on('counterClockwise',
|
||||
function($speed = 0.5) use (&$pcmd) {
|
||||
$pcmd['counterClockwise'] = $speed;
|
||||
unset($pcmd['clockwise']);
|
||||
});
|
||||
|
||||
$udpControl->on('stop', function() use (&$pcmd) {
|
||||
$udpControl->on('stop',
|
||||
function() use (&$pcmd) {
|
||||
$pcmd = array();
|
||||
});
|
||||
|
||||
$udpControl->on('front', function($speed = 0.3) use (&$pcmd) {
|
||||
$udpControl->on('front',
|
||||
function($speed = 0.3) use (&$pcmd) {
|
||||
$pcmd['front'] = $speed;
|
||||
unset($pcmd['back']);
|
||||
});
|
||||
|
||||
$udpControl->on('back', function($speed = 0.3) use (&$pcmd) {
|
||||
$udpControl->on('back',
|
||||
function($speed = 0.3) use (&$pcmd) {
|
||||
$pcmd['back'] = $speed;
|
||||
unset($pcmd['front']);
|
||||
});
|
||||
|
||||
$udpControl->on('right', function($speed = 0.3) use (&$pcmd) {
|
||||
$udpControl->on('right',
|
||||
function($speed = 0.3) use (&$pcmd) {
|
||||
$pcmd['right'] = $speed;
|
||||
unset($pcmd['left']);
|
||||
});
|
||||
|
||||
$udpControl->on('left', function($speed = 0.3) use (&$pcmd) {
|
||||
$udpControl->on('left',
|
||||
function($speed = 0.3) use (&$pcmd) {
|
||||
$pcmd['left'] = $speed;
|
||||
unset($pcmd['right']);
|
||||
});
|
||||
|
||||
$udpControl->on('up', function($speed = 0.6) use (&$pcmd) {
|
||||
$udpControl->on('up',
|
||||
function($speed = 0.6) use (&$pcmd) {
|
||||
$pcmd['up'] = $speed;
|
||||
unset($pcmd['down']);
|
||||
});
|
||||
|
||||
$udpControl->on('down', function($speed = 0.6) use (&$pcmd) {
|
||||
$udpControl->on('down',
|
||||
function($speed = 0.6) use (&$pcmd) {
|
||||
$pcmd['down'] = $speed;
|
||||
unset($pcmd['up']);
|
||||
});
|
||||
|
||||
$udpControl->on('flip', function() use (&$anim) {
|
||||
$udpControl->on('flip',
|
||||
function() use (&$anim) {
|
||||
$anim['control:flight_anim'] = '16,5';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Joli\ArDrone\Navdata;
|
||||
|
||||
use Evenement\EventEmitter;
|
||||
use Joli\ArDrone\Config\Config;
|
||||
use Datagram\Factory AS UdpFactory;
|
||||
use Datagram\Socket AS UdpSocket;
|
||||
use React\Datagram\Factory AS UdpFactory;
|
||||
use React\Datagram\Socket AS UdpSocket;
|
||||
use Joli\ArDrone\Navdata\Frame;
|
||||
|
||||
class UdpNavdata extends EventEmitter {
|
||||
class UdpNavdata extends EventEmitter
|
||||
{
|
||||
/**
|
||||
* @var \React\EventLoop\StreamSelectLoop
|
||||
*/
|
||||
@@ -25,29 +27,31 @@ class UdpNavdata extends EventEmitter {
|
||||
|
||||
public function __construct($loop)
|
||||
{
|
||||
$this->port = Config::CONTROL_PORT;
|
||||
$this->ip = Config::DRONE_IP;
|
||||
$this->loop = $loop;
|
||||
$this->port = Config::CONTROL_PORT;
|
||||
$this->ip = Config::DRONE_IP;
|
||||
$this->loop = $loop;
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
private function start()
|
||||
{
|
||||
$socket = $this->socket;
|
||||
|
||||
// $socket = $this->socket;
|
||||
$udpFactory = new UdpFactory($this->loop);
|
||||
$udpNavdata = $this;
|
||||
|
||||
//var_dump(Config::DRONE_IP); var_dump(Config::NAVDATA_PORT);die();
|
||||
// Navdata stream
|
||||
$udpFactory->createClient(Config::DRONE_IP, Config::NAVDATA_PORT)->then(function (UdpSocket $client) use (&$udpNavdata) {
|
||||
$udpFactory->createClient(Config::DRONE_IP.':'.Config::NAVDATA_PORT)->then(function (UdpSocket $client) use (&$udpNavdata) {
|
||||
// Start dialog
|
||||
$client->send('1');
|
||||
$client->send('1');
|
||||
|
||||
$client->on('message', function($message) use (&$udpNavdata) {
|
||||
$client->on('message',
|
||||
function($message) use (&$udpNavdata) {
|
||||
$frame = new Frame($message);
|
||||
$udpNavdata->emit('navdata', array($frame));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Referência em uma Nova Issue
Bloquear um usuário