Jump to content


Obteining data from UAVObjects withouth using GCS


  • Please log in to reply
32 replies to this topic

#1 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 13 January 2012 - 03:35 PM

I want to obtein the data from one UAVObject and I want to show the data using the console.

For example I want to see the data from the GPS and show this data in screen using the console. Is that possible?

#2 D-Lite

D-Lite

    Core Team

  • Members
  • PipPipPip
  • 968 posts
  • Country: flag of Germany Germany


Posted 13 January 2012 - 05:57 PM

You could do this using a Python script and PyUAVTalk. It's experimental and requires some work to get what you want but it's a good start.

#3 Kenn Sebesta

Kenn Sebesta

    Controls Master!

  • Members
  • PipPipPip
  • 896 posts
  • Country: flag of Luxembourg Luxembourg


Posted 13 January 2012 - 07:29 PM

Yeah, it should be readily doable by directly reading the serial port. The UAVTalk protocol is explained in further detail in the wiki, you'll just have to parse it and then extract whatever data you'd like.

#4 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 13 January 2012 - 07:39 PM

Thank your for your answers, but I want to use one which uses C instead Python, QT, or others GUI for get and transmit the data to the CopterPilot

Edited by bigluis, 13 January 2012 - 07:41 PM.


#5 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 13 January 2012 - 08:24 PM

You might try using my Arduino UAVTalk port.  It should be relatively easy to compile in standard C.  You'd just have to write the serial interface, which shouldn't be too hard.


#6 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 14 January 2012 - 05:26 AM

Hello,

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 XXL-Wing

XXL-Wing

    Developer

  • Members
  • PipPipPip
  • 166 posts
  • LocationVienna
  • Country: flag of Austria Austria

Posted 14 January 2012 - 07:45 AM

does anything useful arrive at you serial port? have you checked that?
at first, make sure serial comm is working, and afterwards try to dcode what is coming in
No matter how good your backend systems are, the users will only remember your front end. Fail there and you will fail, period.   -- Tristan Louis
Don't make me think.   -- Steve Krug, usability expert

#8 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 14 January 2012 - 02:44 PM

First, you need to ensure that you have the same version of the UAVObjects as the version you're running on whatever you're connected to.  The UAVObject IDs change whenever the object changes, so it will not recognize objects that have changed if the versions are different.

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 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 14 January 2012 - 06:07 PM

Thanks, I'm going to try that.

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?

#10 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 14 January 2012 - 07:32 PM

I believe that's okay.

View Postbigluis, on 14 January 2012 - 06:07 PM, said:

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?
I believe that correct.

#11 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 16 January 2012 - 04:37 AM

Hello,

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 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 16 January 2012 - 03:41 PM

Great!

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 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 16 January 2012 - 07:07 PM

Could you give me an example?

#14 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 16 January 2012 - 08:34 PM

Just look in the telemetry module.  It calls FlightTelemetryStatsGet in there.

#15 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 16 January 2012 - 10:49 PM

This is the code which I have been probing. When I send some data, it appears updated. However, when I send the FlightStatusArmedSet command it don't get armed.

#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.
Attached File  pilottest.png   189.32K   21 downloads

Below of that I've attached the entire code.
Attached File  PilotTest.zip   302.02K   5 downloads

Edited by bigluis, 16 January 2012 - 11:04 PM.


#16 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 16 January 2012 - 11:57 PM

I'm not sure it's as simple as that to arm the copter.  Even if you do arm the copter in this way it's likely going to be disarmed because of some failesafe (receiver disconnected, etc).  What are you trying to accomplish?

#17 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 17 January 2012 - 02:34 PM

I'm trying to use another microcontroller to control the CopterControl. The problem is that I'm not sure about using the GCS code because I don't know if I could compile the code in the new microcontroler.

#18 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 17 January 2012 - 05:12 PM

I think how you do this depends on how you plan to control it.  What kind of controller do you plan to use (e.g. joystick, transmitter, etc)?

#19 bigluis

bigluis

    Member

  • Members
  • PipPip
  • 26 posts
  • Country: flag of United States United States

Posted 18 January 2012 - 02:30 PM

I'm trying to control the Copter using the serial bus in telemetry mode conected to a Microcontroler which is connected to a Computer by mean of WiFi. At the same time I want to receive the data from one GPS module and One Magnetometer module. I don't want to use a PPM, PWM, Spektrum, or S. Bus transmiter to control the Copter.

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:

View PostBrian, on 16 January 2012 - 11:57 PM, said:

I'm not sure it's as simple as that to arm the copter.  Even if you do arm the copter in this way it's likely going to be disarmed because of some failesafe (receiver disconnected, etc).  What are you trying to accomplish?

I mean, how do I know if exist any fail-safe. what function do I must use to get this data?

#20 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 18 January 2012 - 03:48 PM

For my transmitter I send GCSReceiver objects, which simulates a transmitter/receiver pair, and sends stick movements, etc over the telemetry link.  The GCS controller gadget is also sending (I believe) GCSReceiver objects over the telemetry link.

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.