radio link telemetry protocol on IIC

R9D receiver use a RPM-02 module to get mavlink data through IIC, here are few discussion on how to get data into R9D 

https://www.rcgroups.com/forums/showthread.php?2236519-Radiolink-AT9-%C2%96-anybody-owns-it-Reviews/page14#post34359050
The PRM-02 module uses these Mavlink packets to get the required data:

mavlink_msg_sys_status_pack - Ext Voltage
mavlink_msg_gps_raw_int_pack - Latitude , Longitude and GPS Satellites
mavlink_msg_vfr_hud_pack - Speed,Rise and Altitude
mavlink_msg_global_position_int_pack - Yaw
mavlink_msg_attitude_pack - Roll and Pitch

The data being sent from the Prm-02 to the radio is sent with MSB first.
The the data is the same as would be in the Mavlink packet apart from the floats.
The receiver gets them as 2 bytes. They have been multiplied by 10.
For example if the float in the Mavlink packet for speed was 10.3 the the value sent to the receiver
would be 103.

The transmitter just reads from address 04. The PRM-02 then sends packets according to what data it has.
Apart from the 2 packets I have shown here, there are others but they dont seem to affect the telemetry.
The packets all start with 0x89 and then the next byte indicates which packet it is.

Here are the two sample packets that contain all the Telemetry data shown in my post above:

{0x89, 0xAB, streamData.gps_sats, altHi, altLo, yawHi, yawLo, speedHi, speedLo, rollHi , rollLo, pitchHi, pitchLo, distanceHi, distanceLo, 0x00}


{0x89, 0xCD, streamData.gps_sats, riseHi, riseLo, voltesHi, voltesLo,0x00, 0x00, 0x00 , 0x00, 0x00, x00, 0x00, 0x00, 0x00};

There is a 3rd line as well, which is like
89+ FE+ 1F+ 48+ 00+ C8+ 01+ 2F+ FC+ 00+ 00+ 2F+ FC+ 00+ 00+ 2F-

an example code is found here:
https://github.com/cleanflight/cleanflight/issues/1690
the package discription is quite different in the code then info above.

iic slave seems not working for 8266, nor esp32
https://github.com/suculent/esp8266-I2C-slave

So, I tested first send some fix data with my pro mini 8Mhz, 328
A5 as clock, A4 as data link and connect ground together.
it works fine.




#include <Wire.h>
//#include <mavlink.h>
struct STREAM_DATA {
uint16_t battVoltage =12300;// battery voltage in mv
float altitude = 0;
float climb = 0;
float roll = 3.3;
float pitch = 4.4;
float yaw = 5.5;
uint8_t gps_sats = 0;
float gps_lon = 0;
float gps_lat = 0;
float home_lon = 0;
float home_lat = 0;
uint16_t gps_speed = 0;
boolean gps_fix = false;
uint32_t home_distance = 100;//in 1/10 meter
};
STREAM_DATA streamData;
boolean set = false;

void setup() {
Serial.begin(57600);
// Serial2.begin(57600);

Wire.begin(4);
Wire.onRequest(onRequest);
Serial.println("Starting up...");
}
void loop() {

}

void set1() {
int alt = streamData.altitude * 10;
byte altHi = highByte(alt ) ;
byte altLo = lowByte(alt ) ;
int yaw = streamData.yaw * 100;
byte yawHi = highByte(yaw );
byte yawLo = lowByte(yaw );

int speed2 = streamData.gps_speed * 10;
byte speedHi = highByte(speed2);
byte speedLo = lowByte(speed2);

int roll = streamData.roll * 10;
byte rollHi = highByte(roll);
byte rollLo = lowByte(roll);

int pitch = streamData.pitch * 10;
byte pitchHi = highByte(pitch);
byte pitchLo = lowByte(pitch);
// int distance = calc_dist(streamData.gps_lat, streamData.gps_lon, streamData.home_lat, streamData.home_lon) * 100;
int distance =streamData.home_distance;
byte distanceHi = highByte(distance);
byte distanceLo = lowByte(distance);
byte buffer[16] = {0x89, 0xAB, streamData.gps_sats, altHi, altLo, yawHi, yawLo, speedHi, speedLo, rollHi , rollLo, pitchHi, pitchLo, distanceHi, distanceLo, 0x00};
Wire.write(buffer, 16);
}
void set2() {
int rise = streamData.climb * 10;
byte riseHi = highByte(rise);
byte riseLo = lowByte(rise);
byte voltesHi = highByte(streamData.battVoltage);
byte voltesLo = lowByte(streamData.battVoltage);
float lat = 40.689060;
float log = -74.044636;
byte buffer[16] = {0x89, 0xCD, streamData.gps_sats, riseHi, riseLo, voltesHi, voltesLo,/**/ 0x0, 0x0, 0x0 , 0x0, /**/0x0, 0x0, 0x0, 0x0,/**/ 0x00};
Wire.write(buffer, 16);
}

void onRequest() {
Serial.println("request received");
if (set) {
set = false;
set1();
} else {
set = true;
set2();
}
}


the code works great, but the lat and long is not as description but I did not find where is the control mode, it would be good for me to know the current mode on my controller.
with the sample code, the mode is always norm, I think it could hide in the zeros.

for the yaw, roll, pitch, mavlink comes with rad, so you need to modify a little bit to make it work.



Latitude and longitude are not working, my AT9 firmware is 1.2.6 osd , I tried MSB first or LSB first, nothing comes out as exact coordinate.


留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone