Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the Mavlink handler for the Actuator controls message #7477

Merged
merged 2 commits into from
Aug 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

@dagar dagar Aug 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once last nitpicky thing, can you change these into orb_publish_auto? It includes the nullptr check and initiate advertise in a single call.
https://github.com/PX4/Firmware/blob/master/src/modules/uORB/uORB.h#L177

EDIT: Nevermind, you can't do this because the actuator controls will go to a separate instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    int inst
    orb_publish_auto(ORB_ID(actuator_controls_0), &_actuator_controls_pubs[0], &actuator_controls, inst, ORB_PRIO_DEFAULT)

_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