Skip to content

Commit

Permalink
update sonar message to match mavlink distance sensor definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mrivi authored and TSC21 committed Jun 27, 2019
1 parent e04ff96 commit 8ef5625
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion models/sonar/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</material>
</visual>
<sensor name="sonar" type="sonar">
<pose>0 0 0 0 1.57 0</pose>
<pose>0 0 0 0 1.57 0 </pose>
<sonar>
<min>0.02</min>
<max>5.0</max>
Expand Down
16 changes: 8 additions & 8 deletions src/gazebo_mavlink_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void GazeboMavlinkInterface::SonarCallback(SonarPtr& sonar_message) {
int roll = static_cast<int>(round(GetDegrees360(euler.X())));
int pitch = static_cast<int>(round(GetDegrees360(euler.Y())));
int yaw = static_cast<int>(round(GetDegrees360(euler.Z())));


if (roll == 0 && pitch == 0 && yaw == 0) {
sensor_msg.orientation = 25; // downward facing
Expand All @@ -919,21 +919,21 @@ void GazeboMavlinkInterface::SonarCallback(SonarPtr& sonar_message) {
sensor_msg.orientation = 0; // forward facing
} else if (roll == 0 && pitch == 90 && yaw == 90) {
sensor_msg.orientation = 6; // left facing
} else if (roll == 0 && pitch == 90 && yaw == -90) {
} else if (roll == 0 && pitch == 90 && yaw == 270) {
sensor_msg.orientation = 2; // right facing
} else {
sensor_msg.orientation = 100; // custom orientation
sensor_msg.q[0] = sonar_message->orientation().w();
sensor_msg.q[1] = sonar_message->orientation().x();
sensor_msg.q[2] = sonar_message->orientation().y();
sensor_msg.q[3] = sonar_message->orientation().z();
sensor_msg.quaternion[0] = sonar_message->orientation().w();
sensor_msg.quaternion[1] = sonar_message->orientation().x();
sensor_msg.quaternion[2] = sonar_message->orientation().y();
sensor_msg.quaternion[3] = sonar_message->orientation().z();
}

sensor_msg.type = 1;
sensor_msg.id = 1;
sensor_msg.covariance = 0;
sensor_msg.h_fov = sonar_message->h_fov();
sensor_msg.v_fov = sonar_message->v_fov();
sensor_msg.horizontal_fov = sonar_message->h_fov();
sensor_msg.vertical_fov = sonar_message->v_fov();

mavlink_message_t msg;
mavlink_msg_distance_sensor_encode_chan(1, 200, MAVLINK_COMM_0, &msg, &sensor_msg);
Expand Down
4 changes: 2 additions & 2 deletions src/gazebo_sonar_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void SonarPlugin::OnNewScans()
sonar_message.set_max_distance(parentSensor->RangeMax());
sonar_message.set_current_distance(parentSensor->Range());

sonar_message.set_h_fov(2.0f * atan(parentSensor->GetRadius() / parentSensor->RangeMax()));
sonar_message.set_v_fov(2.0f * atan(parentSensor->GetRadius() / parentSensor->RangeMax()));
sonar_message.set_h_fov(2.0f * atan(parentSensor->Radius() / parentSensor->RangeMax()));
sonar_message.set_v_fov(2.0f * atan(parentSensor->Radius() / parentSensor->RangeMax()));
ignition::math::Quaterniond pose_model_quaternion = parentSensor->Pose().Rot();
gazebo::msgs::Quaternion* orientation = new gazebo::msgs::Quaternion();
orientation->set_x(pose_model_quaternion.X());
Expand Down

0 comments on commit 8ef5625

Please sign in to comment.