ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

My teleop node is not very reactive

asked 2020-05-02 07:28:54 -0500

Marcus Barnet gravatar image

updated 2020-05-02 13:24:00 -0500

I wrote my own teleop node in order to use my joypad with my robot. It works fine, but the robot takes few addition seconds to stop even if I already released the stick on the joypad.

It seems a buffer problem or something related to the node frame rate, but I'm not so sure.

This is my teleop node:

TeleopRobo::TeleopRobo():
  linear_(1),
  angular_(2)
{

  nh_.param("axis_linear", linear_, linear_);
  nh_.param("axis_angular", angular_, angular_);
  nh_.param("axis_rotation", rotation_, rotation_);
  nh_.param("scale_angular", a_scale_, a_scale_);
  nh_.param("scale_linear", l_scale_, l_scale_);
  nh_.param("scale_rotation", s_rotation_, s_rotation_);

  vel_pub_ = nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1000);

  joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 1000, &TeleopRobo::joyCallback, this);

}

void TeleopRobo::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
  geometry_msgs::Twist twist;
  twist.linear.y = a_scale_*joy->axes[angular_];
  twist.linear.x = l_scale_*joy->axes[linear_];
  twist.angular.z = -s_rotation_*joy->axes[rotation_];
  vel_pub_.publish(twist);
}


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

  ros::Rate loop_rate(10);

  ros::spin();
}

and this is the node used to control my robot:

int main(int argc, char **argv)
{
ros::init(argc, argv, "base_controller");
ros::NodeHandle n;
ros::Rate loop_rate(10);
ros::Subscriber cmd_vel = n.subscribe("cmd_vel", 1000, &RoboteqDevice::cmd_velCallback, &device);

ros::spin();

return 0;
}

void RoboteqDevice::cmd_velCallback(const geometry_msgs::Twist::ConstPtr& msg)
{
ROS_INFO("X=%.3f  Y= %.3f  Z=%.3f  Angle: %.1f ", (float) msg->linear.x, (float) msg->linear.y, (float) msg->linear.z, (float) msg->angular.z);
vel_x = msg->linear.x;
vel_y = msg->linear.y;
vteta_z = msg->angular.z;

// send commands to motors
}

This is my rqt_graph output:

image description

If I use rostopic echo /cmd_vel I can see that the values instantly go to zero when I release the stick, so the problem should be on the base_controller node.

What do you think?

EDIT1:

I changed the queue size to 1 in the subscriber and now the robot is very reactive! Thank you! The problem is that the robot stops after a while even if I'm still pushing the stick. I checked the output of /joy topic and when the robot stop also the output of the /joy topic stops. Then, I need to release the stick or to press another button in order to restore the joystick. Why this happen?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2020-05-02 09:38:45 -0500

hashirzahir gravatar image

Hi, I noticed in your cmd_vel subscriber, you have declared a queue size of 1000 messages for the cmd_vel topic.

From the ROS wiki,

ros::Subscriber subscribe(const std::string& topic, uint32_t queue_size, <callback>, transport_hints)

This implies that there is a backlog of 1000 velocity commands in the subscriber queue and hence your base controller will not be processing the latest command given by your joystick but rather a command given a few seconds ago. To fix this, simply set a smaller queue size. A queue size of 1 will ensure that only the latest command from the joystick will be interpreted but at the cost of ignoring some older commands since likely your joystick will publish command values faster than the base_controller node can process them. So you can balance out these 2 requirements and select a queue size between 1 and 10 and still receive "real time" response to your controller.

Hope that helps.

edit flag offensive delete link more

Comments

Thank you for yoru support! I'm going to try your suggestion and I'll let you know!

Marcus Barnet gravatar image Marcus Barnet  ( 2020-05-02 10:33:48 -0500 )edit

I changed the queue size to 1 in the subscriber and now the robot is very reactive! Thank you! The problem is that the robot stops after a while even if I'm still pushing the stick. I checked the output of /joy topic and when the robot stop also the output of the /joy topic stops. Then, I need to release the stick or to press another button in order to restore the joystick. Why this happen?

Marcus Barnet gravatar image Marcus Barnet  ( 2020-05-02 13:23:41 -0500 )edit

I solved it thanks to this topic.

Marcus Barnet gravatar image Marcus Barnet  ( 2020-05-02 13:36:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-05-02 07:28:54 -0500

Seen: 330 times

Last updated: May 02 '20