CC3D - Communication via UART
« on: February 01, 2016, 09:14:51 am »
Hi everyone,

I am doing some tests to read the telemetry of the CC3D board using the UART channel of a RaspberryPi.
Does anyone know where to find info about how this communication work?
What is the structure of the data I should wait?
By now I can receive some characters from the CC3D, but they make no sense.
My configuration is 57600, 8 bits, 1 stop bit.

Thanks in advanced,
Omar


Re: CC3D - Communication via UART
« Reply #2 on: February 02, 2016, 08:31:04 am »
Thanks for the links!!

I will take a look to see how this protocol works.


sonium

  • *
  • 15
Re: CC3D - Communication via UART
« Reply #3 on: May 15, 2016, 08:38:15 pm »
Hi, I'm trying the same thing (except the UART is the oplink modem). So far I found code from Taulabs [1]. It seems to establish a connection using /shell.py -s -b 38400 /dev/ttyAMA0 (use ssh -X to connect to RPi) but then if I try doing anything meaningful I get error about mismatching packet sizes.
Please let me know if you get any further.

[1]
https://github.com/TauLabs/TauLabs/tree/09af5415bb393e6e31f8cadc151f9d40e9b7e380/python

Edit:

The helpful folks at Taulabs pointed me to [2] and recommended trying minimal_connection.py it still has however more or less simlar problems.

[2] https://github.com/d-ronin/dRonin/tree/next/python
« Last Edit: May 15, 2016, 09:58:06 pm by sonium »

hwh

  • *
  • 1018
Re: CC3D - Communication via UART
« Reply #4 on: May 15, 2016, 10:38:39 pm »
Hi, I'm trying the same thing (except the UART is the oplink modem). So far I found code from Taulabs [1]. It seems to establish a connection using /shell.py -s -b 38400 /dev/ttyAMA0 (use ssh -X to connect to RPi) but then if I try doing anything meaningful I get error about mismatching packet sizes.
...
If you didn't modify the TauLabs code to understand LibrePilot UAV objects you'd get that.  You can't take code from a project and expect it to work with a different project without modifications.  That code gets it's idea of how the UAV objects are formatted by looking up in the same source tree it's in.

sonium

  • *
  • 15
Re: CC3D - Communication via UART
« Reply #5 on: May 15, 2016, 10:42:22 pm »
ok, that explains some things I have seen. But not the mismatching packed sizes, since UAVtalk should be standardized on that, or?

hwh

  • *
  • 1018
Re: CC3D - Communication via UART
« Reply #6 on: May 15, 2016, 11:22:49 pm »
No, each UAVobject has it's own size.  A packet that transfers just a single value like sonaraltitude is much smaller than one that transfers a larger number of settings like mixersettings.

edit:  Looking at it with the LP definitions loaded it seems like every object is exactly 2 bytes off in size.  That implies that there is probably some difference in the overall packet structure or protocol.  Maybe an added or deleted field.
« Last Edit: May 16, 2016, 01:58:45 am by hwh »

sonium

  • *
  • 15
Re: CC3D - Communication via UART
« Reply #7 on: May 16, 2016, 10:07:05 am »
I got the code from alessiomorale working, here a run-down of basic steps on RPi2:

Code: [Select]
git clone https://bitbucket.org/alessiomorale/librepilot
cd librepilot
git checkout amorale/lp_python_porting
sudo apt-get install qt5-default qt5-qmake qtbase5-dev-tools
make uavobjects_python_install

Now I have my OPlink modem connected to the raspberry pi via the UART pins and power it via the +5V and GND pins from the GPIO. If the OPlink mini is powered externaly the +5V should left be disconnected. On the Oplink side the connected port is set to 'Telemetry'.

there is an example code in librepilot/ground/pyuavtalk/examples/example.py however the UART speed needs to be adjusted in line 58:
Code: [Select]
        serPort = serial.Serial(_port, 38400, timeout=.5)   # this was the default set in the GCS Oplink tab

Time to try, model powered by flight battery:
Code: [Select]
pi@raspberrypi:~/librepilot/ground/pyuavtalk/examples $ python example.py /dev/ttyAMA0 o
Opening Port "/dev/ttyAMA0"
Creating UavTalk
Starting ObjectManager
INFO:root:Importing UAVObject definitions from /usr/local/lib/python2.7/dist-packages/openpilot/uavtalk/../uavobjects
Starting UavTalk
Request fast periodic updates for AttitudeState
Install Observer for AttitudeState updates

 . Rate: 6.4 Hz   RPY: 13.134890 11.503283 -10.094670
Stopping UavTalk

Re: CC3D - Communication via UART
« Reply #8 on: May 24, 2016, 01:55:01 pm »
I tried the same branch but without success on RPI2:

