36 std::string beamLinkName;
37 GetSDFParam<std::string>(_sdf,
"beam_link_name_0", beamLinkName,
"");
38 GZ_ASSERT(!beamLinkName.empty(),
"Beam 0 link name empty");
41 GetSDFParam<std::string>(_sdf,
"beam_link_name_1", beamLinkName,
"");
42 GZ_ASSERT(!beamLinkName.empty(),
"Beam 1 link name empty");
45 GetSDFParam<std::string>(_sdf,
"beam_link_name_2", beamLinkName,
"");
46 GZ_ASSERT(!beamLinkName.empty(),
"Beam 2 link name empty");
49 GetSDFParam<std::string>(_sdf,
"beam_link_name_3", beamLinkName,
"");
50 GZ_ASSERT(!beamLinkName.empty(),
"Beam 3 link name empty");
54 std::string beamTopic;
55 GetSDFParam<std::string>(_sdf,
"beam_topic_0", beamTopic,
"");
56 GZ_ASSERT(!beamTopic.empty(),
"Beam 0 topic name empty");
59 GetSDFParam<std::string>(_sdf,
"beam_topic_1", beamTopic,
"");
60 GZ_ASSERT(!beamTopic.empty(),
"Beam 1 topic name empty");
63 GetSDFParam<std::string>(_sdf,
"beam_topic_2", beamTopic,
"");
64 GZ_ASSERT(!beamTopic.empty(),
"Beam 2 topic name empty");
67 GetSDFParam<std::string>(_sdf,
"beam_topic_3", beamTopic,
"");
68 GZ_ASSERT(!beamTopic.empty(),
"Beam 3 topic name empty");
81 for (
int i = 0; i < 4; i++)
82 this->
dvlBeamMsgs.push_back(uuv_sensor_ros_plugins_msgs::DVLBeam());
86 sensor_msgs::Range, sensor_msgs::Range,
87 sensor_msgs::Range, sensor_msgs::Range>(
97 this->
rosNode->advertise<uuv_sensor_ros_plugins_msgs::DVL>(
101 this->
rosNode->advertise<geometry_msgs::TwistWithCovarianceStamped>(
102 this->sensorOutputTopic +
"_twist", 1);
121 for (
int i = 0; i < 9; i++)
122 this->
dvlROSMsg.velocity_covariance[i] = 0.0;
124 this->dvlROSMsg.velocity_covariance[0] = variance;
125 this->dvlROSMsg.velocity_covariance[4] = variance;
126 this->dvlROSMsg.velocity_covariance[8] = variance;
128 for (
int i = 0; i < 36; i++)
131 this->twistROSMsg.twist.covariance[0] = variance;
132 this->twistROSMsg.twist.covariance[7] = variance;
133 this->twistROSMsg.twist.covariance[14] = variance;
134 this->twistROSMsg.twist.covariance[21] = -1;
135 this->twistROSMsg.twist.covariance[28] = -1;
136 this->twistROSMsg.twist.covariance[35] = -1;
141 this->
gazeboNode->Advertise<sensor_msgs::msgs::Dvl>(
158 ignition::math::Vector3d bodyVel;
166 #if GAZEBO_MAJOR_VERSION >= 8 167 bodyVel = this->
link->RelativeLinearVel();
169 bodyVel = this->
link->GetRelativeLinearVel().Ign();
181 sensor_msgs::msgs::Dvl dvlGazeboMsg;
184 for (
int i = 0; i < 9; i++)
186 if (i == 0 || i == 4 || i == 8)
187 dvlGazeboMsg.add_linear_velocity_covariance(variance);
189 dvlGazeboMsg.add_linear_velocity_covariance(0.0);
193 gazebo::msgs::Vector3d* v =
new gazebo::msgs::Vector3d();
194 v->set_x(bodyVel.X());
195 v->set_y(bodyVel.Y());
196 v->set_z(bodyVel.Z());
197 dvlGazeboMsg.set_allocated_linear_velocity(v);
202 this->
dvlROSMsg.header.stamp.sec = _info.simTime.sec;
203 this->
dvlROSMsg.header.stamp.nsec = _info.simTime.nsec;
209 this->
dvlROSMsg.velocity.x = bodyVel.X();
210 this->
dvlROSMsg.velocity.y = bodyVel.Y();
211 this->
dvlROSMsg.velocity.z = bodyVel.Z();
216 this->
twistROSMsg.twist.twist.linear.x = bodyVel.X();
217 this->
twistROSMsg.twist.twist.linear.y = bodyVel.Y();
218 this->
twistROSMsg.twist.twist.linear.z = bodyVel.Z();
223 #if GAZEBO_MAJOR_VERSION >= 8 233 const sensor_msgs::RangeConstPtr& _range1,
234 const sensor_msgs::RangeConstPtr& _range2,
235 const sensor_msgs::RangeConstPtr& _range3)
237 if (_range0->range == _range0->min_range &&
238 _range1->range == _range1->min_range &&
239 _range2->range == _range2->min_range &&
240 _range3->range == _range3->min_range)
247 if (_range0->range == _range0->max_range &&
248 _range1->range == _range1->max_range &&
249 _range2->range == _range2->max_range &&
250 _range3->range == _range3->max_range)
258 0.25 * (_range0->range + _range1->range + _range2->range + _range3->range);
273 std::string targetFrame, sourceFrame;
280 targetFrame = this->
link->GetName();
296 ignition::math::Pose3d pose;
297 pose.Pos() = ignition::math::Vector3d(
301 pose.Rot() = ignition::math::Quaterniond(
307 this->
dvlBeamMsgs[i].pose = geometry_msgs::PoseStamped();
309 this->
dvlBeamMsgs[i].pose.header.frame_id = sourceFrame;
uuv_sensor_ros_plugins_msgs::DVL dvlROSMsg
ROS DVL message.
std::vector< ignition::math::Pose3d > beamPoses
List of poses of each beam wrt to the DVL frame.
std::vector< std::string > beamTopics
List of beam topics.
bool UpdateBeamTransforms()
Updates the poses of each beam wrt the DVL frame.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the plugin.
double GetGaussianNoise(double _amp)
Returns noise value for a function with zero mean from the default Gaussian noise model...
void publish(const boost::shared_ptr< M > &message) const
tf::StampedTransform tfLocalNEDFrame
Local NED TF frame.
#define ALTITUDE_OUT_OF_RANGE
bool EnableMeasurement(const common::UpdateInfo &_info) const
Enables generation of simulated measurement if the timeout since the last update has been reached...
physics::WorldPtr world
Pointer to the world.
ros::Publisher twistPub
ROS publisher for twist data.
common::Time lastMeasurementTime
(Simulation) time when the last sensor measurement was generated.
boost::shared_ptr< message_filters::Subscriber< sensor_msgs::Range > > beamSub3
boost::shared_ptr< message_filters::Subscriber< sensor_msgs::Range > > beamSub0
std::vector< uuv_sensor_ros_plugins_msgs::DVLBeam > dvlBeamMsgs
TFSIMD_FORCE_INLINE const tfScalar & getW() const
bool enableLocalNEDFrame
True if a the local NED frame needs to be broadcasted.
DVLROSPlugin()
Class constructor.
void SendLocalNEDTransform()
Returns true if the base_link_ned frame exists.
double noiseAmp
Noise amplitude.
boost::shared_ptr< message_filters::TimeSynchronizer< sensor_msgs::Range, sensor_msgs::Range, sensor_msgs::Range, sensor_msgs::Range > > syncBeamMessages
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load plugin and its configuration from sdf,.
void OnBeamCallback(const sensor_msgs::RangeConstPtr &_range0, const sensor_msgs::RangeConstPtr &_range1, const sensor_msgs::RangeConstPtr &_range2, const sensor_msgs::RangeConstPtr &_range3)
Get beam Range message update.
TFSIMD_FORCE_INLINE const tfScalar & x() const
boost::shared_ptr< message_filters::Subscriber< sensor_msgs::Range > > beamSub1
transport::NodePtr gazeboNode
Gazebo's node handle for transporting measurement messages.
TFSIMD_FORCE_INLINE const tfScalar & z() const
double noiseSigma
Noise standard deviation.
TFSIMD_FORCE_INLINE const tfScalar & y() const
transport::PublisherPtr gazeboSensorOutputPub
Gazebo's publisher for transporting measurement messages.
ignition::math::Pose3d localNEDFrame
Pose of the local NED frame wrt link frame.
bool beamTransformsInitialized
physics::LinkPtr link
Pointer to the link.
std::string sensorOutputTopic
Name of the sensor's output topic.
ros::Publisher rosSensorOutputPub
Gazebo's publisher for transporting measurement messages.
tf::TransformListener transformListener
boost::shared_ptr< ros::NodeHandle > rosNode
ROS node handle for communication with ROS.
geometry_msgs::TwistWithCovarianceStamped twistROSMsg
Store pose message since many attributes do not change (cov.).
virtual ~DVLROSPlugin()
Class destructor.
boost::shared_ptr< message_filters::Subscriber< sensor_msgs::Range > > beamSub2
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
std::string robotNamespace
Robot namespace.
virtual bool OnUpdate(const common::UpdateInfo &_info)
Update sensor measurement.
bool gazeboMsgEnabled
Flag set to true if the Gazebo sensors messages are supposed to be published as well (it can avoid un...
TODO: Modify computation of velocity using the beams.
void PublishState()
Publish the current state of the plugin.
std::vector< std::string > beamsLinkNames
List of beam links.
double altitude
Measured altitude in meters.