Skip to content

Commit 42f3966

Browse files
committed
manual_control_setpoint: change x, y, z, r naming
In review it was requested to have a different name for manual_control_setpoint.z because of the adjusted range. It was agreed to switch to an array for stick inputs called xyzr.
1 parent 1ea11f6 commit 42f3966

File tree

15 files changed

+95
-106
lines changed

15 files changed

+95
-106
lines changed

msg/manual_control_setpoint.msg

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,17 @@ uint8 data_source # where this input is coming from
1212

1313
# Any of the channels may not be available and be set to NaN
1414
# to indicate that it does not contain valid data.
15-
# The variable names follow the definition of the
16-
# MANUAL_CONTROL mavlink message.
17-
# The default range is from -1 to 1 (mavlink message -1000 to 1000)
18-
# The range for the z variable is defined from 0 to 1. (The z field of
19-
# the MANUAL_CONTROL mavlink message is defined from -1000 to 1000)
20-
21-
float32 x # stick position in x direction -1..1
22-
# in general corresponds to forward/back motion or pitch of vehicle,
23-
# in general a positive value means forward or negative pitch and
24-
# a negative value means backward or positive pitch
25-
26-
float32 y # stick position in y direction -1..1
27-
# in general corresponds to right/left motion or roll of vehicle,
28-
# in general a positive value means right or positive roll and
29-
# a negative value means left or negative roll
30-
31-
float32 z # throttle stick position -1..1
32-
# in general corresponds to up/down motion or thrust of vehicle,
33-
# in general the value corresponds to the demanded throttle by the user,
34-
# if the input is used for setting the setpoint of a vertical position
35-
# controller any value > 0 means up and any value < 0 means down
36-
37-
float32 r # yaw stick/twist position, -1..1
38-
# in general corresponds to the righthand rotation around the vertical
39-
# (downwards) axis of the vehicle
15+
16+
# Stick positions [-1,1]
17+
# on a common RC mode 1/2/3/4 remote/joystick the stick deflection: -1 is down/left, 1 is up/right
18+
# Positive directions are generally used for:
19+
# x - forward, negative pitch, nose down
20+
# y - right, positive roll, right side down
21+
# z - up, positive thrust, -1 is 0% thrust +1 is 100% thrust
22+
# r - righthand rotation around vertical downwards axis (= clockwise yaw rotation when seen from above)
23+
# The definition is analogous to the MANUAL_CONTROL mavlink message's x, y, z, r fields.
24+
# Note: QGC sends z in range [0,1000] - [0,1]. The MAVLink input conversion [0,1] to [-1,1] is at the moment kept backwards compatible.
25+
float32[4] xyzr
4026

4127
float32 flaps # flap position
4228

@@ -47,3 +33,7 @@ float32 aux4 # default function: camera roll
4733
float32 aux5 # default function: payload drop
4834
float32 aux6
4935

36+
# DEPRECATED: float32 x
37+
# DEPRECATED: float32 y
38+
# DEPRECATED: float32 z
39+
# DEPRECATED: float32 r

src/examples/fixedwing_control/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ int fixedwing_control_thread_main(int argc, char *argv[])
386386
}
387387

388388
/* check if the throttle was ever more than 50% - go later only to failsafe if yes */
389-
if (PX4_ISFINITE(manual_control_setpoint.z) &&
390-
(manual_control_setpoint.z >= .2f) &&
391-
(manual_control_setpoint.z <= 1.f)) {
389+
if (PX4_ISFINITE(manual_control_setpoint.xyzr[2]) &&
390+
(manual_control_setpoint.xyzr[2] >= .2f) &&
391+
(manual_control_setpoint.xyzr[2] <= 1.f)) {
392392
}
393393

394394
/* get the system status and the flight mode we're in */

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ bool Sticks::checkAndSetStickInputs()
5151

5252
if (_manual_control_setpoint_sub.update(&manual_control_setpoint)) {
5353
// Linear scale
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; // NED z, thrust resacaled from [0,1] to [-1,1]
57-
_positions(3) = manual_control_setpoint.r; // yaw [-1,1]
54+
_positions = matrix::Vector<float, 4>(manual_control_setpoint.xyzr);
55+
_positions(2) = -_positions(2); // NED z direction is down not up
5856

5957
// Exponential scale
6058
_positions_expo(0) = math::expo_deadzone(_positions(0), _param_mpc_xy_man_expo.get(), _param_mpc_hold_dz.get());

src/modules/airship_att_control/airship_att_control_main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ AirshipAttitudeControl::publish_actuator_controls()
9191

9292
} else {
9393
_actuators.control[0] = 0.0f;
94-
_actuators.control[1] = _manual_control_setpoint.x;
95-
_actuators.control[2] = _manual_control_setpoint.r;
96-
_actuators.control[3] = (_manual_control_setpoint.z + 1.f) * .5f;
94+
_actuators.control[1] = _manual_control_setpoint.xyzr[0];
95+
_actuators.control[2] = _manual_control_setpoint.xyzr[3];
96+
_actuators.control[3] = (_manual_control_setpoint.xyzr[2] + 1.f) * .5f;
9797
}
9898

9999
// note: _actuators.timestamp_sample is set in AirshipAttitudeControl::Run()

src/modules/commander/Commander.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ Commander::handle_command(const vehicle_command_s &cmd)
705705
break;
706706
}
707707

