Skip to content

Commit c098bde

Browse files
authored
Merge pull request #6887 from ShikOfTheRa/Shiki-antenna-tracking
Antenna tracking - video telemetry
2 parents f2692f3 + 1ce2a59 commit c098bde

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

docs/Settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
| osd_snr_alarm | 4 | -20 | 10 | Value below which Crossfire SNR Alarm pops-up. (dB) |
430430
| osd_stats_energy_unit | MAH | | | Unit used for the drawn energy in the OSD stats [MAH/WH] (milliAmpere hour/ Watt hour) |
431431
| osd_stats_min_voltage_unit | BATTERY | | | Display minimum voltage of the `BATTERY` or the average per `CELL` in the OSD stats. |
432+
| osd_telemetry | OFF | | | To enable OSD telemetry for antenna tracker. Possible values are `OFF`, `ON` and `TEST` |
432433
| osd_temp_label_align | LEFT | | | Allows to chose between left and right alignment for the OSD temperature sensor labels. Valid values are `LEFT` and `RIGHT` |
433434
| osd_time_alarm | 10 | 0 | 600 | Value above which to make the OSD flight time indicator blink (minutes) |
434435
| osd_units | METRIC | | | IMPERIAL, METRIC, UK |

src/main/drivers/osd_symbols.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@
119119
#define SYM_RPM 0x8B // 139 RPM
120120
#define SYM_WAYPOINT 0x8C // 140 Waypoint
121121
#define SYM_AZIMUTH 0x8D // 141 Azimuth
122-
// 0x8E // 142 -
123-
// 0x8F // 143 -
122+
123+
#define SYM_TELEMETRY_0 0x8E // 142 Antenna tracking telemetry
124+
#define SYM_TELEMETRY_1 0x8F // 143 Antenna tracking telemetry
124125

125126
#define SYM_BATT_FULL 0x90 // 144 Battery full
126127
#define SYM_BATT_5 0x91 // 145 Battery

src/main/fc/settings.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ tables:
7575
- name: osd_video_system
7676
values: ["AUTO", "PAL", "NTSC"]
7777
enum: videoSystem_e
78+
- name: osd_telemetry
79+
values: ["OFF", "ON","TEST"]
80+
enum: osd_telemetry_e
7881
- name: osd_alignment
7982
values: ["LEFT", "RIGHT"]
8083
enum: osd_alignment_e
@@ -2900,6 +2903,12 @@ groups:
29002903
headers: ["io/osd.h", "drivers/osd.h"]
29012904
condition: USE_OSD
29022905
members:
2906+
- name: osd_telemetry
2907+
description: "To enable OSD telemetry for antenna tracker. Possible values are `OFF`, `ON` and `TEST`"
2908+
table: osd_telemetry
2909+
field: telemetry
2910+
type: uint8_t
2911+
default_value: "OFF"
29032912
- name: osd_video_system
29042913
description: "Video system used. Possible values are `AUTO`, `PAL` and `NTSC`"
29052914
default_value: "AUTO"

src/main/io/osd.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,67 @@ static void osdDrawRadar(uint16_t *drawn, uint32_t *usedScale)
11831183
osdDrawMap(reference, 0, SYM_ARROW_UP, GPS_distanceToHome, poiDirection, SYM_HOME, drawn, usedScale);
11841184
}
11851185

