DevGuide/Communications

From PaparazziUAV
Jump to navigation Jump to search

This page describes the way the communications with the aircrafts are implemented in paparazzi.

Messages_Format

We'll start with high level stuff such as sending your own telemetry message or datalink (uplink) message. We'll then look at the lower layers

sending telemetry message

Describe your message in the telemetry section in conf/messages.xml

This should look like this

<message name="MARK" id="32">
  <field name="ac_id" type="uint8"/>
  <field name="lat" type="float" unit="deg"/>
  <field name="long" type="float" unit="deg"/>
  <field name="alt" type="uint32" unit="mm" alt_unit="m" alt_unit_coef="1000"/>
</message>

The id has to be unique. The fields can have type int8, int16, int32, uint8, uint16, uint32, float and arrays of those. They must be aligned on a multiple of their size (c.f. examples with pad fields).

The alt_unit and alt_unit_coef will be used the Plotter and the Messages agents to display human readable values. When alt_unit_coef is not specified, some basic default conversions are automatic:

  • deg <-> rad
  • deg/s <-> rad/s
  • m <-> cm
  • m/s <-> cm/s
  • decideg -> deg

This enables all the ground system to deal with your message and generate sending code for the airborne system. The code is generated in var/include/messages.h.

From the airborne code you can send the message by using this code, for example

DOWNLINK_SEND_MARK(DefaultChannel, &mark_id, &mark_lat, &mark_long, &mark_alt);

The first parameter of the DOWNLINK_SEND_x macro is the channel you want to send it over, in most cases you want to use the DefaultChannel.

You can also have the autopilot send the message periodically. For doing so, in your telemetry file (for example conf/telemetry/default.xml, you can make your own and reference it in the conf/conf.xml file). You can add a line like

<message name="MARK" period="1"/>

meaning that MARK will be sent every second. You then need to specify the arguments to your message in the sw/airborne/firmwares/fixedwing/ap_downlink.h or sw/airborne/firmwares/rotorcraft/telemetry.h header by providing a macro

#define PERIODIC_SEND_MARK() DOWNLINK_SEND_MARK(DefaultChannel, &mark_id, &mark_lat, &mark_long, &mark_alt)

You can have different telemetry modes having different rates for each message. For example you might want a verbose mode and a stealth mode.

When sent by the aircraft the message will be available on the ground ivy bus. You can watch it using the messages program or with the ivyprobe command line ( ivyprobe '(.*)' ).

The file sw/ground_segment/cockpit/ant_track.c shows how to receive a message in a C program. For ocaml, we have a higher level library to receive messages (sw/lib/ocaml/pprz.ml).

Adding datalink (uplink) messages

This is similar to the above. Add your message in the datalink section of messages.xml This will generate parsing code for the airborne program (var/include/dl_protocol.h).

There are several possibilities to parse the uplink messages:

  1. add your handler in the sw/airborne/firmwares/fixedwing/datalink.c or sw/airborne/firmwares/rotorcraft/datalink.c code
  2. use a module with a datalink node where you specify the message to be parsed and the function to be called when the messages arrives
  3. or you can just rewrite your own dl_parse_msg() function, for example in a test program where you want to receive only your own messages.

The "transport" layer

Paparazzi can use the built-in transport layer of different hardware (currently only wavecards and xbee/xtends) and also provides his own layer for hardware lacking it (showing as remote serial ports). C sourcecode (.c) and belonging header (.h) -files are: xbee.c, xbee.h and pprz_transport.c, pprz_transport.h