mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 03:03:34 +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; }
|
||||
|
||||
Reference in New Issue
Block a user