Skip to content

Commit

Permalink
AP_OSD: use get_max_rpm_esc()
Browse files Browse the repository at this point in the history
allow ESC index to be specified for OSD ESC info
  • Loading branch information
andyp1per authored and tridge committed Jun 26, 2024
1 parent 0387356 commit 451c1ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
3 changes: 3 additions & 0 deletions libraries/AP_OSD/AP_OSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class AP_OSD_Screen : public AP_OSD_AbstractScreen
AP_Int8 txt_resolution;
AP_Int8 font_index;
#endif
#if HAL_WITH_ESC_TELEM
AP_Int8 esc_index;
#endif

void draw_altitude(uint8_t x, uint8_t y);
void draw_bat_volt(uint8_t instance,VoltageType type,uint8_t x, uint8_t y);
Expand Down
39 changes: 30 additions & 9 deletions libraries/AP_OSD/AP_OSD_Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = {
#if HAL_WITH_ESC_TELEM
// @Param: ESCTEMP_EN
// @DisplayName: ESCTEMP_EN
// @Description: Displays first esc's temp
// @Description: Displays highest temp of all active ESCs, or of a specific ECS if OSDx_ESC_IDX is set
// @Values: 0:Disabled,1:Enabled

// @Param: ESCTEMP_X
Expand All @@ -374,7 +374,7 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = {

// @Param: ESCRPM_EN
// @DisplayName: ESCRPM_EN
// @Description: Displays first esc's rpm
// @Description: Displays highest rpm of all active ESCs, or of a specific ESC if OSDx_ESC_IDX is set
// @Values: 0:Disabled,1:Enabled

// @Param: ESCRPM_X
Expand All @@ -390,7 +390,7 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info[] = {

// @Param: ESCAMPS_EN
// @DisplayName: ESCAMPS_EN
// @Description: Displays first esc's current
// @Description: Displays the current of the ESC with the highest rpm of all active ESCs, or of a specific ESC if OSDx_ESC_IDX is set
// @Values: 0:Disabled,1:Enabled

// @Param: ESCAMPS_X
Expand Down Expand Up @@ -1166,6 +1166,14 @@ const AP_Param::GroupInfo AP_OSD_Screen::var_info2[] = {
AP_SUBGROUPINFO(rc_lq, "RC_LQ", 9, AP_OSD_Screen, AP_OSD_Setting),
#endif

#if HAL_WITH_ESC_TELEM
// @Param: ESC_IDX
// @DisplayName: ESC_IDX
// @Description: Index of the ESC to use for displaying ESC information. 0 means use the ESC with the highest value.
// @Range: 0 32
AP_GROUPINFO("ESC_IDX", 10, AP_OSD_Screen, esc_index, 0),
#endif

AP_GROUPEND
};

Expand Down Expand Up @@ -2003,8 +2011,13 @@ void AP_OSD_Screen::draw_vspeed(uint8_t x, uint8_t y)
void AP_OSD_Screen::draw_esc_temp(uint8_t x, uint8_t y)
{
int16_t etemp;
// first parameter is index into array of ESC's. Hardwire to zero (first) for now.
if (!AP::esc_telem().get_temperature(0, etemp)) {

if (esc_index > 0) {
if (!AP::esc_telem().get_motor_temperature(esc_index-1, etemp)) {
return;
}
}
else if (!AP::esc_telem().get_highest_motor_temperature(etemp)) {
return;
}

Expand All @@ -2014,8 +2027,12 @@ void AP_OSD_Screen::draw_esc_temp(uint8_t x, uint8_t y)
void AP_OSD_Screen::draw_esc_rpm(uint8_t x, uint8_t y)
{
float rpm;
// first parameter is index into array of ESC's. Hardwire to zero (first) for now.
if (!AP::esc_telem().get_rpm(0, rpm)) {
uint8_t esc = AP::esc_telem().get_max_rpm_esc();
if (esc_index > 0) {
if (!AP::esc_telem().get_rpm(esc_index-1, rpm)) {
return;
}
} else if (!AP::esc_telem().get_rpm(esc, rpm)) {
return;
}
float krpm = rpm * 0.001f;
Expand All @@ -2026,8 +2043,12 @@ void AP_OSD_Screen::draw_esc_rpm(uint8_t x, uint8_t y)
void AP_OSD_Screen::draw_esc_amps(uint8_t x, uint8_t y)
{
float amps;
// first parameter is index into array of ESC's. Hardwire to zero (first) for now.
if (!AP::esc_telem().get_current(0, amps)) {
uint8_t esc = AP::esc_telem().get_max_rpm_esc();
if (esc_index > 0) {
if (!AP::esc_telem().get_current(esc_index-1, amps)) {
return;
}
} else if (!AP::esc_telem().get_current(esc, amps)) {
return;
}
backend->write(x, y, false, "%4.1f%c", amps, SYMBOL(SYM_AMP));
Expand Down

0 comments on commit 451c1ae

Please sign in to comment.