pi@raspi:~/workspace/librepilot/ground/pyuavtalk/examples $ python example.py /dev/ttyAMA0 o
Opening Port "/dev/ttyAMA0"
Creating UavTalk
Starting ObjectManager
INFO:root:Importing UAVObject definitions from /usr/local/lib/python2.7/dist-packages/openpilot/uavtalk/../uavobjects
Starting UavTalk
Request fast periodic updates for AttitudeState
Install Observer for AttitudeState updates

:( waiting forever here

eventually had to stop using ^C
^C
Stopping UavTalk

used the default 38400 baud rate.

Ported the python script (pyuavtalk) to my laptop (Windows 10) and result is the same.
python examples\example.py COM3 o
Note: COM3 is the serial port of oplink mini. [ Given sonium has "/dev/ttyAMA0" on RPI2, I suppose I should use the normal serial port COM3?] 

By moving the Oplink mini (micro-usb connector) to my laptop, Librepilot GCS on windows 10 instantly establishes telemetry link. However I notice that Librepilot GCS uses port "USB oplinkmini" instead of "COM3" for communicating with oplink on the drone. If I change it to "COM3", I cannot get telemetry link. Does this mean there is another layer (driver?) in the Librepilot GCS which drives the COM3 port? Can anyone please explain the logic behind?

Thanks
Richard


« Last Edit: May 25, 2016, 12:57:51 am by richardche_au »

f5soh

  • *****
  • 4572
    • LibrePilot
Re: CC3D - Communication via UART
« Reply #9 on: May 25, 2016, 01:48:30 am »
python only supports serial port.

You should enable the VCP port as telemetry (move the Telemetry setting from USB Hid to VCP)

Next connect using /dev/ttyACM0 for Rpi


Re: CC3D - Communication via UART
« Reply #10 on: May 25, 2016, 09:28:08 am »
Thanks for the detailed instruction, got it working!

Slightly different set up though:
1. On Win 10 GCS connects to drone via Oplink mini, in the H/W config tab keep the config as is (HID telemetry and VCP disabled) - this way I can connect via USB telemetry as usual. I tried as shown in the picture but seems I cannot get USB telemetry working on my revo board for some reason. Maybe it does not matter what you have on the revo board?

2. in the oplink tab, change VCP port to serial

3. Plug in oplink mini (usb) onto RPI;

4. use ttyACM0 on RPI and run the example script untouched.

Hurrah!

Thank you F5soh again for sharing.

sallyc

  • *
  • 47
Re: CC3D - Communication via UART
« Reply #11 on: August 04, 2017, 07:35:24 pm »
Hello, I didn't use OPlink modem, and i did what the previous says and still waiting forever. Can anyone help me?

sallyc

  • *
  • 47
Re: CC3D - Communication via UART
« Reply #12 on: August 25, 2017, 04:37:07 pm »
I got the code from alessiomorale working, here a run-down of basic steps on RPi2:

Code: [Select]
git clone https://bitbucket.org/alessiomorale/librepilot
cd librepilot
git checkout amorale/lp_python_porting
sudo apt-get install qt5-default qt5-qmake qtbase5-dev-tools
make uavobjects_python_install

Now I have my OPlink modem connected to the raspberry pi via the UART pins and power it via the +5V and GND pins from the GPIO. If the OPlink mini is powered externaly the +5V should left be disconnected. On the Oplink side the connected port is set to 'Telemetry'.

there is an example code in librepilot/ground/pyuavtalk/examples/example.py however the UART speed needs to be adjusted in line 58:
Code: [Select]
        serPort = serial.Serial(_port, 38400, timeout=.5)   # this was the default set in the GCS Oplink tab

Time to try, model powered by flight battery:
Code: [Select]
pi@raspberrypi:~/librepilot/ground/pyuavtalk/examples $ python example.py /dev/ttyAMA0 o
Opening Port "/dev/ttyAMA0"
Creating UavTalk
Starting ObjectManager
INFO:root:Importing UAVObject definitions from /usr/local/lib/python2.7/dist-packages/openpilot/uavtalk/../uavobjects
Starting UavTalk
Request fast periodic updates for AttitudeState
Install Observer for AttitudeState updates

 . Rate: 6.4 Hz   RPY: 13.134890 11.503283 -10.094670
Stopping UavTalk

I got root:error: CRC ERROR
does any one knows about this?

Re: CC3D - Communication via UART
« Reply #13 on: August 25, 2017, 07:36:49 pm »
One possibility is that you have mismatched UAVO definitions.

If you change a UAVO / xml file you must recompile all code that knows about that UAVO, including however you manage UAVO IDs for any external project.  And data files that contain old OAVOs will not work with new definitions...

sallyc

  • *
  • 47
Re: CC3D - Communication via UART
« Reply #14 on: August 26, 2017, 12:51:30 pm »
no i did not change the UAVO definitions... :'(