mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-17 11:47:35 +08:00
change trim units from absolute usec to normalized values
This commit is contained in:
committed by
Lorenz Meier
parent
d8528f46ce
commit
dbc149c224
@@ -338,7 +338,7 @@ public:
|
||||
* Invoke the set_offset method of each mixer in the group
|
||||
* for each value in page r_page_servo_control_trim
|
||||
*/
|
||||
unsigned set_trims(uint16_t *v, unsigned n);
|
||||
unsigned set_trims(int16_t *v, unsigned n);
|
||||
|
||||
unsigned set_trim(float trim)
|
||||
{
|
||||
|
||||
@@ -112,21 +112,21 @@ MixerGroup::mix(float *outputs, unsigned space, uint16_t *status_reg)
|
||||
return index;
|
||||
}
|
||||
|
||||
/*
|
||||
* set_trims() has no effect except for the SimpleMixer implementation for which set_trim()
|
||||
* always returns the value one.
|
||||
* The only other existing implementation is MultirotorMixer, which ignores the trim value
|
||||
* and returns _rotor_count.
|
||||
*/
|
||||
unsigned
|
||||
MixerGroup::set_trims(uint16_t *values, unsigned n)
|
||||
MixerGroup::set_trims(int16_t *values, unsigned n)
|
||||
{
|
||||
Mixer *mixer = _first;
|
||||
unsigned index = 0;
|
||||
|
||||
while ((mixer != nullptr) && (index < n)) {
|
||||
/*
|
||||
* hardwired assumption that PWM output range is [1000, 2000] usec
|
||||
*
|
||||
* This only works with SimpleMixer::set_trim(float) which always returns the value one,
|
||||
* but the only other existing implementation is MultirotorMixer, which ignores
|
||||
* the trim value.
|
||||
*/
|
||||
float offset = ((float)values[index] - 1500) / 500;
|
||||
/* convert from integer to float */
|
||||
float offset = (float)values[index] / 10000;
|
||||
|
||||
/* to be safe, clamp offset to range of [-100, 100] usec */
|
||||
if (offset < -0.2f) { offset = -0.2f; }
|
||||
|
||||
@@ -56,7 +56,7 @@ void pwm_limit_init(pwm_limit_t *limit)
|
||||
}
|
||||
|
||||
void pwm_limit_calc(const bool armed, const bool pre_armed, const unsigned num_channels, const uint16_t reverse_mask,
|
||||
const uint16_t *disarmed_pwm, const uint16_t *min_pwm, const uint16_t *max_pwm, const uint16_t *trim_pwm,
|
||||
const uint16_t *disarmed_pwm, const uint16_t *min_pwm, const uint16_t *max_pwm,
|
||||
const float *output, uint16_t *effective_pwm, pwm_limit_t *limit)
|
||||
{
|
||||
|
||||
@@ -207,16 +207,8 @@ void pwm_limit_calc(const bool armed, const bool pre_armed, const unsigned num_c
|
||||
control_value = -1.0f * control_value;
|
||||
}
|
||||
|
||||
// if (trim_pwm[i] == 0) {
|
||||
effective_pwm[i] = control_value * (max_pwm[i] - min_pwm[i]) / 2 + (max_pwm[i] + min_pwm[i]) / 2;
|
||||
|
||||
// } else if (control_value < 0) {
|
||||
// effective_pwm[i] = control_value * (trim_pwm[i] - min_pwm[i]) + trim_pwm[i];
|
||||
//
|
||||
// } else {
|
||||
// effective_pwm[i] = control_value * (max_pwm[i] - trim_pwm[i]) + trim_pwm[i];
|
||||
// }
|
||||
|
||||
/* last line of defense against invalid inputs */
|
||||
if (effective_pwm[i] < min_pwm[i]) {
|
||||
effective_pwm[i] = min_pwm[i];
|
||||
|
||||
@@ -73,7 +73,7 @@ __EXPORT void pwm_limit_init(pwm_limit_t *limit);
|
||||
|
||||
__EXPORT void pwm_limit_calc(const bool armed, const bool pre_armed, const unsigned num_channels,
|
||||
const uint16_t reverse_mask, const uint16_t *disarmed_pwm,
|
||||
const uint16_t *min_pwm, const uint16_t *max_pwm, const uint16_t *trim_pwm,
|
||||
const uint16_t *min_pwm, const uint16_t *max_pwm,
|
||||
const float *output, uint16_t *effective_pwm, pwm_limit_t *limit);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user