708-
const bool throttle_above_low = (_manual_control_setpoint.z > -.8f);
709-
const bool throttle_above_center = (_manual_control_setpoint.z > .2f);
708+
const bool throttle_above_low = (_manual_control_setpoint.xyzr[2] > -.8f);
709+
const bool throttle_above_center = (_manual_control_setpoint.xyzr[2] > .2f);
710710

711711
if (cmd_arms && throttle_above_center &&
712712
(_status.nav_state == vehicle_status_s::NAVIGATION_STATE_POSCTL ||
@@ -2092,8 +2092,8 @@ Commander::run()
20922092

20932093
// transition to previous state if sticks are touched
20942094
if (!_status.rc_signal_lost &&
2095-
((fabsf(_manual_control_setpoint.x) > minimum_stick_deflection) ||
2096-
(fabsf(_manual_control_setpoint.y) > minimum_stick_deflection))) {
2095+
((fabsf(_manual_control_setpoint.xyzr[0]) > minimum_stick_deflection) ||
2096+
(fabsf(_manual_control_setpoint.xyzr[1]) > minimum_stick_deflection))) {
20972097
// revert to position control in any case
20982098
main_state_transition(_status, commander_state_s::MAIN_STATE_POSCTL, _status_flags, &_internal_state);
20992099
mavlink_log_info(&_mavlink_log_pub, "Pilot took over control using sticks");
@@ -2152,8 +2152,8 @@ Commander::run()
21522152
* and we are in MANUAL, Rattitude, or AUTO_READY mode or (ASSIST mode and landed)
21532153
* do it only for rotary wings in manual mode or fixed wing if landed.
21542154
* Disable stick-disarming if arming switch or button is mapped */
2155-
const bool stick_in_lower_left = _manual_control_setpoint.r < -STICK_ON_OFF_LIMIT
2156-
&& (_manual_control_setpoint.z < -.8f)
2155+
const bool stick_in_lower_left = _manual_control_setpoint.xyzr[3] < -STICK_ON_OFF_LIMIT
2156+
&& (_manual_control_setpoint.xyzr[2] < -.8f)
21572157
&& !arm_switch_or_button_mapped;
21582158
const bool arm_switch_to_disarm_transition = !_param_arm_switch_is_button.get() &&
21592159
(_last_manual_control_switches_arm_switch == manual_control_switches_s::SWITCH_POS_ON) &&
@@ -2190,7 +2190,8 @@ Commander::run()
21902190
* check if left stick is in lower right position or arm button is pushed or arm switch has transition from disarm to arm
21912191
* and we're in MANUAL mode.
21922192
* Disable stick-arming if arming switch or button is mapped */
2193-
const bool stick_in_lower_right = _manual_control_setpoint.r > STICK_ON_OFF_LIMIT && _manual_control_setpoint.z < -.8f
2193+
const bool stick_in_lower_right = _manual_control_setpoint.xyzr[3] > STICK_ON_OFF_LIMIT
2194+
&& _manual_control_setpoint.xyzr[2] < -.8f
21942195
&& !arm_switch_or_button_mapped;
21952196
/* allow a grace period for re-arming: preflight checks don't need to pass during that time,
21962197
* for example for accidental in-air disarming */
@@ -2200,7 +2201,7 @@ Commander::run()
22002201
const bool arm_switch_to_arm_transition = !_param_arm_switch_is_button.get() &&
22012202
(_last_manual_control_switches_arm_switch == manual_control_switches_s::SWITCH_POS_OFF) &&
22022203
(_manual_control_switches.arm_switch == manual_control_switches_s::SWITCH_POS_ON) &&
2203-
(_manual_control_setpoint.z < -.8f || in_rearming_grace_period);
2204+
(_manual_control_setpoint.xyzr[2] < -.8f || in_rearming_grace_period);
22042205

22052206
if (!in_armed_state &&
22062207
(_status.rc_input_mode != vehicle_status_s::RC_IN_MODE_OFF) &&

src/modules/commander/rc_calibration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ int do_trim_calibration(orb_advert_t *mavlink_log_pub)
8282
/* set parameters: the new trim values are the combination of active trim values
8383
and the values coming from the remote control of the user
8484
*/
85-
float p = manual_control_setpoint.y * roll_scale + roll_trim_active;
85+
float p = manual_control_setpoint.xyzr[1] * roll_scale + roll_trim_active;
8686
int p1r = param_set(param_find("TRIM_ROLL"), &p);
8787
/*
8888
we explicitly swap sign here because the trim is added to the actuator controls
8989
which are moving in an inverse sense to manual pitch inputs
9090
*/
91-
p = -manual_control_setpoint.x * pitch_scale + pitch_trim_active;
91+
p = -manual_control_setpoint.xyzr[0] * pitch_scale + pitch_trim_active;
9292
int p2r = param_set(param_find("TRIM_PITCH"), &p);
93-
p = manual_control_setpoint.r * yaw_scale + yaw_trim_active;
93+
p = manual_control_setpoint.xyzr[3] * yaw_scale + yaw_trim_active;
9494
int p3r = param_set(param_find("TRIM_YAW"), &p);
9595

9696
if (p1r != 0 || p2r != 0 || p3r != 0) {

src/modules/fw_att_control/FixedwingAttitudeControl.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,25 @@ FixedwingAttitudeControl::vehicle_manual_poll()
145145

146146
// Check if we are in rattitude mode and the pilot is above the threshold on pitch
147147
if (_vcontrol_mode.flag_control_rattitude_enabled) {
148-
if (fabsf(_manual_control_setpoint.y) > _param_fw_ratt_th.get()
149-
|| fabsf(_manual_control_setpoint.x) > _param_fw_ratt_th.get()) {
148+
if (fabsf(_manual_control_setpoint.xyzr[1]) > _param_fw_ratt_th.get()
149+
|| fabsf(_manual_control_setpoint.xyzr[0]) > _param_fw_ratt_th.get()) {
150150
_vcontrol_mode.flag_control_attitude_enabled = false;
151151
}
152152
}
153153

154154
if (!_vcontrol_mode.flag_control_climb_rate_enabled &&
155155
!_vcontrol_mode.flag_control_offboard_enabled) {
156-
const float throttle = (_manual_control_setpoint.z + 1.f) * .5f;
156+
const float throttle = (_manual_control_setpoint.xyzr[2] + 1.f) * .5f;
157157

158158
if (_vcontrol_mode.flag_control_attitude_enabled) {
159159
// STABILIZED mode generate the attitude setpoint from manual user inputs
160160

161-
_att_sp.roll_body = _manual_control_setpoint.y * radians(_param_fw_man_r_max.get()) + radians(_param_fw_rsp_off.get());
161+
_att_sp.roll_body = _manual_control_setpoint.xyzr[1] * radians(_param_fw_man_r_max.get())
162+
+ radians(_param_fw_rsp_off.get());
162163
_att_sp.roll_body = constrain(_att_sp.roll_body,
163164
-radians(_param_fw_man_r_max.get()), radians(_param_fw_man_r_max.get()));
164165

165-
_att_sp.pitch_body = -_manual_control_setpoint.x * radians(_param_fw_man_p_max.get())
166+
_att_sp.pitch_body = -_manual_control_setpoint.xyzr[0] * radians(_param_fw_man_p_max.get())
166167
+ radians(_param_fw_psp_off.get());
167168
_att_sp.pitch_body = constrain(_att_sp.pitch_body,
168169
-radians(_param_fw_man_p_max.get()), radians(_param_fw_man_p_max.get()));
@@ -182,21 +183,21 @@ FixedwingAttitudeControl::vehicle_manual_poll()
182183

183184
// RATE mode we need to generate the rate setpoint from manual user inputs
184185
_rates_sp.timestamp = hrt_absolute_time();
185-
_rates_sp.roll = _manual_control_setpoint.y * radians(_param_fw_acro_x_max.get());
186-
_rates_sp.pitch = -_manual_control_setpoint.x * radians(_param_fw_acro_y_max.get());
187-
_rates_sp.yaw = _manual_control_setpoint.r * radians(_param_fw_acro_z_max.get());
186+
_rates_sp.roll = _manual_control_setpoint.xyzr[1] * radians(_param_fw_acro_x_max.get());
187+
_rates_sp.pitch = -_manual_control_setpoint.xyzr[0] * radians(_param_fw_acro_y_max.get());
188+
_rates_sp.yaw = _manual_control_setpoint.xyzr[3] * radians(_param_fw_acro_z_max.get());
188189
_rates_sp.thrust_body[0] = throttle;
189190

190191
_rate_sp_pub.publish(_rates_sp);
191192

192193
} else {
193194
/* manual/direct control */
194195
_actuators.control[actuator_controls_s::INDEX_ROLL] =
195-
_manual_control_setpoint.y * _param_fw_man_r_sc.get() + _param_trim_roll.get();
196+
_manual_control_setpoint.xyzr[1] * _param_fw_man_r_sc.get() + _param_trim_roll.get();
196197
_actuators.control[actuator_controls_s::INDEX_PITCH] =
197-
-_manual_control_setpoint.x * _param_fw_man_p_sc.get() + _param_trim_pitch.get();
198+
-_manual_control_setpoint.xyzr[0] * _param_fw_man_p_sc.get() + _param_trim_pitch.get();
198199
_actuators.control[actuator_controls_s::INDEX_YAW] =
199-
_manual_control_setpoint.r * _param_fw_man_y_sc.get() + _param_trim_yaw.get();
200+
_manual_control_setpoint.xyzr[3] * _param_fw_man_y_sc.get() + _param_trim_yaw.get();
200201
_actuators.control[actuator_controls_s::INDEX_THROTTLE] = throttle;
201202
}
202203
}
@@ -552,7 +553,7 @@ void FixedwingAttitudeControl::Run()
552553

553554
/* add in manual rudder control in manual modes */
554555
if (_vcontrol_mode.flag_control_manual_enabled) {
555-
_actuators.control[actuator_controls_s::INDEX_YAW] += _manual_control_setpoint.r;
556+
_actuators.control[actuator_controls_s::INDEX_YAW] += _manual_control_setpoint.xyzr[3];
556557
}
557558

558559
if (!PX4_ISFINITE(yaw_u)) {

src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ FixedwingPositionControl::manual_control_setpoint_poll()
207207
{
208208
_manual_control_setpoint_sub.update(&_manual_control_setpoint);
209209

210-
_manual_control_setpoint_altitude = _manual_control_setpoint.x;
211-
_manual_control_setpoint_airspeed = _manual_control_setpoint.z;
210+
_manual_control_setpoint_altitude = _manual_control_setpoint.xyzr[0];
211+
_manual_control_setpoint_airspeed = _manual_control_setpoint.xyzr[2];
212212

213213
if (_param_fw_posctl_inv_st.get()) {
214214
/* Alternate stick allocation (similar concept as for multirotor systems:
215215
* demanding up/down with the throttle stick, and move faster/break with the pitch one.
216216
*/
217-
_manual_control_setpoint_altitude = -_manual_control_setpoint.z;
218-
_manual_control_setpoint_airspeed = _manual_control_setpoint.x;
217+
_manual_control_setpoint_altitude = -_manual_control_setpoint.xyzr[2];
218+
_manual_control_setpoint_airspeed = _manual_control_setpoint.xyzr[0];
219219
}
220220
}
221221

@@ -889,7 +889,7 @@ FixedwingPositionControl::control_position(const hrt_abstime &now, const Vector2
889889

890890
/* reset setpoints from other modes (auto) otherwise we won't
891891
* level out without new manual input */
892-
_att_sp.roll_body = _manual_control_setpoint.y * radians(_param_fw_man_r_max.get());
892+
_att_sp.roll_body = _manual_control_setpoint.xyzr[1] * radians(_param_fw_man_r_max.get());
893893
_att_sp.yaw_body = 0;
894894
}
895895

@@ -925,8 +925,8 @@ FixedwingPositionControl::control_position(const hrt_abstime &now, const Vector2
925925
tecs_status_s::TECS_MODE_NORMAL);
926926

927927
/* heading control */
928-
if (fabsf(_manual_control_setpoint.y) < HDG_HOLD_MAN_INPUT_THRESH &&
929-
fabsf(_manual_control_setpoint.r) < HDG_HOLD_MAN_INPUT_THRESH) {
928+
if (fabsf(_manual_control_setpoint.xyzr[1]) < HDG_HOLD_MAN_INPUT_THRESH &&
929+
fabsf(_manual_control_setpoint.xyzr[3]) < HDG_HOLD_MAN_INPUT_THRESH) {
930930

931931
/* heading / roll is zero, lock onto current heading */
932932
if (fabsf(_vehicle_rates_sub.get().xyz[2]) < HDG_HOLD_YAWRATE_THRESH && !_yaw_lock_engaged) {
@@ -977,12 +977,12 @@ FixedwingPositionControl::control_position(const hrt_abstime &now, const Vector2
977977
}
978978
}
979979

980-
if (!_yaw_lock_engaged || fabsf(_manual_control_setpoint.y) >= HDG_HOLD_MAN_INPUT_THRESH ||
981-
fabsf(_manual_control_setpoint.r) >= HDG_HOLD_MAN_INPUT_THRESH) {
980+
if (!_yaw_lock_engaged || fabsf(_manual_control_setpoint.xyzr[1]) >= HDG_HOLD_MAN_INPUT_THRESH ||
981+
fabsf(_manual_control_setpoint.xyzr[3]) >= HDG_HOLD_MAN_INPUT_THRESH) {
982982

983983
_hdg_hold_enabled = false;
984984
_yaw_lock_engaged = false;
985-
_att_sp.roll_body = _manual_control_setpoint.y * radians(_param_fw_man_r_max.get());
985+
_att_sp.roll_body = _manual_control_setpoint.xyzr[1] * radians(_param_fw_man_r_max.get());
986986
_att_sp.yaw_body = 0;
987987
}
988988

@@ -1026,7 +1026,7 @@ FixedwingPositionControl::control_position(const hrt_abstime &now, const Vector2
10261026
pitch_limit_min,
10271027
tecs_status_s::TECS_MODE_NORMAL);
10281028

1029-
_att_sp.roll_body = _manual_control_setpoint.y * radians(_param_fw_man_r_max.get());
1029+
_att_sp.roll_body = _manual_control_setpoint.xyzr[1] * radians(_param_fw_man_r_max.get());
10301030
_att_sp.yaw_body = 0;
10311031

10321032
} else {

src/modules/mavlink/mavlink_messages.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,10 +3621,10 @@ class MavlinkStreamManualControl : public MavlinkStream
36213621
mavlink_manual_control_t msg{};
36223622

36233623
msg.target = mavlink_system.sysid;
3624-
msg.x = manual_control_setpoint.x * 1000;
3625-
msg.y = manual_control_setpoint.y * 1000;
3626-
msg.z = manual_control_setpoint.z * 1000;
3627-
msg.r = manual_control_setpoint.r * 1000;
3624+
msg.x = manual_control_setpoint.xyzr[0] * 1e3f;
3625+
msg.y = manual_control_setpoint.xyzr[1] * 1e3f;
3626+
msg.z = manual_control_setpoint.xyzr[2] * 1e3f;
3627+
msg.r = manual_control_setpoint.xyzr[3] * 1e3f;
36283628

36293629
manual_control_switches_s manual_control_switches{};
36303630

src/modules/mavlink/mavlink_receiver.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,14 +2060,12 @@ MavlinkReceiver::handle_message_manual_control(mavlink_message_t *msg)
20602060

20612061
} else {
20622062
manual_control_setpoint_s manual_control_setpoint{};
2063-
20642063
manual_control_setpoint.timestamp = hrt_absolute_time();
2065-
manual_control_setpoint.x = man.x / 1e3f;
2066-
manual_control_setpoint.y = man.y / 1e3f;
2067-
manual_control_setpoint.z = man.z / 1e3f;
2068-
manual_control_setpoint.r = man.r / 1e3f;
2064+
manual_control_setpoint.xyzr[0] = man.x / 1e3f;
2065+
manual_control_setpoint.xyzr[1] = man.y / 1e3f;
2066+
manual_control_setpoint.xyzr[2] = (man.z / 1e3f * 2.f) - 1.f; // backwards compatibility QGC
2067+
manual_control_setpoint.xyzr[3] = man.r / 1e3f;
20692068
manual_control_setpoint.data_source = manual_control_setpoint_s::SOURCE_MAVLINK_0 + _mavlink->get_instance_id();
2070-
20712069
_manual_control_setpoint_pub.publish(manual_control_setpoint);
20722070
}
20732071
}

0 commit comments

Comments
 (0)