1186+
static uint16_t crc_accumulate(uint8_t data, uint16_t crcAccum)
1187+
{
1188+
uint8_t tmp;
1189+
tmp = data ^ (uint8_t)(crcAccum & 0xff);
1190+
tmp ^= (tmp << 4);
1191+
crcAccum = (crcAccum >> 8) ^ (tmp << 8) ^ (tmp << 3) ^ (tmp >> 4);
1192+
return crcAccum;
1193+
}
1194+
1195+
1196+
static void osdDisplayTelemetry(void)
1197+
{
1198+
uint32_t trk_data;
1199+
uint16_t trk_crc = 0;
1200+
char trk_buffer[31];
1201+
static int16_t trk_elevation = 127;
1202+
static uint16_t trk_bearing = 0;
1203+
1204+
if (ARMING_FLAG(ARMED)) {
1205+
if (STATE(GPS_FIX)){
1206+
if (GPS_distanceToHome > 5) {
1207+
trk_bearing = GPS_directionToHome;
1208+
trk_bearing += 360 + 180;
1209+
trk_bearing %= 360;
1210+
int32_t alt = CENTIMETERS_TO_METERS(osdGetAltitude());
1211+
float at = atan2(alt, GPS_distanceToHome);
1212+
trk_elevation = (float)at * 57.2957795; // 57.2957795 = 1 rad
1213+
trk_elevation += 37; // because elevation in telemetry should be from -37 to 90
1214+
if (trk_elevation < 0) {
1215+
trk_elevation = 0;
1216+
}
1217+
}
1218+
}
1219+
}
1220+
else{
1221+
trk_elevation = 127;
1222+
trk_bearing = 0;
1223+
}
1224+
1225+
trk_data = 0; // bit 0 - packet type 0 = bearing/elevation, 1 = 2 byte data packet
1226+
trk_data = trk_data | (uint32_t)(0x7F & trk_elevation) << 1; // bits 1-7 - elevation angle to target. NOTE number is abused. constrained value of -37 to 90 sent as 0 to 127.
1227+
trk_data = trk_data | (uint32_t)trk_bearing << 8; // bits 8-17 - bearing angle to target. 0 = true north. 0 to 360
1228+
trk_crc = crc_accumulate(0xFF & trk_data, trk_crc); // CRC First Byte bits 0-7
1229+
trk_crc = crc_accumulate(0xFF & trk_bearing, trk_crc); // CRC Second Byte bits 8-15
1230+
trk_crc = crc_accumulate(trk_bearing >> 8, trk_crc); // CRC Third Byte bits 16-17
1231+
trk_data = trk_data | (uint32_t)trk_crc << 17; // bits 18-29 CRC & 0x3FFFF
1232+
1233+
for (uint8_t t_ctr = 0; t_ctr < 30; t_ctr++) { // Prepare screen buffer and write data line.
1234+
if (trk_data & (uint32_t)1 << t_ctr){
1235+
trk_buffer[29 - t_ctr] = SYM_TELEMETRY_0;
1236+
}
1237+
else{
1238+
trk_buffer[29 - t_ctr] = SYM_TELEMETRY_1;
1239+
}
1240+
}
1241+
trk_buffer[30] = 0;
1242+
displayWrite(osdDisplayPort, 0, 0, trk_buffer);
1243+
if (osdConfig()->telemetry>1){
1244+
displayWrite(osdDisplayPort, 0, 3, trk_buffer); // Test display because normal telemetry line is not visible
1245+
}
1246+
}
11861247
#endif
11871248

11881249
static void osdFormatPidControllerOutput(char *buff, const char *label, const pidController_t *pidController, uint8_t scale, bool showDecimal) {
@@ -2691,8 +2752,11 @@ void osdDrawNextElement(void)
26912752
elementIndex = osdIncElementIndex(elementIndex);
26922753
} while(!osdDrawSingleElement(elementIndex) && index != elementIndex);
26932754

2694-
// Draw artificial horizon last
2755+
// Draw artificial horizon + tracking telemtry last
26952756
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
2757+
if (osdConfig()->telemetry>0){
2758+
osdDisplayTelemetry();
2759+
}
26962760
}
26972761

26982762
PG_RESET_TEMPLATE(osdConfig_t, osdConfig,

src/main/io/osd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ typedef struct osdConfig_s {
369369
uint8_t pan_servo_index; // Index of the pan servo used for home direction offset
370370
int8_t pan_servo_pwm2centideg; // Centidegrees of servo rotation per us pwm
371371
uint8_t crsf_lq_format;
372+
uint8_t telemetry; // use telemetry on displayed pixel line 0
372373

373374
} osdConfig_t;
374375

0 commit comments

Comments
 (0)