Skip to content

Commit bfdd123

Browse files
authored
Merge pull request iNavFlight#9355 from error414/adsb
Adsb support pingRX / Aerobit TT-SC1
2 parents 26ea30b + 874407b commit bfdd123

File tree

30 files changed

+736
-18
lines changed

30 files changed

+736
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ make/local.mk
3535
launch.json
3636
.vscode/tasks.json
3737
.vscode/c_cpp_properties.json
38+
/cmake-build-debug/

docs/ADSB.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ADS-B
2+
3+
[Automatic Dependent Surveillance Broadcast](https://en.wikipedia.org/wiki/Automatic_Dependent_Surveillance%E2%80%93Broadcast)
4+
is an air traffic surveillance technology that enables aircraft to be accurately tracked by air traffic controllers and other pilots without the need for conventional radar.
5+
6+
## Current state
7+
8+
OSD can be configured to shows the closest aircraft.
9+
10+
## Hardware
11+
12+
All ADSB receivers which can send Mavlink [ADSB_VEHICLE](https://mavlink.io/en/messages/common.html#ADSB_VEHICLE) message are supported
13+
14+
* [PINGRX](https://uavionix.com/product/pingrx-pro/) (not tested)
15+
* [TT-SC1](https://www.aerobits.pl/product/aero/) (tested)
16+
17+

docs/MixerProfile.md

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ TailSitter is supported by add a 90deg offset to the board alignment. Set the bo
104104
- Rate Settings
105105
- ·······
106106

107+
### TailSitter support
108+
TailSitter is supported by add a 90deg offset to the board alignment. Set the board aliment normally in the mixer_profile for FW mode(`set platform_type = AIRPLANE`), The motor trust axis should be same direction as the airplane nose. Then, in the mixer_profile for takeoff and landing `set platform_type = TAILSITTER`. The `TAILSITTER` platform type is same as `MULTIROTOR` platform type, expect for a 90 deg board alignment offset. In `TAILSITTER` mixer_profile, when motor trust/airplane nose is pointing to the sky, 'airplane bottom'/'multi rotor front' should facing forward in model preview. Set the motor/servo mixer according to multirotor orientation, Model should roll around geography's longitudinal axis, the roll axis of `TAILSITTER` will be yaw axis of `AIRPLANE`. In addition, When `MIXER TRANSITION` input is activated, a 45deg offset will be add to the target angle for angle mode.
109+
107110
## Happy flying
108111

109112
Remember that this is currently an emerging capability:

docs/Settings.md

+40
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,36 @@ _// TODO_
40324032

40334033
---
40344034

4035+
### osd_adsb_distance_alert
4036+
4037+
Distance inside which ADSB data flashes for proximity warning
4038+
4039+
| Default | Min | Max |
4040+
| --- | --- | --- |
4041+
| 3000 | 1 | 64000 |
4042+
4043+
---
4044+
4045+
### osd_adsb_distance_warning
4046+
4047+
Distance in meters of ADSB aircraft that is displayed
4048+
4049+
| Default | Min | Max |
4050+
| --- | --- | --- |
4051+
| 20000 | 1 | 64000 |
4052+
4053+
---
4054+
4055+
### osd_adsb_ignore_plane_above_me_limit
4056+
4057+
Ignore adsb planes above, limit, 0 disabled (meters)
4058+
4059+
| Default | Min | Max |
4060+
| --- | --- | --- |
4061+
| 0 | 0 | 64000 |
4062+
4063+
---
4064+
40354065
### osd_ahi_bordered
40364066

40374067
Shows a border/corners around the AHI region (pixel OSD only)
@@ -5812,6 +5842,16 @@ Delay before disarming when requested by switch (ms) [0-1000]
58125842

58135843
---
58145844

5845+
### tailsitter_orientation_offset
5846+
5847+
Apply a 90 deg pitch offset in sensor aliment for tailsitter flying mode
5848+
5849+
| Default | Min | Max |
5850+
| --- | --- | --- |
5851+
| OFF | OFF | ON |
5852+
5853+
---
5854+
58155855
### telemetry_halfduplex
58165856

58175857
S.Port telemetry only: Turn UART into UNIDIR for usage on F1 and F4 target. See Telemetry.md for details

lib/main/STM32F4/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

+12
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
343343
len--;
344344
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
345345
}
346+
347+
// set bit 7 of the device configuration byte to indicate write protection
348+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
349+
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
350+
}
351+
346352
return 0;
347353
}
348354

@@ -365,6 +371,12 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
365371
len--;
366372
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
367373
}
374+
375+
// set bit 7 of the device configuration byte to indicate write protection
376+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
377+
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
378+
}
379+
368380
return 0;
369381
}
370382

lib/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

+12
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
347347
len--;
348348
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
349349
}
350+
351+
// set bit 7 of the device configuration byte to indicate write protection
352+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
353+
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
354+
}
355+
350356
return 0;
351357
}
352358

@@ -370,6 +376,12 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
370376
len--;
371377
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
372378
}
379+
380+
// set bit 7 of the device configuration byte to indicate write protection
381+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
382+
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
383+
}
384+
373385
return 0;
374386
}
375387

lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

+11
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *p
346346
len--;
347347
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
348348
}
349+
350+
// set bit 7 of the device configuration byte to indicate write protection
351+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
352+
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
353+
}
354+
349355
return 0;
350356
}
351357

@@ -371,6 +377,11 @@ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
371377
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
372378
}
373379

380+
// set bit 7 of the device configuration byte to indicate write protection
381+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
382+
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
383+
}
384+
374385
return 0;
375386
}
376387

src/main/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ main_sources(COMMON_SRC
344344
flight/ez_tune.c
345345
flight/ez_tune.h
346346

347+
io/adsb.c
347348
io/beeper.c
348349
io/beeper.h
349350
io/servo_sbus.c

src/main/drivers/osd_symbols.h

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@
180180
#define SYM_CROSS_TRACK_ERROR 0xFC // 252 Cross track error
181181

182182

183+
#define SYM_ADSB 0xFD // 253 ADSB
184+
183185
#define SYM_LOGO_START 0x101 // 257 to 297, INAV logo
184186
#define SYM_LOGO_WIDTH 10
185187
#define SYM_LOGO_HEIGHT 4

src/main/fc/fc_msp.c

+35
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "config/config_eeprom.h"
8484
#include "config/feature.h"
8585

86+
#include "io/adsb.h"
8687
#include "io/asyncfatfs/asyncfatfs.h"
8788
#include "io/flashfs.h"
8889
#include "io/gps.h"
@@ -948,6 +949,33 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
948949
sbufWriteU16(dst, gpsSol.epv);
949950
break;
950951
#endif
952+
case MSP2_ADSB_VEHICLE_LIST:
953+
#ifdef USE_ADSB
954+
sbufWriteU8(dst, MAX_ADSB_VEHICLES);
955+
sbufWriteU8(dst, ADSB_CALL_SIGN_MAX_LENGTH);
956+
957+
for(uint8_t i = 0; i < MAX_ADSB_VEHICLES; i++){
958+
959+
adsbVehicle_t *adsbVehicle = findVehicle(i);
960+
961+
for(uint8_t ii = 0; ii < ADSB_CALL_SIGN_MAX_LENGTH; ii++){
962+
sbufWriteU8(dst, adsbVehicle->vehicleValues.callsign[ii]);
963+
}
964+
965+
sbufWriteU32(dst, adsbVehicle->vehicleValues.icao);
966+
sbufWriteU32(dst, adsbVehicle->vehicleValues.lat);
967+
sbufWriteU32(dst, adsbVehicle->vehicleValues.lon);
968+
sbufWriteU32(dst, adsbVehicle->vehicleValues.alt);
969+
sbufWriteU16(dst, (uint16_t)CENTIDEGREES_TO_DEGREES(adsbVehicle->vehicleValues.heading));
970+
sbufWriteU8(dst, adsbVehicle->vehicleValues.tslc);
971+
sbufWriteU8(dst, adsbVehicle->vehicleValues.emitterType);
972+
sbufWriteU8(dst, adsbVehicle->ttl);
973+
}
974+
#else
975+
sbufWriteU8(dst, 0);
976+
sbufWriteU8(dst, 0);
977+
#endif
978+
break;
951979
case MSP_DEBUG:
952980
// output some useful QA statistics
953981
// debug[x] = ((hse_value / 1000000) * 1000) + (SystemCoreClock / 1000000); // XX0YY [crystal clock : core clock]
@@ -1518,6 +1546,13 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
15181546
#else
15191547
sbufWriteU16(dst, 0);
15201548
sbufWriteU16(dst, 0);
1549+
#endif
1550+
#ifdef USE_ADSB
1551+
sbufWriteU16(dst, osdConfig()->adsb_distance_warning);
1552+
sbufWriteU16(dst, osdConfig()->adsb_distance_alert);
1553+
#else
1554+
sbufWriteU16(dst, 0);
1555+
sbufWriteU16(dst, 0);
15211556
#endif
15221557
break;
15231558

src/main/fc/fc_tasks.c

+21
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "io/osd_dji_hd.h"
7070
#include "io/displayport_msp_osd.h"
7171
#include "io/servo_sbus.h"
72+
#include "io/adsb.h"
7273

7374
#include "msp/msp_serial.h"
7475

@@ -181,6 +182,14 @@ void taskUpdateCompass(timeUs_t currentTimeUs)
181182
}
182183
#endif
183184

