Skip to content

Commit

Permalink
Mavlink SET_ACTUATOR_CONTROL_TARGET support group_mlx (#7477)
Browse files Browse the repository at this point in the history
 - Allow to use the 4 groups from Mavlink
 - Allow an Offboard control of the Gimball, Gripper or servoes.
 - Fixes issue #7440

Signed-off-by: Alexis Paques <alexis.paques@gmail.com>
  • Loading branch information
AlexisTM authored and dagar committed Aug 12, 2018
1 parent 56ea4fa commit 6b8ea8e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
50 changes: 44 additions & 6 deletions src/modules/mavlink/mavlink_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ MavlinkReceiver::MavlinkReceiver(Mavlink *parent) :
_flow_distance_sensor_pub(nullptr),
_distance_sensor_pub(nullptr),
_offboard_control_mode_pub(nullptr),
_actuator_controls_pub(nullptr),
_actuator_controls_pubs{nullptr, nullptr, nullptr, nullptr},
_att_sp_pub(nullptr),
_rates_sp_pub(nullptr),
_pos_sp_triplet_pub(nullptr),
Expand Down Expand Up @@ -1099,16 +1099,54 @@ MavlinkReceiver::handle_message_set_actuator_control_target(mavlink_message_t *m

actuator_controls.timestamp = hrt_absolute_time();

/* Set duty cycles for the servos in actuator_controls_0 */
/* Set duty cycles for the servos in the actuator_controls message */
for (size_t i = 0; i < 8; i++) {
actuator_controls.control[i] = set_actuator_control_target.controls[i];
}

if (_actuator_controls_pub == nullptr) {
_actuator_controls_pub = orb_advertise(ORB_ID(actuator_controls_0), &actuator_controls);
switch (set_actuator_control_target.group_mlx) {
case 0:
if (_actuator_controls_pubs[0] == nullptr) {
_actuator_controls_pubs[0] = orb_advertise(ORB_ID(actuator_controls_0), &actuator_controls);

} else {
orb_publish(ORB_ID(actuator_controls_0), _actuator_controls_pub, &actuator_controls);
} else {
orb_publish(ORB_ID(actuator_controls_0), _actuator_controls_pubs[0], &actuator_controls);
}

break;

case 1:
if (_actuator_controls_pubs[1] == nullptr) {
_actuator_controls_pubs[1] = orb_advertise(ORB_ID(actuator_controls_1), &actuator_controls);

} else {
orb_publish(ORB_ID(actuator_controls_1), _actuator_controls_pubs[1], &actuator_controls);
}

break;

case 2:
if (_actuator_controls_pubs[2] == nullptr) {
_actuator_controls_pubs[2] = orb_advertise(ORB_ID(actuator_controls_2), &actuator_controls);

} else {
orb_publish(ORB_ID(actuator_controls_2), _actuator_controls_pubs[2], &actuator_controls);
}

break;

case 3:
if (_actuator_controls_pubs[3] == nullptr) {
_actuator_controls_pubs[3] = orb_advertise(ORB_ID(actuator_controls_3), &actuator_controls);

} else {
orb_publish(ORB_ID(actuator_controls_3), _actuator_controls_pubs[3], &actuator_controls);
}

break;

default:
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class MavlinkReceiver
orb_advert_t _flow_distance_sensor_pub;
orb_advert_t _distance_sensor_pub;
orb_advert_t _offboard_control_mode_pub;
orb_advert_t _actuator_controls_pub;
orb_advert_t _actuator_controls_pubs[4];
orb_advert_t _att_sp_pub;
orb_advert_t _rates_sp_pub;
orb_advert_t _pos_sp_triplet_pub;
Expand Down

0 comments on commit 6b8ea8e

Please sign in to comment.