33 this->
offset.Pos() = ignition::math::Vector3d::Zero;
34 this->
offset.Rot() = ignition::math::Quaterniond(
35 ignition::math::Vector3d(0, 0, 0));
38 this->
refLinAcc = ignition::math::Vector3d::Zero;
39 this->
refAngAcc = ignition::math::Vector3d::Zero;
54 ignition::math::Vector3d vec;
55 GetSDFParam<ignition::math::Vector3d>(_sdf,
"position_offset",
56 vec, ignition::math::Vector3d::Zero);
58 GetSDFParam<ignition::math::Vector3d>(_sdf,
"orientation_offset", vec,
59 ignition::math::Vector3d::Zero);
60 this->
offset.Rot() = ignition::math::Quaterniond(vec);
62 GetSDFParam<bool>(_sdf,
"publish_ned_odom", this->
publishNEDOdom,
false);
64 if (this->publishNEDOdom)
80 #if GAZEBO_MAJOR_VERSION >= 8 102 #if GAZEBO_MAJOR_VERSION >= 8 103 common::Time curTime = this->
world->SimTime();
105 common::Time curTime = this->
world->GetSimTime();
113 ignition::math::Pose3d linkPose, refLinkPose;
114 ignition::math::Vector3d refLinVel, refAngVel;
115 ignition::math::Vector3d linkLinVel, linkAngVel;
119 #if GAZEBO_MAJOR_VERSION >= 8 120 linkLinVel = this->
link->WorldLinearVel();
121 linkAngVel = this->
link->WorldAngularVel();
123 linkPose = this->
link->WorldPose();
125 linkLinVel = this->
link->GetWorldLinearVel().Ign();
126 linkAngVel = this->
link->GetWorldAngularVel().Ign();
128 linkPose = this->
link->GetWorldPose().Ign();
137 #if GAZEBO_MAJOR_VERSION >= 8 153 refLinVel = ignition::math::Vector3d::Zero;
154 refAngVel = ignition::math::Vector3d::Zero;
159 linkLinVel -= refLinVel;
160 linkAngVel -= refAngVel;
163 linkLinVel += ignition::math::Vector3d(
169 linkAngVel += ignition::math::Vector3d(
188 ignition::math::Pose3d _pose, ignition::math::Vector3d _linVel,
189 ignition::math::Vector3d _angVel)
193 nav_msgs::Odometry odomMsg;
196 odomMsg.header.frame_id =
"world";
197 odomMsg.header.stamp.sec = _time.sec;
198 odomMsg.header.stamp.nsec = _time.nsec;
199 odomMsg.child_frame_id = this->
link->GetName();
205 odomMsg.pose.pose.position.x = _pose.Pos().X();
206 odomMsg.pose.pose.position.y = _pose.Pos().Y();
207 odomMsg.pose.pose.position.z = _pose.Pos().Z();
209 odomMsg.pose.pose.orientation.x = _pose.Rot().X();
210 odomMsg.pose.pose.orientation.y = _pose.Rot().Y();
211 odomMsg.pose.pose.orientation.z = _pose.Rot().Z();
212 odomMsg.pose.pose.orientation.w = _pose.Rot().W();
214 odomMsg.twist.twist.linear.x = _linVel.X();
215 odomMsg.twist.twist.linear.y = _linVel.Y();
216 odomMsg.twist.twist.linear.z = _linVel.Z();
218 odomMsg.twist.twist.angular.x = _angVel.X();
219 odomMsg.twist.twist.angular.y = _angVel.Y();
220 odomMsg.twist.twist.angular.z = _angVel.Z();
224 odomMsg.pose.covariance[0] = gn2;
225 odomMsg.pose.covariance[7] = gn2;
226 odomMsg.pose.covariance[14] = gn2;
227 odomMsg.pose.covariance[21] = gn2;
228 odomMsg.pose.covariance[28] = gn2;
229 odomMsg.pose.covariance[35] = gn2;
231 odomMsg.twist.covariance[0] = gn2;
232 odomMsg.twist.covariance[7] = gn2;
233 odomMsg.twist.covariance[14] = gn2;
234 odomMsg.twist.covariance[21] = gn2;
235 odomMsg.twist.covariance[28] = gn2;
236 odomMsg.twist.covariance[35] = gn2;
242 ignition::math::Pose3d _pose, ignition::math::Vector3d _linVel,
243 ignition::math::Vector3d _angVel)
253 nav_msgs::Odometry odomMsg;
257 odomMsg.header.stamp.sec = _time.sec;
258 odomMsg.header.stamp.nsec = _time.nsec;
262 _pose.Pos() = this->
referenceFrame.Rot().RotateVectorReverse(_pose.Pos());
264 ignition::math::Quaterniond q = this->
nedTransform.Rot();
276 odomMsg.pose.pose.position.x = _pose.Pos().X();
277 odomMsg.pose.pose.position.y = _pose.Pos().Y();
278 odomMsg.pose.pose.position.z = _pose.Pos().Z();
280 odomMsg.pose.pose.orientation.x = _pose.Rot().X();
281 odomMsg.pose.pose.orientation.y = _pose.Rot().Y();
282 odomMsg.pose.pose.orientation.z = _pose.Rot().Z();
283 odomMsg.pose.pose.orientation.w = _pose.Rot().W();
285 odomMsg.twist.twist.linear.x = _linVel.X();
286 odomMsg.twist.twist.linear.y = _linVel.Y();
287 odomMsg.twist.twist.linear.z = _linVel.Z();
289 odomMsg.twist.twist.angular.x = _angVel.X();
290 odomMsg.twist.twist.angular.y = _angVel.Y();
291 odomMsg.twist.twist.angular.z = _angVel.Z();
294 odomMsg.pose.covariance[0] = gn2;
295 odomMsg.pose.covariance[7] = gn2;
296 odomMsg.pose.covariance[14] = gn2;
297 odomMsg.pose.covariance[21] = gn2;
298 odomMsg.pose.covariance[28] = gn2;
299 odomMsg.pose.covariance[35] = gn2;
301 odomMsg.twist.covariance[0] = gn2;
302 odomMsg.twist.covariance[7] = gn2;
303 odomMsg.twist.covariance[14] = gn2;
304 odomMsg.twist.covariance[21] = gn2;
305 odomMsg.twist.covariance[28] = gn2;
306 odomMsg.twist.covariance[35] = gn2;
319 geometry_msgs::TransformStamped childTransform;
321 std::string sourceFrame = this->
link->GetName();
329 gzmsg <<
"Transform between " << targetFrame <<
" and " << sourceFrame
331 gzmsg << ex.what() << std::endl;
336 childTransform.transform.translation.x,
337 childTransform.transform.translation.y,
338 childTransform.transform.translation.z);
340 childTransform.transform.rotation.w,
341 childTransform.transform.rotation.x,
342 childTransform.transform.rotation.y,
343 childTransform.transform.rotation.z);
ignition::math::Vector3d lastRefAngVel
ignition::math::Vector3d lastRefLinVel
physics::LinkPtr referenceLink
Reference link.
ignition::math::Pose3d nedTransform
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
bool EnableMeasurement(const common::UpdateInfo &_info) const
Enables generation of simulated measurement if the timeout since the last update has been reached...
ignition::math::Pose3d referenceFrame
Pose of the reference frame wrt world frame.
physics::WorldPtr world
Pointer to the world.
common::Time lastMeasurementTime
(Simulation) time when the last sensor measurement was generated.
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
ignition::math::Pose3d offset
Pose offset.
double noiseAmp
Noise amplitude.
~PoseGTROSPlugin()
Class destructor.
virtual bool OnUpdate(const common::UpdateInfo &_info)
Update sensor measurement.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load plugin and its configuration from sdf,.
void UpdateReferenceFramePose()
Updates the pose of the reference frame wrt the world frame.
double noiseSigma
Noise standard deviation.
std::string referenceFrameID
Frame ID of the reference frame.
void PublishOdomMessage(common::Time _time, ignition::math::Pose3d _pose, ignition::math::Vector3d _linVel, ignition::math::Vector3d _angVel)
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.
ignition::math::Vector3d refLinAcc
boost::shared_ptr< tf2_ros::TransformListener > tfListener
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the plugin.
boost::shared_ptr< ros::NodeHandle > rosNode
ROS node handle for communication with ROS.
PoseGTROSPlugin()
Class constructor.
void PublishNEDOdomMessage(common::Time _time, ignition::math::Pose3d _pose, ignition::math::Vector3d _linVel, ignition::math::Vector3d _angVel)
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
ignition::math::Vector3d refAngAcc
ros::Publisher nedOdomPub
void UpdateNEDTransform()