185+
#ifdef USE_ADSB
186+
void taskAdsb(timeUs_t currentTimeUs)
187+
{
188+
UNUSED(currentTimeUs);
189+
adsbTtlClean(currentTimeUs);
190+
}
191+
#endif
192+
184193
#ifdef USE_BARO
185194
void taskUpdateBaro(timeUs_t currentTimeUs)
186195
{
@@ -360,6 +369,9 @@ void fcTasksInit(void)
360369
#ifdef USE_PITOT
361370
setTaskEnabled(TASK_PITOT, sensors(SENSOR_PITOT));
362371
#endif
372+
#ifdef USE_ADSB
373+
setTaskEnabled(TASK_ADSB, true);
374+
#endif
363375
#ifdef USE_RANGEFINDER
364376
setTaskEnabled(TASK_RANGEFINDER, sensors(SENSOR_RANGEFINDER));
365377
#endif
@@ -495,6 +507,15 @@ cfTask_t cfTasks[TASK_COUNT] = {
495507
},
496508
#endif
497509

510+
#ifdef USE_ADSB
511+
[TASK_ADSB] = {
512+
.taskName = "ADSB",
513+
.taskFunc = taskAdsb,
514+
.desiredPeriod = TASK_PERIOD_HZ(1), // ADSB is updated at 1 Hz
515+
.staticPriority = TASK_PRIORITY_IDLE,
516+
},
517+
#endif
518+
498519
#ifdef USE_BARO
499520
[TASK_BARO] = {
500521
.taskName = "BARO",

src/main/fc/runtime_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ typedef enum {
144144
ANTI_WINDUP_DEACTIVATED = (1 << 25),
145145
LANDING_DETECTED = (1 << 26),
146146
IN_FLIGHT_EMERG_REARM = (1 << 27),
147+
TAILSITTER = (1 << 28), //offset the pitch angle by 90 degrees
147148
} stateFlags_t;
148149

149150
#define DISABLE_STATE(mask) (stateFlags &= ~(mask))

src/main/fc/settings.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,11 @@ groups:
11911191
field: mixer_config.switchTransitionTimer
11921192
min: 0
11931193
max: 200
1194+
- name: tailsitter_orientation_offset
1195+
description: "Apply a 90 deg pitch offset in sensor aliment for tailsitter flying mode"
1196+
default_value: OFF
1197+
field: mixer_config.tailsitterOrientationOffset
1198+
type: bool
11941199

11951200

11961201

@@ -3457,6 +3462,31 @@ groups:
34573462
max: 11
34583463
default_value: 9
34593464

3465+
- name: osd_adsb_distance_warning
3466+
description: "Distance in meters of ADSB aircraft that is displayed"
3467+
default_value: 20000
3468+
condition: USE_ADSB
3469+
field: adsb_distance_warning
3470+
min: 1
3471+
max: 64000
3472+
type: uint16_t
3473+
- name: osd_adsb_distance_alert
3474+
description: "Distance inside which ADSB data flashes for proximity warning"
3475+
default_value: 3000
3476+
condition: USE_ADSB
3477+
field: adsb_distance_alert
3478+
min: 1
3479+
max: 64000
3480+
type: uint16_t
3481+
- name: osd_adsb_ignore_plane_above_me_limit
3482+
description: "Ignore adsb planes above, limit, 0 disabled (meters)"
3483+
default_value: 0
3484+
condition: USE_ADSB
3485+
field: adsb_ignore_plane_above_me_limit
3486+
min: 0
3487+
max: 64000
3488+
type: uint16_t
3489+
34603490
- name: osd_estimations_wind_compensation
34613491
description: "Use wind estimation for remaining flight time/distance estimation"
34623492
default_value: ON

src/main/flight/imu.c

+28
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,33 @@ static void imuCalculateTurnRateacceleration(fpVector3_t *vEstcentrifugalAccelBF
704704
lastspeed = currentspeed;
705705
}
706706

707+
fpQuaternion_t* getTailSitterQuaternion(bool normal2tail){
708+
static bool firstRun = true;
709+
static fpQuaternion_t qNormal2Tail;
710+
static fpQuaternion_t qTail2Normal;
711+
if(firstRun){
712+
fpAxisAngle_t axisAngle;
713+
axisAngle.axis.x = 0;
714+
axisAngle.axis.y = 1;
715+
axisAngle.axis.z = 0;
716+
axisAngle.angle = DEGREES_TO_RADIANS(-90);
717+
axisAngleToQuaternion(&qNormal2Tail, &axisAngle);
718+
quaternionConjugate(&qTail2Normal, &qNormal2Tail);
719+
firstRun = false;
720+
}
721+
return normal2tail ? &qNormal2Tail : &qTail2Normal;
722+
}
723+
724+
void imuUpdateTailSitter(void)
725+
{
726+
static bool lastTailSitter=false;
727+
if (((bool)STATE(TAILSITTER)) != lastTailSitter){
728+
fpQuaternion_t* rotation_for_tailsitter= getTailSitterQuaternion(STATE(TAILSITTER));
729+
quaternionMultiply(&orientation, &orientation, rotation_for_tailsitter);
730+
}
731+
lastTailSitter = STATE(TAILSITTER);
732+
}
733+
707734
static void imuCalculateEstimatedAttitude(float dT)
708735
{
709736
#if defined(USE_MAG)
@@ -800,6 +827,7 @@ static void imuCalculateEstimatedAttitude(float dT)
800827
useCOG, courseOverGround,
801828
accWeight,
802829
magWeight);
830+
imuUpdateTailSitter();
803831
imuUpdateEulerAngles();
804832
}
805833

0 commit comments

Comments
 (0)