28 #include <boost/algorithm/string.hpp> 45 this->
world_ = _parent->GetWorld();
48 if ( !_sdf->HasElement (
"robotNamespace" ) ) {
49 ROS_INFO_NAMED(
"joint_state_publisher",
"GazeboRosJointStatePublisher Plugin missing <robotNamespace>, defaults to \"%s\"",
52 this->
robot_namespace_ = _sdf->GetElement (
"robotNamespace" )->Get<std::string>();
58 if ( !_sdf->HasElement (
"jointName" ) ) {
59 ROS_ASSERT (
"GazeboRosJointStatePublisher Plugin missing jointNames" );
61 sdf::ElementPtr element = _sdf->GetElement (
"jointName" ) ;
62 std::string joint_names = element->Get<std::string>();
63 boost::erase_all ( joint_names,
" " );
64 boost::split (
joint_names_, joint_names, boost::is_any_of (
"," ) );
68 if ( !_sdf->HasElement (
"updateRate" ) ) {
69 ROS_WARN_NAMED(
"joint_state_publisher",
"GazeboRosJointStatePublisher Plugin (ns = %s) missing <updateRate>, defaults to %f",
72 this->
update_rate_ = _sdf->GetElement (
"updateRate" )->Get<
double>();
81 #if GAZEBO_MAJOR_VERSION >= 8 87 for (
unsigned int i = 0; i<
joint_names_.size(); i++ ) {
89 ROS_INFO_NAMED(
"joint_state_publisher",
"GazeboRosJointStatePublisher is going to publish joint: %s",
joint_names_[i].c_str() );
97 #if GAZEBO_MAJOR_VERSION >= 8 100 last_update_time_ = this->
world_->GetSimTime();
110 #if GAZEBO_MAJOR_VERSION >= 8 111 common::Time current_time = this->
world_->SimTime();
113 common::Time current_time = this->
world_->GetSimTime();
117 ROS_WARN_NAMED(
"joint_state_publisher",
"Negative joint state update time difference detected.");
121 double seconds_since_last_update = ( current_time -
last_update_time_ ).Double();
141 for (
int i = 0; i <
joints_.size(); i++ ) {
142 physics::JointPtr joint =
joints_[i];
143 double velocity = joint->GetVelocity( 0 );
144 #if GAZEBO_MAJOR_VERSION >= 8 145 double position = joint->Position ( 0 );
147 double position = joint->GetAngle ( 0 ).Radian();
event::ConnectionPtr updateConnection
#define ROS_INFO_NAMED(name,...)
GazeboRosJointStatePublisher()
void publish(const boost::shared_ptr< M > &message) const
std::string getPrefixParam(ros::NodeHandle &nh)
#define ROS_WARN_NAMED(name,...)
physics::ModelPtr parent_
~GazeboRosJointStatePublisher()
std::vector< physics::JointPtr > joints_
std::string robot_namespace_
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
boost::shared_ptr< ros::NodeHandle > rosnode_
void publishJointStates()
sensor_msgs::JointState joint_state_
common::Time last_update_time_
ros::Publisher joint_state_publisher_
std::vector< std::string > joint_names_
void OnUpdate(const common::UpdateInfo &_info)