0
$\begingroup$

Gazebo Answers logo

Hi, I am using ros_enabled_model plugin with ros groovy . With the help of ros I am publishing cmd_vel geometry_msgs/Twist. I am able to publish the cmd_vel but on gazebo side subscriber is not working . Can anybody plz explain why it is not subscribing. Here is my code

public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)                
{    
 node=new ros::NodeHandle("~");
 ros::SubscribeOptions so=ros::SubscribeOptions::create<geometry_msgs::Twist>("/cmd_vel", 1,boost::bind(&ModelPush::ROSCallback_Vel, this, _1),ros::VoidPtr(),node->getCallbackQueue());
              
 cmd_vel_sub=node->subscribe(so);

}



void ROSCallback_Vel(const geometry_msgs::Twist::ConstPtr &msg)
{
         
 ROS_INFO("I heard");
          
 ROS_INFO("I received odom: [%lf,%lf,%lf,%lf,%lf, %lf]",msg->linear.x,msg->linear.y,msg->linear.z,msg->angular.x,msg->angular.y,msg->angular.z);
    
 double velocity=msg->linear.x;
 
 double angularVelocity=msg->angular.z;
}
 

Originally posted by anonymous on Gazebo Answers with karma: 11 on 2014-12-11

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

Hi,

you might need to call

ros::spinOnce();

in the update loop. Or use and asynchronous spinner. Here are some spinning tutorials.

Cheers, Andrei


Originally posted by AndreiHaidu with karma: 2108 on 2014-12-11

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by anonymous on 2014-12-12:
Ya its working now. Thanks!.

Comment by JuliusS on 2016-07-08:
When you say update loop, you mean the 'on update' function that is attached to ConnectWorldUpdateBegin?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.