manual_contol_setpoint: fix mode slot numbering (#12578)

* This fix is necessary because usually uORB structs get initialized with
all zeros and then get filled with the fields that are actually in use.
 * The number 0 for the mode slot was already commanding to switch to the
mode in slot one even though for example the joystick input via mavlink
does not use this mechanism at all.
This commit is contained in:
Matthias Grob
2019-08-01 12:27:58 -04:00
committed by Daniel Agar
parent 5d986f2030
commit d0f1a551e9
3 changed files with 17 additions and 18 deletions
+5 -6
View File
@@ -350,9 +350,8 @@ RCUpdate::rc_poll(const ParameterHandles &parameter_handles)
manual.z = math::constrain(_filter_throttle.apply(manual.z), 0.f, 1.f);
if (_parameters.rc_map_flightmode > 0) {
/* the number of valid slots equals the index of the max marker minus one */
const int num_slots = manual_control_setpoint_s::MODE_SLOT_MAX;
/* number of valid slots */
const int num_slots = manual_control_setpoint_s::MODE_SLOT_NUM;
/* the half width of the range of a slot is the total range
* divided by the number of slots, again divided by two
@@ -369,10 +368,10 @@ RCUpdate::rc_poll(const ParameterHandles &parameter_handles)
* will take us to the correct final index.
*/
manual.mode_slot = (((((_rc.channels[_parameters.rc_map_flightmode - 1] - slot_min) * num_slots) + slot_width_half) /
(slot_max - slot_min)) + (1.0f / num_slots));
(slot_max - slot_min)) + (1.0f / num_slots)) + 1;
if (manual.mode_slot >= num_slots) {
manual.mode_slot = num_slots - 1;
if (manual.mode_slot > num_slots) {
manual.mode_slot = num_slots;
}
}