37#include "generated/flight_plan.h"
38#include "generated/airframe.h"
44#if defined(FIXEDWING_FIRMWARE)
47#elif defined(ROTORCRAFT_FIRMWARE)
58#define OSD_STRING_SIZE 31
59#define osd_sprintf _osd_sprintf
61#if !defined(OSD_USE_FLOAT_LOW_PASS_FILTERING)
62#define OSD_USE_FLOAT_LOW_PASS_FILTERING
66#if !defined(AMPS_LOW_PASS_FILTER_STRENGTH) || AMPS_LOW_PASS_FILTER_STRENGTH == 0
67#define AMPS_LOW_PASS_FILTER_STRENGTH 6
70#if !defined(SPEED_LOW_PASS_FILTER_STRENGTH) || SPEED_LOW_PASS_FILTER_STRENGTH == 0
71#define SPEED_LOW_PASS_FILTER_STRENGTH 6
74#if !defined(BAT_CAPACITY)
75#pragma message "BAT_CAPACITY not defined, 5000 mah will be used."
76#define BAT_CAPACITY 5000.0
79#if defined(FIXEDWING_FIRMWARE)
81#if !defined(LOITER_BAT_CURRENT)
82#pragma message "LOITER_BAT_CURRENT not defined, 10 Amps will be used for LOITER current draw."
83#define LOITER_BAT_CURRENT 10.0
86#if !defined(STALL_AIRSPEED)
87#pragma message "STALL_AIRSPEED not defined, 10 m/s will be used."
88#define STALL_AIRSPEED 10.0
91#if !defined(MINIMUM_AIRSPEED)
92#pragma message "MINIMUM_AIRSPEED not defined, 1.3 * STALL_SPEED will be used"
93#define MINIMUM_AIRSPEED (1.3f * STALL_AIRSPEED)
98#if !defined(IMU_MAG_X_SIGN)
99#define IMU_MAG_X_SIGN 1
101#if !defined(IMU_MAG_X_SIGN)
102#define IMU_MAG_Y_SIGN 1
104#if !defined(IMU_MAG_X_SIGN)
105#define IMU_MAG_Z_SIGN 1
121#if defined(FIXEDWING_FIRMWARE)
122static void mag_compass(
void);
131static bool _osd_sprintf(
char *buffer,
char *
string,
float value);
178#if defined(FIXEDWING_FIRMWARE)
180void mag_compass(
void)
184 float cos_roll;
float sin_roll;
float cos_pitch;
float sin_pitch;
float mag_x;
float mag_y;
185 static float mag_declination = 0;
186 static bool declination_calculated =
false;
192 cos_roll = cosf(att->
phi);
193 sin_roll = sinf(att->
phi);
194 cos_pitch = cosf(att->
theta);
195 sin_pitch = sinf(att->
theta);
202#if defined(AHRS_MAG_DECLINATION)
203 if (AHRS_MAG_DECLINATION != 0.0) {
212 if (declination_calculated ==
false) {
213#if defined(NOMINAL_AIRSPEED)
219 if (mag_declination > M_PI) {
220 mag_declination -= (2.0 * M_PI);
221 }
else if (mag_declination < -M_PI) { mag_declination += (2.0 * M_PI); }
223 declination_calculated =
true;
224 if (fabs(mag_declination) > RadOfDeg(10.)) { mag_declination = 0; declination_calculated =
false; }
246 svA->
fx = svB.
fx - svC.
fx;
247 svA->
fy = svB.
fy - svC.
fy;
248 svA->
fz = svB.
fz - svC.
fz;
267 static VECTOR svPlanePosition, Home_Position, Home_PositionForPlane, Home_PositionForPlane2;
285#if defined(FIXEDWING_FIRMWARE)
292 Home_Position.
fz = 0;
302 smRotation.
fy1 = -smRotation.
fx2;
303 smRotation.
fy2 = smRotation.
fx1;
335 home_dir = atan2(Home_PositionForPlane2.
fy, Home_PositionForPlane2.
fx);
336 if (home_dir > M_PI) {
337 home_dir -= (2.0 * M_PI);
338 }
else if (home_dir < -M_PI) { home_dir += (2.0 * M_PI); }
349#if defined USE_MATEK_TYPE_OSD_CHIP && USE_MATEK_TYPE_OSD_CHIP == 1
357 if (c >=
'0' && c <=
'9') {
358 if (c ==
'0') { c -= 38; }
else { c -= 48; }
359 }
else if (c >=
'A' && c <=
'Z') {
361 }
else if (c >=
'a' && c <=
'z') {
366 case (
'('): c = 0x3f;
break;
367 case (
')'): c = 0x40;
break;
368 case (
'.'): c = 0x41;
break;
369 case (
'?'): c = 0x42;
break;
370 case (
';'): c = 0x43;
break;
371 case (
':'): c = 0x44;
break;
372 case (
','): c = 0x45;
break;
374 case (
'/'): c = 0x47;
break;
375 case (
'"'): c = 0x48;
break;
376 case (
'-'): c = 0x49;
break;
377 case (
'<'): c = 0x4A;
break;
378 case (
'>'): c = 0x4B;
break;
379 case (
'@'): c = 0x4C;
break;
380 case (
' '): c = 0x00;
break;
381 case (
'\0'): c = 0xFF;
break;
393 float current_amps = 0;
394 float horizontal_speed = 0;
395 float bat_capacity_left = 0;
396 static float bat_capacity_used = 0;
400 bat_capacity_used += (current_amps * 1000.) / (3600. * (
float)MAX7456_PERIODIC_FREQ);
401 bat_capacity_left = (float)
BAT_CAPACITY - bat_capacity_used;
402 if (bat_capacity_left < 0) { bat_capacity_left = 0; }
405#if defined(FIXEDWING_FIRMWARE)
407 current_amps = LOITER_BAT_CURRENT;
408 horizontal_speed = MINIMUM_AIRSPEED;
412 horizontal_speed = 10.0;
415#if defined(OSD_USE_FLOAT_LOW_PASS_FILTERING)
417 static double current_amps_sum = 0;
418 static double horizontal_speed_sum = 0;
419 static float current_amps_filtered = 0;
420 static float horizontal_speed_filtered = 0;
422 current_amps_sum = (current_amps_sum - current_amps_filtered) + current_amps;
424 current_amps = current_amps_filtered;
426 horizontal_speed_sum = (horizontal_speed_sum - horizontal_speed_filtered) + horizontal_speed;
428 horizontal_speed = horizontal_speed_filtered;
434 static uint64_t current_amps_sum = 0;
435 static uint64_t horizontal_speed_sum = 0;
436 static uint32_t current_amps_filtered = 0;
437 static uint32_t horizontal_speed_filtered = 0;
440 current_amps_int = (
uint32_t)(current_amps * 1000.0);
441 horizontal_speed_int = (
uint32_t)(horizontal_speed * 1000.0);
443 current_amps_sum = (current_amps_sum - current_amps_filtered) + current_amps_int;
447 horizontal_speed_sum = (horizontal_speed_sum - horizontal_speed_filtered) + horizontal_speed_int;
451 current_amps = (float)(current_amps_filtered) / 1000.;
452 horizontal_speed = (float)(horizontal_speed_filtered) / 1000.;
465 int8_t x = 0,
idx = 0, post_offset = 0, aft_offset = 0, string_len = 0;
468 if (row > 15) { column = 15; }
469 if (column > 29) { column = 29; }
478 if (attributes &
C_JUST) {
479 if (char_nb % 2 == 0) { char_nb++; }
480 post_offset = (char_nb - string_len) / 2;
481 aft_offset = char_nb - string_len;
482 if (((
int8_t)column - (char_nb / 2)) >= 0) { column -= (char_nb / 2); }
483 for (x = 0; x < 30; x++) { osd_buf[x] = 0; }
485 for (x = 0; x < string_len; x++) { osd_buf[post_offset + x] =
osd_string[x]; }
486 osd_buf[string_len + aft_offset] = 0xFF;
489 do {
osd_string[x] = osd_buf[x]; }
while (osd_buf[x++] != 0xFF);
490 }
else if (attributes &
R_JUST) {
493 if (((
int8_t)column - char_nb) >= 0) { column -= char_nb; }
494 if (((
int8_t)char_nb - string_len) >= 0) { post_offset = char_nb - string_len; }
else {post_offset = 0; }
505 for (; x < char_nb; x++) {
osd_string[x] = 0; }
536 char to_asc[10] = {48, 48, 48, 48, 48, 48, 48, 48, 48, 48};
541 for (x = 0; x <
sizeof(string_buf); x++) { string_buf[x] = 0; }
544 for (x = 0; x <
sizeof(string_buf); x++) { string_buf[x] = *(
string + x);
if (string_buf[x] ==
'\0') {
break; } }
550 while (string_buf[x] !=
'\0') {
552 if (string_buf[x] ==
'%') {
if (string_buf[x + 4] ==
'c') { (param_start = x + 1); param_end = x + 3;
break; } }
555 if (param_end - param_start) {
557 string_buf[x] = ((string_buf[param_start] - 48) * 100) + ((string_buf[param_start + 1] - 48) * 10) +
558 (string_buf[param_start + 2] - 48);
563 for (y = (x + 4); y <=
sizeof(string_buf); y++) { string_buf[x++] = string_buf[y]; }
565 }
while ((param_end - param_start > 0));
573 while (string_buf[x] !=
'\0') {
574 if (string_buf[x] ==
'%') {
577 }
else if (string_buf[x] ==
'f') { param_end = x;
break; }
580 if (param_end - param_start) {
582 frac_nb = string_buf[param_end - 1] - 48;
583 if (frac_nb > 3) { frac_nb = 3; }
585 y = (
sizeof(to_asc) - 1);
588 if (frac_nb > 0 && frac_nb <= 3) {
594 digit = (i_frac / x);
595 to_asc[y + z] = digit + 48;
609 to_asc[y] = (i_dec % 10) + 48;
612 if (value < 0) { y--; to_asc[y] =
'-'; }
620 for (x = 0; x < param_start; x++) { *(buffer + x) = string_buf[x]; }
624 while (y <
sizeof(to_asc)) { *(buffer + x) = to_asc[y]; x++; y++; }
629 *(buffer + x++) = string_buf[param_end];
631 }
while (string_buf[param_end] !=
'\0');
635 for (x = 0; x <
sizeof(string_buf); x++) {
636 *(buffer + x) = string_buf[x];
637 if (*(buffer + x) ==
'\0') {
break; }
648 float distance_to_home = 0;
649 static float home_direction_degrees = 0;
650#if defined(BARO_ALTITUDE_VAR)
651 static float baro_alt_correction = 0;
656#if defined(FIXEDWING_FIRMWARE)
665 distance_to_home = (float)(sqrt(ph_x * ph_x + ph_y * ph_y));
667#if defined(FIXEDWING_FIRMWARE)
679#if defined(FIXEDWING_FIRMWARE)
695 if (home_direction_degrees < 0) { home_direction_degrees += 360; }
696 if (home_direction_degrees >= 360) { home_direction_degrees -= 360; }
698#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
722#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
730#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
742#if defined(FIXEDWING_FIRMWARE)
755#if defined(FIXEDWING_FIRMWARE)
765#if defined(FIXEDWING_FIRMWARE)
766#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
786#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
798#if defined(BARO_ALTITUDE_VAR)
800 RunOnceEvery((MAX7456_PERIODIC_FREQ * 300), { baro_alt_correction =
GetPosAlt() - BARO_ALTITUDE_VAR;});
803 altitude = BARO_ALTITUDE_VAR + baro_alt_correction;
808#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
818#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
832#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
845#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
863 if (DegOfRad(att->
theta) > 3) {
872 if (DegOfRad(att->
theta) < -3) {
881 if (DegOfRad(att->
phi) > 3) {
885 }
else {
osd_put_s(
" ",
false, 5, 8, 18); }
890 if (DegOfRad(att->
phi) < -3) {
899#if defined(USE_MATEK_TYPE_OSD_CHIP) && USE_MATEK_TYPE_OSD_CHIP == 1
908 default:
step = 0;
break;
1005#if USE_PAL_FOR_OSD_VIDEO
1006#pragma message "Camera and OSD must be both PAL or NTSC otherwise only the camera picture will be visible."
#define ABI_BROADCAST
Broadcast address.
struct pprz_autopilot autopilot
Global autopilot structure.
Core autopilot interface common to all firmwares.
Hardware independent code for commands handling.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
struct Electrical electrical
Interface for electrical status: supply voltage, current, battery status, etc.
#define LOW_BAT_LEVEL
low battery level in Volts (for 3S LiPo)
Some architecture independent helper functions for GPIOs.
struct GpsState gps
global GPS state
#define GPS_FIX_3D
3D GPS fix
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
@ SPICpolIdleLow
CPOL = 0.
@ SPISelectUnselect
slave is selected before transaction and unselected after
SPI transaction structure.
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
struct imu_mag_t * imu_get_mag(uint8_t sender_id, bool create)
Find or create the mag in the imu structure.
struct Int32Vect3 scaled
Last scaled values in body frame.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
static void draw_osd(void)
#define SPEED_LOW_PASS_FILTER_STRENGTH
uint8_t max7456_osd_status
void max7456_periodic(void)
static bool _osd_sprintf(char *buffer, char *string, float value)
static void osd_put_s(char *string, uint8_t attributes, uint8_t char_nb, uint8_t row, uint8_t column)
static void calc_flight_time_left(void)
static void vSubtractVectors(VECTOR *svA, VECTOR svB, VECTOR svC)
static void vMultiplyMatrixByVector(VECTOR *svA, MATRIX smB, VECTOR svC)
struct spi_transaction max7456_trans
char osd_str_buf[OSD_STRING_SIZE]
uint32_t max_flyable_distance_left
static char ascii_to_osd_c(char c)
char osd_string[OSD_STRING_SIZE]
uint16_t osd_char_address
#define AMPS_LOW_PASS_FILTER_STRENGTH
uint8_t osd_spi_rx_buffer[2]
uint8_t osd_spi_tx_buffer[2]
static float home_direction(void)
Maxim MAX7456 single-channel monochrome on-screen display driver.
Maxim MAX7456 single-channel monochrome on-screen display driver.
#define OSD_AUTO_INCREMENT_MODE
#define OSD_NVRAM_BUSY_FLAG
#define OSD_RESET_BUSY_FLAG
#define OSD_INVERT_PIXELS
#define OSD_VIDEO_MODE_PAL
float waypoint_get_x(uint8_t wp_id)
Get X/East coordinate of waypoint in meters.
float waypoint_get_y(uint8_t wp_id)
Get Y/North coordinate of waypoint in meters.
#define GetPosAlt()
Get current altitude above MSL.
#define GetAltRef()
Get current altitude reference for local coordinates.
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
vector in East North Up coordinates Units: meters
Rotorcraft navigation functions.
Architecture independent SPI (Serial Peripheral Interface) API.
struct Stabilization stabilization
API to get/set the generic vehicle states.
Architecture independent timing functions.
Periodic telemetry system header (includes downlink utility and generated code).
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned long long uint64_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.