30 this->
node->shutdown();
36 this->
model = _parent;
38 GZ_ASSERT(this->
model != NULL,
"Invalid model pointer");
44 gzerr <<
"ROS was not initialized. Closing plugin..." << std::endl;
51 if (_sdf->HasElement(
"robotNamespace"))
56 gzmsg <<
"JointStatePublisher::robotNamespace=" 62 if (_sdf->HasElement(
"updateRate"))
63 this->
updateRate = _sdf->Get<
double>(
"updateRate");
67 gzmsg <<
"JointStatePublisher::Retrieving moving joints:" << std::endl;
69 double upperLimit, lowerLimit;
70 for (
auto &joint : this->
model->GetJoints())
72 #if GAZEBO_MAJOR_VERSION >= 8 73 lowerLimit = joint->LowerLimit(0);
74 upperLimit = joint->UpperLimit(0);
76 lowerLimit = joint->GetLowerLimit(0).Radian();
77 upperLimit = joint->GetUpperLimit(0).Radian();
79 if (lowerLimit == 0 && upperLimit == 0)
81 else if (joint->GetType() == gazebo::physics::Base::EntityType::FIXED_JOINT)
86 gzmsg <<
"\t- " << joint->GetName() << std::endl;
90 GZ_ASSERT(this->
updateRate > 0,
"Update rate must be positive");
97 this->
node->advertise<sensor_msgs::JointState>(
99 #if GAZEBO_MAJOR_VERSION >= 8 102 this->lastUpdate = this->
world->GetSimTime();
111 #if GAZEBO_MAJOR_VERSION >= 8 112 gazebo::common::Time simTime = this->
world->SimTime();
114 gazebo::common::Time simTime = this->
world->GetSimTime();
126 sensor_msgs::JointState jointState;
128 jointState.header.stamp = stamp;
130 jointState.name.resize(this->
model->GetJointCount());
131 jointState.position.resize(this->
model->GetJointCount());
132 jointState.velocity.resize(this->
model->GetJointCount());
133 jointState.effort.resize(this->
model->GetJointCount());
136 for (
auto &joint : this->
model->GetJoints())
140 jointState.name[i] = joint->GetName();
141 #if GAZEBO_MAJOR_VERSION >= 8 142 jointState.position[i] = joint->Position(0);
144 jointState.position[i] = joint->GetAngle(0).Radian();
146 jointState.velocity[i] = joint->GetVelocity(0);
147 jointState.effort[i] = joint->GetForce(0);
151 jointState.name[i] = joint->GetName();
152 jointState.position[i] = 0.0;
153 jointState.velocity[i] = 0.0;
154 jointState.effort[i] = 0.0;
167 if (_jointName.compare(joint) == 0)
std::vector< std::string > movingJoints
void OnUpdate(const gazebo::common::UpdateInfo &_info)
bool IsIgnoredJoint(std::string _jointName)
void publish(const boost::shared_ptr< M > &message) const
gazebo::event::ConnectionPtr updateConnection
gazebo::physics::WorldPtr world
ROSCPP_DECL bool isInitialized()
gazebo::common::Time lastUpdate
gazebo::physics::ModelPtr model
GZ_REGISTER_MODEL_PLUGIN(UmbilicalPlugin)
void PublishJointStates()
ros::Publisher jointStatePub
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf)
std::string robotNamespace
boost::shared_ptr< ros::NodeHandle > node