Obteining data from UAVObjects withouth using GCS
#1
Posted 13 January 2012 - 03:35 PM
For example I want to see the data from the GPS and show this data in screen using the console. Is that possible?
#3
Posted 13 January 2012 - 07:29 PM
#4
Posted 13 January 2012 - 07:39 PM
Edited by bigluis, 13 January 2012 - 07:41 PM.
#5
Posted 13 January 2012 - 08:24 PM
#6
Posted 14 January 2012 - 05:26 AM
I have tried to use the arduino code and it doesn't work. I write the next code
Wprogrma.h
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> #ifndef __WPROGRAM_H_ #define __WPROGRAM_H_ typedef unsigned char uint8_t; typedef unsigned int uint16_t; typedef unsigned long int uint32_t; typedef signed char int8_t; //typedef signed long int int32_t; typedef void* UAVObjHandle; #define __ATTR_PROGMEM__ __attribute__((__progmem__)) #define PROGMEM __ATTR_PROGMEM__ #endif
piltoTest.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <PIOS_CRC/PIOS_CRC.h>
#include <UAVTalk/UAVTalk.h>
#include <UAVObj/UAVObj.h>
#include <UAVObjects/UAVObjects.h>
#define BAUDRATE B57600
#define MODEMDEVICE "/dev/ttyUSB1"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
int fd,c, res;
int32_t WriteMsg(uint8_t *data, int32_t length) {
write(fd, data, length);
}
void ObjEventCallback(UAVObjEvent* ev) {
uint32_t id = UAVObjGetID(ev->obj);
switch(ev->event) {
case EV_UNPACKED:
printf("Unpacked event for ");
printf("%X\n", id);
//ns.println(id, HEX);
break;
case EV_UPDATED:
case EV_UPDATED_MANUAL:
printf("Updated event for ");
//ns.println(id, HEX);
printf("%X\n", id);
UAVTalkSendObject(ev->obj, ev->instId, 1, 100);
break;
case EV_UPDATE_REQ:
printf("Update request event for ");
//ns.println(id, HEX);
printf("%X\n", id);
break;
}
}
volatile int STOP=FALSE;
int main() {
struct termios oldtio,newtio;
uint8_t buf[1];
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE); exit(-1); }
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
// Initialize UAVTalk
UAVTalkInitialize(WriteMsg);
UAVObjInitialize();
// Initialize the UAVTalk objects that you need.
GCSTelemetryStatsInitialize();
GCSTelemetryStatsConnectCallback(ObjEventCallback);
while (STOP==FALSE) { /* loop for input */
res = read(fd,buf,1);
UAVTalkProcessInputStream(*buf);
}
tcsetattr(fd,TCSANOW,&oldtio);
}
and it doesn't show me anything in the screen. Can you help me to solve the problem?
#7
Posted 14 January 2012 - 07:45 AM
at first, make sure serial comm is working, and afterwards try to dcode what is coming in
Don't make me think. -- Steve Krug, usability expert
#8
Posted 14 January 2012 - 02:44 PM
Second, I assume you're reading the telemetry stream from a CC, and the CC will never send a GCSTelemetryStats update. Try something like FlightTelemetryStats.
#9
Posted 14 January 2012 - 06:07 PM
In the other hand, I'm using the uavTalk.h and UAVTalk.cpp that appear in the file ./openpilot/arduino/libraries. Is it the corret file or do I must use another file?
#11
Posted 16 January 2012 - 04:37 AM
This is the code corrected and working.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <PIOS_CRC/PIOS_CRC.h>
#include <UAVTalk/UAVTalk.h>
#include <UAVObj/UAVObj.h>
#include <UAVObjects/UAVObjects.h>
#define BAUDRATE B57600
#define MODEMDEVICE "/dev/ttyUSB1"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
int fd,c, res;
int32_t WriteMsg(uint8_t *data, int32_t length) {
write(fd, data, length);
}
void ObjEventCallback(UAVObjEvent* ev) {
uint32_t id = UAVObjGetID(ev->obj);
switch(ev->event) {
case EV_UNPACKED:
printf("Unpacked event for ");
printf("%lX\n", id);
//ns.println(id, HEX);
break;
case EV_UPDATED:
case EV_UPDATED_MANUAL:
printf("Updated event for ");
//ns.println(id, HEX);
printf("%lX\n", id);
UAVTalkSendObject(ev->obj, ev->instId, 1, 100);
break;
case EV_UPDATE_REQ:
printf("Update request event for ");
//ns.println(id, HEX);
printf("%lX\n", id);
break;
}
}
volatile int STOP=FALSE;
int main() {
struct termios oldtio,newtio;
uint8_t buf[1];
printf("hola\n");
/* printf("fd: %i", fd);*/
/* if(fd>0)close(fd);*/
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
printf("fd: %i\n", fd);
if (fd < 0) {perror(MODEMDEVICE); exit(-1); }
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
// Initialize UAVTalk
UAVTalkInitialize(WriteMsg);
UAVObjInitialize();
// Initialize the UAVTalk objects that you need.
FlightTelemetryStatsInitialize();
FlightTelemetryStatsConnectCallback(ObjEventCallback);
while (STOP==FALSE) { /* loop for input */
res = read(fd,buf,1);
UAVTalkProcessInputStream(*buf);
}
tcsetattr(fd,TCSANOW,&oldtio);
}
But it only give me the ObjectID, what do I must do for get the data from each object?
Edited by bigluis, 16 January 2012 - 04:52 AM.
#12
Posted 16 January 2012 - 03:41 PM
At any time you can call the Get function of any UAVObjects that you've initialized to get a copy of the structure. When you get an EV_UPDATED event it means that it received an update from the other side of the link, and you can call the corresponding Get function to get the updated value(s).
#13
Posted 16 January 2012 - 07:07 PM
#14
Posted 16 January 2012 - 08:34 PM
#15
Posted 16 January 2012 - 10:49 PM
#include <sys types.h="">
#include <sys stat.h="">
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <pios_crc pios_crc.h="">
#include <uavtalk uavtalk.h="">
#include <uavobj uavobj.h="">
#include <uavobjects uavobjects.h="">
#define BAUDRATE B57600
#define MODEMDEVICE "/dev/ttyUSB1"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
int fd,c, res;
int32_t WriteMsg(uint8_t *data, int32_t length) {
write(fd, data, length);
}
void ObjEventCallback(UAVObjEvent* ev) {
uint32_t id = UAVObjGetID(ev->obj);
/* uint8_t data2[5];*/
/* int32_t data1 = FlightTelemetryStatsGet(data2[0]);*/
float data1[5];
FlightTelemetryStatsTxDataRateGet(data1);
switch(ev->event) {
case EV_UNPACKED:
printf("Unpacked event for ");
printf("%lX\n", id);
int i;
FlightTelemetryStatsRxDataRateGet(data1);
/* for(i=0;i>5;i++)*/
printf("data1 = %F\n",data1[2]);
break;
case EV_UPDATED:
case EV_UPDATED_MANUAL:
printf("Updated event for ");
//ns.println(id, HEX);
printf("%lX\n", id);
UAVTalkSendObject(ev->obj, ev->instId, 1, 100);
break;
case EV_UPDATE_REQ:
printf("Update request event for ");
//ns.println(id, HEX);
printf("%lX\n", id);
break;
}
}
volatile int STOP=FALSE;
int main() {
struct termios oldtio,newtio;
uint8_t buf[1];
printf("hola\n");
/* printf("fd: %i", fd);*/
/* if(fd>0)close(fd);*/
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
printf("fd: %i\n", fd);
if (fd < 0) {perror(MODEMDEVICE); exit(-1); }
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
// Initialize UAVTalk
UAVTalkInitialize(WriteMsg);
UAVObjInitialize();
// Initialize the UAVTalk objects that you need.
/* FlightTelemetryStatsInitialize();*/
/* FlightTelemetryStatsConnectCallback(ObjEventCallback);*/
/* FlightStatusConnectCallback(ObjEventCallback);*/
int retorno = ManualControlCommandInitialize();
ManualControlCommandConnectCallback(ObjEventCallback);
printf("retorno %i\n", retorno);
uint8_t ctrlcomando[1]={1};
ManualControlCommandConnectedSet(ctrlcomando);
ctrlcomando[0]=0;
ManualControlCommandConnectedGet(ctrlcomando);
printf("ctrlcomando %i\n",ctrlcomando[0]);
float yaw1[1],roll1[1],pitch1[1],Throttle1[1];
ManualControlCommandYawGet(yaw1);
ManualControlCommandRollGet(roll1);
ManualControlCommandPitchGet(pitch1);
ManualControlCommandThrottleGet(Throttle1);
printf("roll %f\tyaw1 %f\t pitch1 %f\t Throttle %f\n",roll1[0],yaw1[0],pitch1[0],Throttle1[0]);
roll1[0]=0.5,yaw1[0]=0.5,pitch1[0]=0.5,Throttle1[0]=0.5;
ManualControlCommandYawSet(yaw1);
ManualControlCommandRollSet(roll1);
ManualControlCommandPitchSet(pitch1);
ManualControlCommandThrottleSet(Throttle1);
printf("roll %f\tyaw1 %f\t pitch1 %f\t Throttle %f\n",roll1[0],yaw1[0],pitch1[0],Throttle1[0]);
/* ManualControlCommandData mcc = UAVObjGetByName("ManualControlCommand");*/
retorno = FlightStatusInitialize();
FlightStatusConnectCallback(ObjEventCallback);
uint8_t ctrlarmed[1];
FlightStatusArmedGet(ctrlarmed);
printf("ctrlarmed %i\n",ctrlarmed[0]);
ctrlarmed[0]=0;
FlightStatusArmedSet(ctrlarmed);
ctrlarmed[0]=1;
FlightStatusArmedSet(ctrlarmed);
ctrlarmed[0]=2;
FlightStatusArmedSet(ctrlarmed);
ctrlarmed[0]=0;
FlightStatusArmedGet(ctrlarmed);
printf("ctrlarmed %i\n",ctrlarmed[0]);
uint8_t flightstatus[1]={0};
FlightStatusFlightModeSet(flightstatus);
flightstatus[0]=1;
FlightStatusFlightModeGet(flightstatus);
printf("flightstatus %u\n",flightstatus[0]);
while (STOP==FALSE) { /* loop for input */
res = read(fd,buf,1);
UAVTalkProcessInputStream(*buf);
/* printf("res %x\n",res);*/
}
tcsetattr(fd,TCSANOW,&oldtio);
}
These are the data that appear in the console.
pilottest.png 189.32K
21 downloadsBelow of that I've attached the entire code.
PilotTest.zip 302.02K
5 downloads
Edited by bigluis, 16 January 2012 - 11:04 PM.
#16
Posted 16 January 2012 - 11:57 PM
#17
Posted 17 January 2012 - 02:34 PM
#18
Posted 17 January 2012 - 05:12 PM
#19
Posted 18 January 2012 - 02:30 PM
On the other hand, when I use the GCS manual controller gadget, I don't need to use any kind of remote controller. For this reason, I want to know what do you refer when you talk about that:
Brian, on 16 January 2012 - 11:57 PM, said:
I mean, how do I know if exist any fail-safe. what function do I must use to get this data?
#20
Posted 18 January 2012 - 03:48 PM
When I use my transmitter, I do a standard arming sequence (yaw right). I'm not sure how the GCS controller arms the copter. You might want to look in the manualcontrol module (I believe that's what it's called) to figure out the arming sequence and failsafes that are in place.



United States
Germany
Luxembourg
Austria







