Cannot get geometry_msgs::Twist from subscription to cmdVelReceived [closed]

asked 2013-01-21 08:31:05 -0600

MartinW gravatar image

updated 2014-04-20 14:09:42 -0600

ngrennan gravatar image

Hello all,

I am trying to write a program that subscribes to a geometry_msgs::Twist msg being published on a topic. Rxgraph says it is subscribed but I doesn't register in the console. The program is supposed to be a keyboard teleoperation where I send some commands through the keyboard on one node and another node picks up these commands and publishes them.

Here is a simple version of the code:

        printf("before subscription\n"); 
      cmd_vel_sub_ = node_.subscribe<geometry_msgs::Twist>("drrobot_cmd_vel", 1, boost::bind(&DrRobotPlayerNode::cmdVelReceived, this, _1));
        printf("after subscription\n");

 void cmdVelReceived(const geometry_msgs::Twist::ConstPtr& cmd_vel)
    {
        printf(" test \n");
      double g_vel = cmd_vel->linear.x;
      double t_vel = cmd_vel->angular.z;

      if (robotConfig1_.boardType == Hawk_H20_Motion)
      {
        double leftWheel = (2 * g_vel - t_vel* wheelDis_) / (2 * wheelRadius_);
        double rightWheel = (t_vel* wheelDis_ + 2 * g_vel) / (2 * wheelRadius_);

        int leftWheelCmd = motorDir_ * leftWheel * encoderOneCircleCnt_ / ( 2* 3.1415927);
        int rightWheelCmd = - motorDir_ * rightWheel * encoderOneCircleCnt_ / ( 2* 3.1415927);
        ROS_INFO("Received control command: [%d, %d]", leftWheelCmd,rightWheelCmd);


drrobotMotionDriver_->sendMotorCtrlAllCmd(Velocity,leftWheelCmd, rightWheelCmd,NOCONTROL,NOCONTROL, NOCONTROL,NOCONTROL);
      }}

This is inside the prewritten code's class, then the main function is:

int main(int argc, char** argv){
ros::init(argc, argv, "drrobot_jaguar4x4_player");

DrRobotPlayerNode drrobotPlayer;
ros::NodeHandle n;
// Start up the robot
if (drrobotPlayer.start() != 0)
{

    printf("error starting up the robot! \n");

    exit(-1);
}
/////////////////////////////////////////////////////////////////

ros::Rate loop_rate(10);      //10Hz

while (n.ok())
{
    printf("in the while loop \n");
  drrobotPlayer.doUpdate();
  ros::spinOnce();
 loop_rate.sleep();
}
/////////////////////////////////////////////////////////////////

// Stop the robot
drrobotPlayer.stop();

return(0);}

I have attached a screenshot of the console out, I tried to send it three commands, but it shows nothing is received. It doesn't even enter the function cmdVelReceived to printf(" test \n");

Does anyone know what is going wrong here? Many thanks in advance.

Kind Regards, Martin

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by felix k
close date 2013-01-22 22:28:14

Comments

1

Are you sure you're publishing and subscribing on the same namespace? What does rostopic list tell you? It also could be a problem with your publisher. Does your subscriber register a callback if you publish to your topic with rostopic pub?

tbh gravatar imagetbh ( 2013-01-21 09:44:53 -0600 )edit

Yea, I tried it again after lunch and everything worked fine :S Must have been something in the system and after a restart it started working!

MartinW gravatar imageMartinW ( 2013-01-22 06:57:41 -0600 )edit