37 #include <gazebo/common/Events.hh> 38 #include <gazebo/physics/physics.hh> 43 #include <geometry_msgs/Twist.h> 44 #include <nav_msgs/Odometry.h> 45 #include <boost/bind.hpp> 47 #include <gazebo/gazebo_config.h> 70 #if (GAZEBO_MAJOR_VERSION >= 8) 84 world = _model->GetWorld();
94 if (_sdf->HasElement(
"robotNamespace"))
95 namespace_ = _sdf->GetElement(
"robotNamespace")->GetValue()->GetAsString();
97 if (_sdf->HasElement(
"topicName"))
98 topic_ = _sdf->GetElement(
"topicName")->GetValue()->GetAsString();
100 if (_sdf->HasElement(
"bodyName"))
102 link_name_ = _sdf->GetElement(
"bodyName")->GetValue()->GetAsString();
105 link = _model->GetLink();
112 ROS_FATAL(
"DiffDrivePlugin6W plugin error: bodyName: %s does not exist\n",
link_name_.c_str());
116 if (_sdf->HasElement(
"frontLeftJoint"))
joints[
FRONT_LEFT] = _model->GetJoint(_sdf->GetElement(
"frontLeftJoint")->GetValue()->GetAsString());
117 if (_sdf->HasElement(
"frontRightJoint"))
joints[
FRONT_RIGHT] = _model->GetJoint(_sdf->GetElement(
"frontRightJoint")->GetValue()->GetAsString());
118 if (_sdf->HasElement(
"midLeftJoint"))
joints[
MID_LEFT] = _model->GetJoint(_sdf->GetElement(
"midLeftJoint")->GetValue()->GetAsString());
119 if (_sdf->HasElement(
"midRightJoint"))
joints[
MID_RIGHT] = _model->GetJoint(_sdf->GetElement(
"midRightJoint")->GetValue()->GetAsString());
120 if (_sdf->HasElement(
"rearLeftJoint"))
joints[
REAR_LEFT] = _model->GetJoint(_sdf->GetElement(
"rearLeftJoint")->GetValue()->GetAsString());
121 if (_sdf->HasElement(
"rearRightJoint"))
joints[
REAR_RIGHT] = _model->GetJoint(_sdf->GetElement(
"rearRightJoint")->GetValue()->GetAsString());
130 if (_sdf->HasElement(
"wheelSeparation"))
131 _sdf->GetElement(
"wheelSeparation")->GetValue()->Get(
wheelSep);
133 if (_sdf->HasElement(
"wheelDiameter"))
134 _sdf->GetElement(
"wheelDiameter")->GetValue()->Get(
wheelDiam);
136 if (_sdf->HasElement(
"torque"))
137 _sdf->GetElement(
"torque")->GetValue()->Get(
torque);
142 ROS_FATAL_STREAM(
"A ROS node for Gazebo has not been initialized, unable to load plugin. " 143 <<
"Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
154 ros::SubscribeOptions::create<geometry_msgs::Twist>(
topic_, 1,
176 for (
size_t i = 0; i < 2; ++i){
180 #if (GAZEBO_MAJOR_VERSION >= 8) 206 common::Time stepTime;
211 #if (GAZEBO_MAJOR_VERSION >= 8) 232 odomVel[0] = dr / stepTime.Double();
234 odomVel[2] = da / stepTime.Double();
246 #if (GAZEBO_MAJOR_VERSION > 4) 298 x_ = cmd_msg->linear.x;
299 rot_ = cmd_msg->angular.z;
309 static const double timeout = 0.01;
322 #if (GAZEBO_MAJOR_VERSION >= 8) 329 #if (GAZEBO_MAJOR_VERSION >= 8) 330 ignition::math::Pose3d pose =
link->WorldPose();
331 ignition::math::Vector3d velocity =
link->WorldLinearVel();
332 ignition::math::Vector3d angular_velocity =
link->WorldAngularVel();
334 tf::Quaternion qt(pose.Rot().X(), pose.Rot().Y(), pose.Rot().Z(), pose.Rot().W());
335 tf::Vector3 vt(pose.Pos().X(), pose.Pos().Y(), pose.Pos().Z());
337 math::Pose pose =
link->GetWorldPose();
338 math::Vector3 velocity =
link->GetWorldLinearVel();
339 math::Vector3 angular_velocity =
link->GetWorldAngularVel();
341 tf::Quaternion qt(pose.rot.x, pose.rot.y, pose.rot.z, pose.rot.w);
342 tf::Vector3 vt(pose.pos.x, pose.pos.y, pose.pos.z);
352 #if (GAZEBO_MAJOR_VERSION >= 8) 353 odom_.pose.pose.position.x = pose.Pos().X();
354 odom_.pose.pose.position.y = pose.Pos().Y();
356 odom_.pose.pose.orientation.x = pose.Rot().X();
357 odom_.pose.pose.orientation.y = pose.Rot().Y();
358 odom_.pose.pose.orientation.z = pose.Rot().Z();
359 odom_.pose.pose.orientation.w = pose.Rot().W();
361 odom_.twist.twist.linear.x = velocity.X();
362 odom_.twist.twist.linear.y = velocity.Y();
363 odom_.twist.twist.angular.z = angular_velocity.Z();
365 odom_.pose.pose.position.x = pose.pos.x;
366 odom_.pose.pose.position.y = pose.pos.y;
368 odom_.pose.pose.orientation.x = pose.rot.x;
369 odom_.pose.pose.orientation.y = pose.rot.y;
370 odom_.pose.pose.orientation.z = pose.rot.z;
371 odom_.pose.pose.orientation.w = pose.rot.w;
373 odom_.twist.twist.linear.x = velocity.x;
374 odom_.twist.twist.linear.y = velocity.y;
375 odom_.twist.twist.angular.z = angular_velocity.z;
379 odom_.child_frame_id =
"base_footprint";
380 odom_.header.stamp = current_time_;
void cmdVelCallback(const geometry_msgs::Twist::ConstPtr &cmd_msg)
void publish(const boost::shared_ptr< M > &message) const
std::string getPrefixParam(ros::NodeHandle &nh)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL bool isInitialized()
virtual ~DiffDrivePlugin6W()
ros::NodeHandle * rosnode_
physics::JointPtr joints[6]
std::string resolve(const std::string &prefix, const std::string &frame_name)
#define ROS_FATAL_STREAM(args)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
boost::thread callback_queue_thread_
ros::CallbackQueue queue_
common::Time prevUpdateTime
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
tf::TransformBroadcaster * transform_broadcaster_
boost::shared_ptr< void > VoidPtr
event::ConnectionPtr updateConnection