comment envoyer une commande au ARDrone 2.0 sous Android ?
Bonjour,
J'essaie de programmer une application Android permettant de contrôler l'ARDrone 2.0 de Parrot et je n'arrive pas à envoyer une commande. Vendredi, j'avais réussi à faire décoler l'engin mais depuis hier le code ne marche plus pourtant il me semble que je ne l'avais pas modifier:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
public class CmdDecollage extends Thread {
String commande="";
byte[] cmdToByte;
InetAddress IpDrone;
DatagramSocket clientSocket;
boolean etat;
DatagramPacket sendPacketWithCmd;
private byte[] ip = {(byte)192, (byte)168, (byte)1, (byte)1 };
boolean isRunning = true;
private final static long TIME_SLEEP= 20;
//---- Traitement ----//
public void run() {
//---- Convertit l'adresse byte en IP ----//
try {
IpDrone = InetAddress.getByAddress(ip);
} catch (UnknownHostException e1) {
e1.printStackTrace();
etat = false;
}
//---- Cree le Socket ----//
try {
clientSocket = new DatagramSocket();
} catch (SocketException e) {
e.printStackTrace();
etat = false;
}
while(isRunning){
runControl();
try {
Thread.sleep(TIME_SLEEP);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void runControl(){
//---- Commande à envoyer au Drone ----//
commande = "AT*REF=1,290717696<LF>AT*REF=2,290717952<LF>AT*REF=3,290717696<LF>";
//---- Convertit la commande en Byte ----//
cmdToByte = commande.getBytes();
//---- Envoie la packet avec la commande au Drone ----//
try {
sendPacketWithCmd = new DatagramPacket(cmdToByte, cmdToByte.length, IpDrone, 5556);
clientSocket.send(sendPacketWithCmd);
} catch (IOException e) {
e.printStackTrace();
etat = false;
}
etat = true;
isRunning=false;
}
public boolean retourneetat(){
return etat;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
public class HomeActivity extends Activity {
Button boutonDecollage;
CmdDecollage cmdD;
static TextView tV;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
tV = (TextView) findViewById(R.id.text);
//---- Bouton pour decoller ----//
boutonDecollage = (Button) findViewById(R.id.button1);
//--- Ecouteur du Bouton de Decollage ----//
boutonDecollage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
cmdD = new CmdDecollage();
cmdD.start();
tV.setText("DONC c'est : "+cmdD.retourneetat());
}
});
}
public static TextView gettV() {
return tV;
}
public static void settV(TextView tV) {
HomeActivity.tV = tV;
}
} |
Merci.