mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
Move param handles in rc_update into unified struct
- To follow structure & matthias recommendation
This commit is contained in:
@@ -66,13 +66,13 @@ RCUpdate::RCUpdate() :
|
|||||||
ModuleParams(nullptr),
|
ModuleParams(nullptr),
|
||||||
WorkItem(MODULE_NAME, px4::wq_configurations::hp_default),
|
WorkItem(MODULE_NAME, px4::wq_configurations::hp_default),
|
||||||
_trigger_slots_hysteresis{
|
_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
|
// initialize parameter handles
|
||||||
for (unsigned i = 0; i < RC_MAX_CHAN_COUNT; i++) {
|
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
|
// shifted by 1 because param name starts at 1
|
||||||
char name[rc_parameter_map_s::PARAM_ID_LEN];
|
char name[rc_parameter_map_s::PARAM_ID_LEN];
|
||||||
snprintf(name, rc_parameter_map_s::PARAM_ID_LEN, "RC_MAP_PARAM%d", i + 1);
|
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)
|
// Find param handles for Generic Trigger Channel & Actions for slot 1 ~ 6
|
||||||
char param_name_buf[17] = {};
|
|
||||||
for (uint8_t trig_slot = 1; trig_slot <= RC_TRIG_SLOT_COUNT; trig_slot++) {
|
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);
|
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);
|
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 */);
|
rc_parameter_map_poll(true /* forced */);
|
||||||
@@ -171,6 +171,16 @@ void RCUpdate::parameters_updated()
|
|||||||
|
|
||||||
update_rc_functions();
|
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
|
// deprecated parameters, will be removed post v1.12 once QGC is updated
|
||||||
{
|
{
|
||||||
int32_t rc_map_value = 0;
|
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++) {
|
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;
|
_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)
|
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
|
// Use the Generic RC Switch / Button only when the RC is in use
|
||||||
if (_manual_control_setpoint_sub.update() &&
|
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;
|
_manual_control_setpoint_source_is_rc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go through the trigger slots and update the states
|
// Go through the trigger slots and update the states
|
||||||
const uint32_t rc_trigger_is_button_mask = _param_rc_trig_btn_mask.get();
|
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++) {
|
for (uint8_t trig_slot = 1; trig_slot <= RC_TRIG_SLOT_COUNT; trig_slot++) {
|
||||||
int channel{RC_TRIG_CHAN_UNASSIGNED};
|
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};
|
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) {
|
if (channel > RC_TRIG_CHAN_UNASSIGNED) {
|
||||||
|
|
||||||
@@ -610,13 +619,14 @@ void RCUpdate::UpdateManualSwitches(const hrt_abstime ×tamp_sample)
|
|||||||
// Update the Generic Action states
|
// Update the Generic Action states
|
||||||
const uint8_t trig1_chan = _param_rc_trig1_chan.get();
|
const uint8_t trig1_chan = _param_rc_trig1_chan.get();
|
||||||
const uint8_t trig1_action = _param_rc_trig1_action.get();
|
const uint8_t trig1_action = _param_rc_trig1_action.get();
|
||||||
|
|
||||||
// Trigger Channel is configured
|
// Trigger Channel is configured
|
||||||
if (trig1_chan > 0) {
|
if (trig1_chan > 0) {
|
||||||
const bool is_btn = _param_rc_trig_btn_mask.get() & (1 << 0);
|
const bool is_btn = _param_rc_trig_btn_mask.get() & (1 << 0);
|
||||||
|
|
||||||
if (is_btn) {
|
if (is_btn) {
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Is Switch
|
// Is Switch
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,11 +69,15 @@ namespace rc_update
|
|||||||
|
|
||||||
// Number of Generic Trigger slots that can be configured
|
// Number of Generic Trigger slots that can be configured
|
||||||
static constexpr uint8_t RC_TRIG_SLOT_COUNT = 6;
|
static constexpr uint8_t RC_TRIG_SLOT_COUNT = 6;
|
||||||
|
|
||||||
// Value of the RC_TRIG#_CHAN when the channel is unassigned
|
// Value of the RC_TRIG#_CHAN when the channel is unassigned
|
||||||
static constexpr uint8_t RC_TRIG_CHAN_UNASSIGNED = 0;
|
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
|
// Enum class translation of the RC_TRIG#_ACTION values
|
||||||
static constexpr enum RC_TRIGGER_ACTIONS {
|
enum RC_TRIGGER_ACTIONS {
|
||||||
RC_TRIGGER_ACTION_UNASSIGNED = -1,
|
RC_TRIGGER_ACTION_UNASSIGNED = -1,
|
||||||
// Commander States (defined in commander_state.msg)
|
// Commander States (defined in commander_state.msg)
|
||||||
RC_TRIGGER_ACTION_MANUAL_FLIGHTMODE = 0,
|
RC_TRIGGER_ACTION_MANUAL_FLIGHTMODE = 0,
|
||||||
@@ -176,6 +180,9 @@ private:
|
|||||||
bool rev[RC_MAX_CHAN_COUNT];
|
bool rev[RC_MAX_CHAN_COUNT];
|
||||||
|
|
||||||
int32_t rc_map_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN];
|
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{};
|
} _parameters{};
|
||||||
|
|
||||||
struct ParameterHandles {
|
struct ParameterHandles {
|
||||||
@@ -186,10 +193,12 @@ private:
|
|||||||
param_t dz[RC_MAX_CHAN_COUNT];
|
param_t dz[RC_MAX_CHAN_COUNT];
|
||||||
|
|
||||||
param_t rc_map_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN];
|
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
|
param_t rc_param[rc_parameter_map_s::RC_PARAM_MAP_NCHAN];
|
||||||
to a RC channel, equivalent float values in the
|
/**< param handles for the parameters which are bound to a RC channel, equivalent float values
|
||||||
_parameters struct are not existing
|
* in the_parameters struct are not existing because these parameters are never read. */
|
||||||
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{};
|
} _parameter_handles{};
|
||||||
|
|
||||||
uORB::SubscriptionCallbackWorkItem _input_rc_sub{this, ORB_ID(input_rc)};
|
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)
|
// 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};
|
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];
|
systemlib::Hysteresis _trigger_slots_hysteresis[RC_TRIG_SLOT_COUNT];
|
||||||
param_t _trigger_channel_param_handles[RC_TRIG_SLOT_COUNT] {};
|
param_t _trigger_channel_param_handles[RC_TRIG_SLOT_COUNT] {};
|
||||||
param_t _trigger_action_param_handles[RC_TRIG_SLOT_COUNT] {};
|
param_t _trigger_action_param_handles[RC_TRIG_SLOT_COUNT] {};
|
||||||
|
|||||||
Reference in New Issue
Block a user