Skip to content

Commit ca3ea83

Browse files
committed
new manual_control_switches msg (split out of manual_control_setpoint)
1 parent 5e855c6 commit ca3ea83

23 files changed

+541
-473
lines changed

msg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ set(msg_files
7878
log_message.msg
7979
logger_status.msg
8080
manual_control_setpoint.msg
81+
manual_control_switches.msg
8182
mavlink_log.msg
8283
mission.msg
8384
mission_result.msg

msg/manual_control_setpoint.msg

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
uint64 timestamp # time since system start (microseconds)
22

3-
uint8 SWITCH_POS_NONE = 0 # switch is not mapped
4-
uint8 SWITCH_POS_ON = 1 # switch activated (value = 1)
5-
uint8 SWITCH_POS_MIDDLE = 2 # middle position (value = 0)
6-
uint8 SWITCH_POS_OFF = 3 # switch not activated (value = -1)
7-
uint8 MODE_SLOT_NONE = 0 # no mode slot assigned
8-
uint8 MODE_SLOT_1 = 1 # mode slot 1 selected
9-
uint8 MODE_SLOT_2 = 2 # mode slot 2 selected
10-
uint8 MODE_SLOT_3 = 3 # mode slot 3 selected
11-
uint8 MODE_SLOT_4 = 4 # mode slot 4 selected
12-
uint8 MODE_SLOT_5 = 5 # mode slot 5 selected
13-
uint8 MODE_SLOT_6 = 6 # mode slot 6 selected
14-
uint8 MODE_SLOT_NUM = 6 # number of slots
3+
uint64 timestamp_sample # the timestamp of the raw data (microseconds)
4+
155
uint8 SOURCE_RC = 1 # radio control
166
uint8 SOURCE_MAVLINK_0 = 2 # mavlink instance 0
177
uint8 SOURCE_MAVLINK_1 = 3 # mavlink instance 1
188
uint8 SOURCE_MAVLINK_2 = 4 # mavlink instance 2
199
uint8 SOURCE_MAVLINK_3 = 5 # mavlink instance 4
2010

11+
uint8 data_source # where this input is coming from
12+
2113
# Any of the channels may not be available and be set to NaN
2214
# to indicate that it does not contain valid data.
2315
# The variable names follow the definition of the
@@ -30,38 +22,28 @@ float32 x # stick position in x direction -1..1
3022
# in general corresponds to forward/back motion or pitch of vehicle,
3123
# in general a positive value means forward or negative pitch and
3224
# a negative value means backward or positive pitch
25+
3326
float32 y # stick position in y direction -1..1
3427
# in general corresponds to right/left motion or roll of vehicle,
3528
# in general a positive value means right or positive roll and
3629
# a negative value means left or negative roll
30+
3731
float32 z # throttle stick position 0..1
3832
# in general corresponds to up/down motion or thrust of vehicle,
3933
# in general the value corresponds to the demanded throttle by the user,
4034
# if the input is used for setting the setpoint of a vertical position
4135
# controller any value > 0.5 means up and any value < 0.5 means down
36+
4237
float32 r # yaw stick/twist position, -1..1
4338
# in general corresponds to the righthand rotation around the vertical
4439
# (downwards) axis of the vehicle
40+
4541
float32 flaps # flap position
42+
4643
float32 aux1 # default function: camera yaw / azimuth
4744
float32 aux2 # default function: camera pitch / tilt
4845
float32 aux3 # default function: camera trigger
4946
float32 aux4 # default function: camera roll
5047
float32 aux5 # default function: payload drop
5148
float32 aux6
5249

53-
uint8 mode_switch # main mode 3 position switch (mandatory): _MANUAL_, ASSIST, AUTO
54-
uint8 return_switch # return to launch 2 position switch (mandatory): _NORMAL_, RTL
55-
uint8 rattitude_switch # rattitude control 2 position switch (optional): _MANUAL, RATTITUDE
56-
uint8 posctl_switch # position control 2 position switch (optional): _ALTCTL_, POSCTL
57-
uint8 loiter_switch # loiter 2 position switch (optional): _MISSION_, LOITER
58-
uint8 acro_switch # acro 2 position switch (optional): _MANUAL_, ACRO
59-
uint8 offboard_switch # offboard 2 position switch (optional): _NORMAL_, OFFBOARD
60-
uint8 kill_switch # throttle kill: _NORMAL_, KILL
61-
uint8 arm_switch # arm/disarm switch: _DISARMED_, ARMED
62-
uint8 transition_switch # VTOL transition switch: _HOVER, FORWARD_FLIGHT
63-
uint8 gear_switch # landing gear switch: _DOWN_, UP
64-
uint8 mode_slot # the slot a specific model selector is in
65-
uint8 data_source # where this input is coming from
66-
uint8 stab_switch # stabilize switch (only relevant for fixed wings, optional): _MANUAL, STABILIZED
67-
uint8 man_switch # manual switch (only relevant for fixed wings, optional): _STABILIZED_, MANUAL

msg/manual_control_switches.msg

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
uint64 timestamp # time since system start (microseconds)
2+
3+
uint8 SWITCH_POS_NONE = 0 # switch is not mapped
4+
uint8 SWITCH_POS_ON = 1 # switch activated (value = 1)
5+
uint8 SWITCH_POS_MIDDLE = 2 # middle position (value = 0)
6+
uint8 SWITCH_POS_OFF = 3 # switch not activated (value = -1)
7+
8+
uint8 MODE_SLOT_NONE = 0 # no mode slot assigned
9+
uint8 MODE_SLOT_1 = 1 # mode slot 1 selected
10+
uint8 MODE_SLOT_2 = 2 # mode slot 2 selected
11+
uint8 MODE_SLOT_3 = 3 # mode slot 3 selected
12+
uint8 MODE_SLOT_4 = 4 # mode slot 4 selected
13+
uint8 MODE_SLOT_5 = 5 # mode slot 5 selected
14+
uint8 MODE_SLOT_6 = 6 # mode slot 6 selected
15+
uint8 MODE_SLOT_NUM = 6 # number of slots
16+
17+
uint8 mode_slot # the slot a specific model selector is in
18+
19+
uint8 arm_switch # arm/disarm switch: _DISARMED_, ARMED
20+
uint8 return_switch # return to launch 2 position switch (mandatory): _NORMAL_, RTL
21+
uint8 loiter_switch # loiter 2 position switch (optional): _MISSION_, LOITER
22+
uint8 offboard_switch # offboard 2 position switch (optional): _NORMAL_, OFFBOARD
23+
uint8 kill_switch # throttle kill: _NORMAL_, KILL
24+
uint8 gear_switch # landing gear switch: _DOWN_, UP
25+
uint8 transition_switch # VTOL transition switch: _HOVER, FORWARD_FLIGHT
26+
27+
# legacy "advanced" switch configuration (will be removed soon)
28+
uint8 mode_switch # main mode 3 position switch (mandatory): _MANUAL_, ASSIST, AUTO
29+
uint8 man_switch # manual switch (only relevant for fixed wings, optional): _STABILIZED_, MANUAL
30+
uint8 acro_switch # acro 2 position switch (optional): _MANUAL_, ACRO
31+
uint8 rattitude_switch # rattitude control 2 position switch (optional): _MANUAL, RATTITUDE
32+
uint8 stab_switch # stabilize switch (only relevant for fixed wings, optional): _MANUAL, STABILIZED
33+
uint8 posctl_switch # position control 2 position switch (optional): _ALTCTL_, POSCTL

msg/rc_channels.msg

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
uint64 timestamp # time since system start (microseconds)
22

3-
uint8 RC_CHANNELS_FUNCTION_THROTTLE=0
4-
uint8 RC_CHANNELS_FUNCTION_ROLL=1
5-
uint8 RC_CHANNELS_FUNCTION_PITCH=2
6-
uint8 RC_CHANNELS_FUNCTION_YAW=3
7-
uint8 RC_CHANNELS_FUNCTION_MODE=4
8-
uint8 RC_CHANNELS_FUNCTION_RETURN=5
9-
uint8 RC_CHANNELS_FUNCTION_POSCTL=6
10-
uint8 RC_CHANNELS_FUNCTION_LOITER=7
11-
uint8 RC_CHANNELS_FUNCTION_OFFBOARD=8
12-
uint8 RC_CHANNELS_FUNCTION_ACRO=9
13-
uint8 RC_CHANNELS_FUNCTION_FLAPS=10
14-
uint8 RC_CHANNELS_FUNCTION_AUX_1=11
15-
uint8 RC_CHANNELS_FUNCTION_AUX_2=12
16-
uint8 RC_CHANNELS_FUNCTION_AUX_3=13
17-
uint8 RC_CHANNELS_FUNCTION_AUX_4=14
18-
uint8 RC_CHANNELS_FUNCTION_AUX_5=15
19-
uint8 RC_CHANNELS_FUNCTION_PARAM_1=16
20-
uint8 RC_CHANNELS_FUNCTION_PARAM_2=17
21-
uint8 RC_CHANNELS_FUNCTION_PARAM_3_5=18
22-
uint8 RC_CHANNELS_FUNCTION_RATTITUDE=19
23-
uint8 RC_CHANNELS_FUNCTION_KILLSWITCH=20
24-
uint8 RC_CHANNELS_FUNCTION_TRANSITION=21
25-
uint8 RC_CHANNELS_FUNCTION_GEAR=22
26-
uint8 RC_CHANNELS_FUNCTION_ARMSWITCH=23
27-
uint8 RC_CHANNELS_FUNCTION_STAB=24
28-
uint8 RC_CHANNELS_FUNCTION_AUX_6=25
29-
uint8 RC_CHANNELS_FUNCTION_MAN=26
3+
uint8 FUNCTION_THROTTLE=0
4+
uint8 FUNCTION_ROLL=1
5+
uint8 FUNCTION_PITCH=2
6+
uint8 FUNCTION_YAW=3
7+
uint8 FUNCTION_MODE=4
8+
uint8 FUNCTION_RETURN=5
9+
uint8 FUNCTION_POSCTL=6
10+
uint8 FUNCTION_LOITER=7
11+
uint8 FUNCTION_OFFBOARD=8
12+
uint8 FUNCTION_ACRO=9
13+
uint8 FUNCTION_FLAPS=10
14+
uint8 FUNCTION_AUX_1=11
15+
uint8 FUNCTION_AUX_2=12
16+
uint8 FUNCTION_AUX_3=13
17+
uint8 FUNCTION_AUX_4=14
18+
uint8 FUNCTION_AUX_5=15
19+
uint8 FUNCTION_PARAM_1=16
20+
uint8 FUNCTION_PARAM_2=17
21+
uint8 FUNCTION_PARAM_3_5=18
22+
uint8 FUNCTION_RATTITUDE=19
23+
uint8 FUNCTION_KILLSWITCH=20
24+
uint8 FUNCTION_TRANSITION=21
25+
uint8 FUNCTION_GEAR=22
26+
uint8 FUNCTION_ARMSWITCH=23
27+
uint8 FUNCTION_STAB=24
28+
uint8 FUNCTION_AUX_6=25
29+
uint8 FUNCTION_MAN=26
3030

3131
uint64 timestamp_last_valid # Timestamp of last valid RC signal
3232
float32[18] channels # Scaled to -1..1 (throttle: 0..1)

msg/tools/uorb_rtps_message_ids.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ rtps:
289289
id: 138
290290
- msg: estimator_selector_status
291291
id: 139
292+
- msg: manual_control_switches
293+
id: 140
292294
########## multi topics: begin ##########
293295
- msg: actuator_controls_0
294296
id: 150

src/drivers/linux_pwm_out/linux_pwm_out.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void task_main(int argc, char *argv[])
322322
_controls[0].control[0] = 0.f;
323323
_controls[0].control[1] = 0.f;
324324
_controls[0].control[2] = 0.f;
325-
int channel = rc_channels.function[rc_channels_s::RC_CHANNELS_FUNCTION_THROTTLE];
325+
int channel = rc_channels.function[rc_channels_s::FUNCTION_THROTTLE];
326326

327327
if (ret == 0 && channel >= 0 && channel < (int)(sizeof(rc_channels.channels) / sizeof(rc_channels.channels[0]))) {
328328
_controls[0].control[3] = rc_channels.channels[channel];

src/lib/flight_tasks/tasks/AutoMapper/FlightTaskAutoMapper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ using namespace matrix;
4242

4343
FlightTaskAutoMapper::FlightTaskAutoMapper() :
4444
_sticks(this)
45-
{};
45+
{
46+
_gear.landing_gear = landing_gear_s::GEAR_KEEP;
47+
}
4648

4749
bool FlightTaskAutoMapper::activate(const vehicle_local_position_setpoint_s &last_setpoint)
4850
{
@@ -187,7 +189,7 @@ float FlightTaskAutoMapper::_getLandSpeed()
187189
// user input assisted land speed
188190
if (_param_mpc_land_rc_help.get()
189191
&& (_dist_to_ground < _param_mpc_land_alt1.get())
190-
&& _sticks.checkAndSetStickInputs(_time_stamp_current)) {
192+
&& _sticks.checkAndSetStickInputs()) {
191193
// stick full up -1 -> stop, stick full down 1 -> double the speed
192194
land_speed *= (1 + _sticks.getPositionExpo()(2));
193195
}

src/lib/flight_tasks/tasks/ManualAltitude/FlightTaskManualAltitude.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,32 @@ bool FlightTaskManualAltitude::updateInitialize()
5050
{
5151
bool ret = FlightTask::updateInitialize();
5252

53-
_sticks.checkAndSetStickInputs(_time_stamp_current);
54-
_sticks.setGearAccordingToSwitch(_gear);
53+
manual_control_switches_s manual_control_switches;
54+
55+
if (_manual_control_switches_sub.copy(&manual_control_switches) && (manual_control_switches.timestamp > 0)) {
56+
57+
const int8_t gear_switch = manual_control_switches.gear_switch;
58+
59+
if (_gear_switch_old != gear_switch) {
60+
if (gear_switch == manual_control_switches_s::SWITCH_POS_OFF) {
61+
_gear.landing_gear = landing_gear_s::GEAR_DOWN;
62+
}
63+
64+
if (gear_switch == manual_control_switches_s::SWITCH_POS_ON) {
65+
_gear.landing_gear = landing_gear_s::GEAR_UP;
66+
}
67+
}
68+
69+
_gear_switch_old = gear_switch;
70+
71+
} else {
72+
// Only switch the landing gear up if the user switched from gear down to gear up.
73+
// If the user had the switch in the gear up position and took off ignore it
74+
// until he toggles the switch to avoid retracting the gear immediately on takeoff.
75+
_gear.landing_gear = landing_gear_s::GEAR_KEEP;
76+
}
77+
78+
_sticks.checkAndSetStickInputs();
5579

5680
if (_sticks_data_required) {
5781
ret = ret && _sticks.isAvailable();

src/lib/flight_tasks/tasks/ManualAltitude/FlightTaskManualAltitude.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "FlightTask.hpp"
4343
#include "Sticks.hpp"
4444
#include <lib/ecl/AlphaFilter/AlphaFilter.hpp>
45+
#include <uORB/Subscription.hpp>
46+
#include <uORB/topics/manual_control_switches.h>
4547

4648
class FlightTaskManualAltitude : public FlightTask
4749
{
@@ -145,4 +147,9 @@ class FlightTaskManualAltitude : public FlightTask
145147
float _dist_to_ground_lock = NAN;
146148

147149
AlphaFilter<matrix::Vector2f> _man_input_filter;
150+
151+
uORB::Subscription _manual_control_switches_sub{ORB_ID(manual_control_switches)};
152+
153+
int _gear_switch_old{manual_control_switches_s::SWITCH_POS_NONE}; ///< old switch state
154+
148155
};

src/lib/flight_tasks/tasks/Utility/Sticks.cpp

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,23 @@ Sticks::Sticks(ModuleParams *parent) :
4444
ModuleParams(parent)
4545
{};
4646

47-
bool Sticks::checkAndSetStickInputs(hrt_abstime now)
47+
bool Sticks::checkAndSetStickInputs()
4848
{
49-
_sub_manual_control_setpoint.update();
50-
51-
hrt_abstime rc_timeout = (_param_com_rc_loss_t.get() * 1.5f) * 1_s;
52-
5349
// Sticks are rescaled linearly and exponentially to [-1,1]
54-
if ((now - _sub_manual_control_setpoint.get().timestamp) < rc_timeout) {
50+
manual_control_setpoint_s manual_control_setpoint;
51+
52+
if (_manual_control_setpoint_sub.update(&manual_control_setpoint)) {
5553
// Linear scale
56-
_positions(0) = _sub_manual_control_setpoint.get().x; // NED x, pitch [-1,1]
57-
_positions(1) = _sub_manual_control_setpoint.get().y; // NED y, roll [-1,1]
58-
_positions(2) = -(_sub_manual_control_setpoint.get().z - 0.5f) * 2.f; // NED z, thrust resacaled from [0,1] to [-1,1]
59-
_positions(3) = _sub_manual_control_setpoint.get().r; // yaw [-1,1]
54+
_positions(0) = manual_control_setpoint.x; // NED x, pitch [-1,1]
55+
_positions(1) = manual_control_setpoint.y; // NED y, roll [-1,1]
56+
_positions(2) = -(manual_control_setpoint.z - 0.5f) * 2.f; // NED z, thrust resacaled from [0,1] to [-1,1]
57+
_positions(3) = manual_control_setpoint.r; // yaw [-1,1]
6058

6159
// Exponential scale
6260
_positions_expo(0) = math::expo_deadzone(_positions(0), _param_mpc_xy_man_expo.get(), _param_mpc_hold_dz.get());
6361
_positions_expo(1) = math::expo_deadzone(_positions(1), _param_mpc_xy_man_expo.get(), _param_mpc_hold_dz.get());
64-
_positions_expo(2) = math::expo_deadzone(_positions(2), _param_mpc_z_man_expo.get(), _param_mpc_hold_dz.get());
65-
_positions_expo(3) = math::expo_deadzone(_positions(3), _param_mpc_yaw_expo.get(), _param_mpc_hold_dz.get());
62+
_positions_expo(2) = math::expo_deadzone(_positions(2), _param_mpc_z_man_expo.get(), _param_mpc_hold_dz.get());
63+
_positions_expo(3) = math::expo_deadzone(_positions(3), _param_mpc_yaw_expo.get(), _param_mpc_hold_dz.get());
6664

6765
// valid stick inputs are required
6866
const bool valid_sticks = PX4_ISFINITE(_positions(0))
@@ -71,9 +69,6 @@ bool Sticks::checkAndSetStickInputs(hrt_abstime now)
7169
&& PX4_ISFINITE(_positions(3));
7270

7371
_input_available = valid_sticks;
74-
75-
} else {
76-
_input_available = false;
7772
}
7873

7974
if (!_input_available) {
@@ -85,31 +80,6 @@ bool Sticks::checkAndSetStickInputs(hrt_abstime now)
8580
return _input_available;
8681
}
8782

88-
void Sticks::setGearAccordingToSwitch(landing_gear_s &gear)
89-
{
90-
// Only switch the landing gear up if the user switched from gear down to gear up.
91-
// If the user had the switch in the gear up position and took off ignore it
92-
// until he toggles the switch to avoid retracting the gear immediately on takeoff.
93-
if (!isAvailable()) {
94-
gear.landing_gear = landing_gear_s::GEAR_KEEP;
95-
96-
} else {
97-
const int8_t gear_switch = _sub_manual_control_setpoint.get().gear_switch;
98-
99-
if (_gear_switch_old != gear_switch) {
100-
if (gear_switch == manual_control_setpoint_s::SWITCH_POS_OFF) {
101-
gear.landing_gear = landing_gear_s::GEAR_DOWN;
102-
}
103-
104-
if (gear_switch == manual_control_setpoint_s::SWITCH_POS_ON) {
105-
gear.landing_gear = landing_gear_s::GEAR_UP;
106-
}
107-
}
108-
109-
_gear_switch_old = gear_switch;
110-
}
111-
}
112-
11383
void Sticks::limitStickUnitLengthXY(Vector2f &v)
11484
{
11585
const float vl = v.length();

0 commit comments

Comments
 (0)