I always send the following sequence:
"AT*CONFIG=1,\"general:navdata_demo\",\"TRUE\"\r"
"AT*CTRL=0\r"
Then whatever you want starting with a sequence number of 1.
I think you are missing the AT*CTRL=0/r
Frage
#include <stdlib.h> // for exit() //
#include <netdb.h>
#include <stdio.h>
#include <string.h> // memset() //
#define DRONE_COMMAND_PORT 5556
#define MAX_MSG 2048
int main(int argc, char *argv[]) {
// declare variables
int sd, rc, flags, nd;
char command[MAX_MSG];
struct sockaddr_in clientAddr;
struct sockaddr_in droneAddr;
struct hostent *h;
struct timespec wait_command;
int seq=0;
char msg[MAX_MSG];
// initialize variables
flags = 0;
wait_command.tv_sec = 0;
wait_command.tv_nsec = 5000000;
// check command line args //
if(argc<2) {
printf("usage : %s <server name/IP>\n", argv[0]);
exit(EXIT_FAILURE);
}
// get server IP address (no check if input is IP address or DNS name)
h = gethostbyname(argv[1]);
if(h==NULL) {
printf("%s: unknown host '%s' \n", argv[0], argv[1]);
exit(EXIT_FAILURE);
}
// create structure for ardrone address & port
droneAddr.sin_family = h->h_addrtype;
droneAddr.sin_port = htons(DRONE_COMMAND_PORT);
memcpy((char *) &droneAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
// create structure for this client
clientAddr.sin_family = AF_INET;
clientAddr.sin_addr.s_addr = htonl(INADDR_ANY);
clientAddr.sin_port = htons(0);
// socket creation
sd = socket(AF_INET,SOCK_DGRAM,0);
if(sd<0) {
printf("%s: cannot open socket \n",argv[0]);
exit(EXIT_FAILURE);
}
// bind client's the port and address
rc = bind(sd, (struct sockaddr *) &clientAddr, sizeof(clientAddr));
if(rc<0) {
printf("%s: cannot bind port\n", argv[0]);
exit(EXIT_FAILURE);
}
// send commands
char cmd[MAX_MSG],cmd2[MAX_MSG],cmd3[MAX_MSG],cmd4[MAX_MSG];
int i;
snprintf(cmd,MAX_MSG,"AT*CONFIG= %u,\"general:navdata_demo\",\"TRUE\"",seq);
printf("%s: %s\n",argv[0],cmd);
sendto(sd, cmd, MAX_MSG , flags, (struct sockaddr *) &droneAddr, sizeof(droneAddr));
seq++;
snprintf(cmd2,MAX_MSG,"AT*FTRIM=%u",seq);
printf("%s: %s\n",argv[0],cmd2);
sendto(sd, cmd2, MAX_MSG , flags, (struct sockaddr *) &droneAddr, sizeof(droneAddr));
seq++;
snprintf(cmd3,MAX_MSG,"AT*PMODE= %u,2",seq);
printf("%s: %s\n",argv[0],cmd3);
sendto(sd, cmd3, MAX_MSG , flags, (struct sockaddr *) &droneAddr, sizeof(droneAddr));
seq++;
char cmd1[MAX_MSG];
printf("%s: sending commands to %d\n", argv[0], inet_ntoa(*(struct in_addr *)h->h_addr_list[0]));
for(i=0;i<10;i++)
{
cmd1[strlen(cmd1)-1] = 0x0d; // change last character from new line to carriage return
snprintf(cmd1,MAX_MSG,"AT*REF=%u,290718208",seq);
printf("%s: %s\n",argv[0],cmd1);
snprintf(cmd1,MAX_MSG,"AT*REF=%u,290718208",seq+1);
printf("%s: %s\n",argv[0],cmd1);
snprintf(cmd1,MAX_MSG,"AT*REF=%u,290718208",seq+2);
printf("%s: %s\n",argv[0],cmd1);
snprintf(cmd1,MAX_MSG,"AT*REF=%u,290718208",seq+3);
printf("%s: %s\n",argv[0],cmd1);
snprintf(cmd4,MAX_MSG,"AT*COMWDG=%u",seq+4);
printf("%s :%s\n",argv[0],cmd4);
rc = sendto(sd, cmd1, MAX_MSG , flags, (struct sockaddr *) &droneAddr, sizeof(droneAddr));
if(rc<0) {
printf("%s: can not send data\n",argv[0]);
close(sd);
exit(EXIT_FAILURE);
}
seq=seq+5;
nanosleep(&wait_command , NULL);
}
return 1;
}
Hi, This is my program to take-off ar.drone. I am not getting any errors when i compile it. But the drone is not taking-off. The at commands in printf statements are getting printed. there is no error in that also. Can anyone tell me if there is any error in my program or why my program is not working?
thanks in advance.
with regards, shiksha
Lösung
I always send the following sequence:
"AT*CONFIG=1,\"general:navdata_demo\",\"TRUE\"\r"
"AT*CTRL=0\r"
Then whatever you want starting with a sequence number of 1.
I think you are missing the AT*CTRL=0/r
Andere Tipps
Try to use
connect()
instead of bind the port.