diff --git a/src/modules/rc_update/rc_update.cpp b/src/modules/rc_update/rc_update.cpp index 090e0d3cd8..f908c39dda 100644 --- a/src/modules/rc_update/rc_update.cpp +++ b/src/modules/rc_update/rc_update.cpp @@ -66,13 +66,13 @@ RCUpdate::RCUpdate() : ModuleParams(nullptr), WorkItem(MODULE_NAME, px4::wq_configurations::hp_default), _trigger_slots_hysteresis{ - systemlib::Hysteresis{false}, - systemlib::Hysteresis{false}, - systemlib::Hysteresis{false}, - systemlib::Hysteresis{false}, - systemlib::Hysteresis{false}, - systemlib::Hysteresis{false} - } + systemlib::Hysteresis{false}, + systemlib::Hysteresis{false}, + systemlib::Hysteresis{false}, + systemlib::Hysteresis{false}, + systemlib::Hysteresis{false}, + systemlib::Hysteresis{false} +} { // initialize parameter handles for (unsigned i = 0; i < RC_MAX_CHAN_COUNT; i++) { @@ -104,16 +104,16 @@ RCUpdate::RCUpdate() : // shifted by 1 because param name starts at 1 char name[rc_parameter_map_s::PARAM_ID_LEN]; snprintf(name, rc_parameter_map_s::PARAM_ID_LEN, "RC_MAP_PARAM%d", i + 1); - _trigger_channel_param_handles.rc_map_param[i] = param_find(name); + _parameter_handles.rc_map_param[i] = param_find(name); } - // Find and set RC Channel & Actions for each Trigger actions (1 ~ 6) - char param_name_buf[17] = {}; + // Find param handles for Generic Trigger Channel & Actions for slot 1 ~ 6 for (uint8_t trig_slot = 1; trig_slot <= RC_TRIG_SLOT_COUNT; trig_slot++) { + char param_name_buf[17] = {}; snprintf(param_name_buf, sizeof(param_name_buf), "RC_TRIG_%d_CHAN", trig_slot); - _trigger_channel_param_handles[trig_slot - 1] = param_find(param_name_buf); + _parameter_handles.generic_trigger_chan[trig_slot - 1] = param_find(param_name_buf); snprintf(param_name_buf, sizeof(param_name_buf), "RC_TRIG_%d_ACTION", trig_slot); - _trigger_action_param_handles[trig_slot - 1] = param_find(param_name_buf); + _parameter_handles.generic_trigger_action[trig_slot - 1] = param_find(param_name_buf); } rc_parameter_map_poll(true /* forced */); @@ -171,6 +171,16 @@ void RCUpdate::parameters_updated() update_rc_functions(); + // Update and check values of the generic action parameters + for (uint8_t trig_slot = 1; trig_slot <= RC_TRIG_SLOT_COUNT; trig_slot++) { + int32_t new_channel{RC_TRIG_CHAN_UNASSIGNED}; + int32_t new_action{RC_TRIG_ACTION_UNASSIGNED}; + param_get(_parameter_handles.generic_trigger_chan[trig_slot - 1], &new_channel); + param_get(_parameter_handles.generic_trigger_action[trig_slot - 1], &new_action); + + + } + // deprecated parameters, will be removed post v1.12 once QGC is updated { int32_t rc_map_value = 0; @@ -247,8 +257,6 @@ void RCUpdate::update_rc_functions() for (int i = 0; i < rc_parameter_map_s::RC_PARAM_MAP_NCHAN; i++) { _rc.function[rc_channels_s::FUNCTION_PARAM_1 + i] = _parameters.rc_map_param[i] - 1; } - - map_flight_modes_buttons(); } void RCUpdate::rc_parameter_map_poll(bool forced) @@ -590,17 +598,18 @@ void RCUpdate::UpdateManualSwitches(const hrt_abstime ×tamp_sample) // Use the Generic RC Switch / Button only when the RC is in use if (_manual_control_setpoint_sub.update() && - _manual_control_setpoint_sub.get().data_source == manual_control_setpoint_s::SOURCE_RC) { + _manual_control_setpoint_sub.get().data_source == manual_control_setpoint_s::SOURCE_RC) { _manual_control_setpoint_source_is_rc = true; } // Go through the trigger slots and update the states const uint32_t rc_trigger_is_button_mask = _param_rc_trig_btn_mask.get(); + for (uint8_t trig_slot = 1; trig_slot <= RC_TRIG_SLOT_COUNT; trig_slot++) { int channel{RC_TRIG_CHAN_UNASSIGNED}; - param_get(_trigger_channel_param_handles[trig_slot-1], &channel); + param_get(_trigger_channel_param_handles[trig_slot - 1], &channel); int action{RC_TRIGGER_ACTION_UNASSIGNED}; - param_get(_trigger_action_param_handles[trig_slot-1], &action); + param_get(_trigger_action_param_handles[trig_slot - 1], &action); if (channel > RC_TRIG_CHAN_UNASSIGNED) { @@ -610,13 +619,14 @@ void RCUpdate::UpdateManualSwitches(const hrt_abstime ×tamp_sample) // Update the Generic Action states const uint8_t trig1_chan = _param_rc_trig1_chan.get(); const uint8_t trig1_action = _param_rc_trig1_action.get(); + // Trigger Channel is configured if (trig1_chan > 0) { const bool is_btn = _param_rc_trig_btn_mask.get() & (1 << 0); + if (is_btn) { - } - else { + } else { // Is Switch } diff --git a/src/modules/rc_update/rc_update.h b/src/modules/rc_update/rc_update.h index e9c2b823a4..be2255d7d5 100644 --- a/src/modules/rc_update/rc_update.h +++ b/src/modules/rc_update/rc_update.h @@ -69,11 +69,15 @@ namespace rc_update // Number of Generic Trigger slots that can be configured static constexpr uint8_t RC_TRIG_SLOT_COUNT = 6; + // Value of the RC_TRIG#_CHAN when the channel is unassigned static constexpr uint8_t RC_TRIG_CHAN_UNASSIGNED = 0; +// Value of the RC_TRIG#_ACTION when the action is unassigned +static constexpr uint8_t RC_TRIG_ACTION_UNASSIGNED = -1; + // Enum class translation of the RC_TRIG#_ACTION values -static constexpr enum RC_TRIGGER_ACTIONS { +enum RC_TRIGGER_ACTIONS { RC_TRIGGER_ACTION_UNASSIGNED = -1, // Commander States (defined in commander_state.msg) RC_TRIGGER_ACTION_MANUAL_FLIGHTMODE = 0, @@ -176,6 +180,9 @@ private: bool rev[RC_MAX_CHAN_COUNT]; int32_t rc_map_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN]; + + uint8_t generic_trigger_chan[RC_TRIG_SLOT_COUNT]; + uint8_t generic_trigger_action[RC_TRIG_SLOT_COUNT]; } _parameters{}; struct ParameterHandles { @@ -186,10 +193,12 @@ private: param_t dz[RC_MAX_CHAN_COUNT]; param_t rc_map_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN]; - param_t rc_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN]; /**< param handles for the parameters which are bound - to a RC channel, equivalent float values in the - _parameters struct are not existing - because these parameters are never read. */ + param_t rc_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN]; + /**< param handles for the parameters which are bound to a RC channel, equivalent float values + * in the_parameters struct are not existing because these parameters are never read. */ + + param_t generic_trigger_chan[RC_TRIG_SLOT_COUNT]; + param_t generic_trigger_action[RC_TRIG_SLOT_COUNT]; } _parameter_handles{}; uORB::SubscriptionCallbackWorkItem _input_rc_sub{this, ORB_ID(input_rc)}; @@ -223,7 +232,6 @@ private: // Flag to indicate that RC input is being used for manual control (whether we can use generic action) bool _manual_control_setpoint_source_is_rc{false}; - // Hysteresis objects to track status of the each trigger slots for generic action systemlib::Hysteresis _trigger_slots_hysteresis[RC_TRIG_SLOT_COUNT]; param_t _trigger_channel_param_handles[RC_TRIG_SLOT_COUNT] {}; param_t _trigger_action_param_handles[RC_TRIG_SLOT_COUNT] {};