AP_ESC_Telem: support set_rpm_scale() call for scripting
This commit is contained in:
parent
8b601fbf63
commit
e7ab8147b3
@ -171,6 +171,13 @@ bool AP_ESC_Telem::get_rpm(uint8_t esc_index, float& rpm) const
|
|||||||
&& (now - rpmdata.last_update_us < ESC_RPM_DATA_TIMEOUT_US)) {
|
&& (now - rpmdata.last_update_us < ESC_RPM_DATA_TIMEOUT_US)) {
|
||||||
const float slew = MIN(1.0f, (now - rpmdata.last_update_us) * rpmdata.update_rate_hz * (1.0f / 1e6f));
|
const float slew = MIN(1.0f, (now - rpmdata.last_update_us) * rpmdata.update_rate_hz * (1.0f / 1e6f));
|
||||||
rpm = (rpmdata.prev_rpm + (rpmdata.rpm - rpmdata.prev_rpm) * slew);
|
rpm = (rpmdata.prev_rpm + (rpmdata.rpm - rpmdata.prev_rpm) * slew);
|
||||||
|
|
||||||
|
#if AP_SCRIPTING_ENABLED
|
||||||
|
if ((1U<<esc_index) & rpm_scale_mask) {
|
||||||
|
rpm *= rpm_scale_factor[esc_index];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -507,6 +514,19 @@ void AP_ESC_Telem::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if AP_SCRIPTING_ENABLED
|
||||||
|
/*
|
||||||
|
set RPM scale factor from script
|
||||||
|
*/
|
||||||
|
void AP_ESC_Telem::set_rpm_scale(const uint8_t esc_index, const float scale_factor)
|
||||||
|
{
|
||||||
|
if (esc_index < ESC_TELEM_MAX_ESCS) {
|
||||||
|
rpm_scale_factor[esc_index] = scale_factor;
|
||||||
|
rpm_scale_mask |= (1U<<esc_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AP_ESC_Telem *AP_ESC_Telem::_singleton = nullptr;
|
AP_ESC_Telem *AP_ESC_Telem::_singleton = nullptr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -100,6 +100,14 @@ public:
|
|||||||
// callback to update the rpm in the frontend, should be called by the driver when new data is available
|
// callback to update the rpm in the frontend, should be called by the driver when new data is available
|
||||||
// can also be called from scripting
|
// can also be called from scripting
|
||||||
void update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate);
|
void update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate);
|
||||||
|
|
||||||
|
#if AP_SCRIPTING_ENABLED
|
||||||
|
/*
|
||||||
|
set RPM scale factor from script
|
||||||
|
*/
|
||||||
|
void set_rpm_scale(const uint8_t esc_index, const float scale_factor);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// callback to update the data in the frontend, should be called by the driver when new data is available
|
// callback to update the data in the frontend, should be called by the driver when new data is available
|
||||||
@ -114,6 +122,12 @@ private:
|
|||||||
uint32_t _last_rpm_log_us[ESC_TELEM_MAX_ESCS];
|
uint32_t _last_rpm_log_us[ESC_TELEM_MAX_ESCS];
|
||||||
uint8_t next_idx;
|
uint8_t next_idx;
|
||||||
|
|
||||||
|
#if AP_SCRIPTING_ENABLED
|
||||||
|
// allow for scaling of RPMs via lua scripts
|
||||||
|
float rpm_scale_factor[ESC_TELEM_MAX_ESCS];
|
||||||
|
uint32_t rpm_scale_mask;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool _have_data;
|
bool _have_data;
|
||||||
|
|
||||||
AP_Int8 mavlink_offset;
|
AP_Int8 mavlink_offset;
|
||||||
|
Loading…
Reference in New Issue
Block a user