Skip to content

Commit

Permalink
mavlink_interface: set protocol ver to 2.0; only send ODOMETRY in tha…
Browse files Browse the repository at this point in the history
…t case
  • Loading branch information
TSC21 authored and LorenzMeier committed May 11, 2018
1 parent 256e00e commit cd91ef4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion include/gazebo_mavlink_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ class GazeboMavlinkInterface : public ModelPlugin {
GazeboMavlinkInterface() : ModelPlugin(),
received_first_referenc_(false),
namespace_(kDefaultNamespace),
protocol_version_(2.0),
motor_velocity_reference_pub_topic_(kDefaultMotorVelocityReferencePubTopic),
use_propeller_pid_(false),
use_elevator_pid_(false),
use_left_elevon_pid_(false),
use_right_elevon_pid_(false),
vehicle_is_tailsitter_(false),
send_odometry_(false),
send_odometry_(true),
imu_sub_topic_(kDefaultImuTopic),
opticalFlow_sub_topic_(kDefaultOpticalFlowTopic),
lidar_sub_topic_(kDefaultLidarTopic),
Expand Down Expand Up @@ -178,6 +179,8 @@ class GazeboMavlinkInterface : public ModelPlugin {
bool received_first_referenc_;
Eigen::VectorXd input_reference_;

float protocol_version_;

std::string namespace_;
std::string motor_velocity_reference_pub_topic_;
std::string mavlink_control_sub_topic_;
Expand Down
21 changes: 19 additions & 2 deletions src/gazebo_mavlink_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void GazeboMavlinkInterface::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf
gzerr << "[gazebo_mavlink_interface] Please specify a robotNamespace.\n";
}

if (_sdf->HasElement("protocol_version")) {
protocol_version_ = _sdf->GetElement("protocol_version")->Get<float>();
}

node_handle_ = transport::NodePtr(new transport::Node());
node_handle_->Init(namespace_);

Expand Down Expand Up @@ -335,7 +339,19 @@ void GazeboMavlinkInterface::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf
fds[0].events = POLLIN;

mavlink_status_t* chan_state = mavlink_get_channel_status(MAVLINK_COMM_0);
chan_state->flags |= MAVLINK_STATUS_FLAG_OUT_MAVLINK1;

// set the Mavlink protocol version to use on the link
if (protocol_version_ == 2.0) {
chan_state->flags &= ~(MAVLINK_STATUS_FLAG_OUT_MAVLINK1);
gzmsg << "Using MAVLink protocol v2.0\n";
}
else if (protocol_version_ == 1.0) {
chan_state->flags |= MAVLINK_STATUS_FLAG_OUT_MAVLINK1;
gzmsg << "Using MAVLink protocol v1.0\n";
}
else {
gzerr << "Unkown protocol version! Using v" << protocol_version_ << "by default \n";
}
}

// This gets called by the world update start event.
Expand Down Expand Up @@ -779,7 +795,8 @@ void GazeboMavlinkInterface::VisionCallback(OdomPtr& odom_message) {
odom_message->angular_velocity().y(),
odom_message->angular_velocity().z()));

if (send_odometry_){
// Only sends ODOMETRY msgs if send_odometry is set and the protocol version is 2.0
if (send_odometry_ && protocol_version_ == 2.0) {
// send ODOMETRY Mavlink msg
mavlink_odometry_t odom;

Expand Down

0 comments on commit cd91ef4

Please sign in to comment.