Ask Your Question

Turtlebot 2 with Kobuki base - Jerky movement and Warning message

asked 2013-06-14 04:20:30 -0500

mickey11592 gravatar image

updated 2013-06-19 04:37:21 -0500

I am running the turtlebot 2 with c++ code I wrote. I continuously get an error message stating:

Is robot stalled? Motors current is very high

After the predetermined halt message I input (5 second delay) the turtlebot will continue moving again, and then halt after another second or so. Is there anything that I can do?

Here is how I am publishing velocity commands:

 #include "ros/ros.h"
//The following have the < and > symbols removed so that they appear in ros answers.
 #include iostream
 #include string
 #include vector
 #include math.h
 #include stdlib.h
 #include time.h
 #include diagnostic_msgs/DiagnosticStatus.h
 #include diagnostic_msgs/DiagnosticArray.h
 #include sensor_msgs/LaserScan.h
 #include geometry_msgs/Twist.h
 #include std_msgs/Int32.h
 using namespace std; 

 double secondsLaptop = 0;
 double secondsCreate = 0;

 //abort flag turned on if bump or wheeldrop sensors activated, or warning or error  messages are thrown
 bool ab0rt = 0;

 bool rotateDirSet=0;

 double linearVel = 0.0;
 double angularVel = 0.0; 

 //vector containing laserscan readings within kinect's field of view
 std::vector<double> rangeReadings;

 //these hold average distance values for leftmost and rightmost laser readings
 double distToLeftWall;
 double distToRightWall;
 double centerLeft;
 double centerRight;

//flag turned on when vector containing laserscan readings is initalized
bool rangesInit=0;

void laserAggCallback(const sensor_msgs::LaserScan::ConstPtr &msg)
  //sensor_msgs::LaserScan points = msg->ranges[i];

  //purge vector immediately before fresh values are pushed on

  //fill vector with full range of values from laserScan message (320 degrees)
  for(int i=0; i<640; i++)
    int k = i-1;
    if(i==0 && rangeReadings[i] != rangeReadings[i])
      rangeReadings[i] = 0.0;
      //cout << rangeReadings[i] << endl;

else if(rangeReadings[i] != rangeReadings[i])
  rangeReadings[i] = rangeReadings[k];
 // cout << rangeReadings[i] << endl;

// ROS_INFO("Range[%d]: [%f]",i ,rangeReadings[i]); } rangesInit=1; }

/* This method checks for nearby obstacles/walls and * allows the robot to stay centered while moving down a hallway. */ void driveCentered() { if (!rangeReadings.empty()) {

//variables to store average far left and far right laser scan readings

// holds the minimum laser scan reading
double minDistance=11.0;
// holds the index of the minimum laser scan reading
int minIndex=320;
// holds the average of all laser scan readings within Kinect's FOV
double avgDist=0;

//extract only the laser scan readings that are within the Kinect's field of view
for (int i=6;i<640;i++)
  avgDist += rangeReadings[i];
  if (rangeReadings[i]<minDistance)
   minIndex = i;

avgDist /= 634;

// check for objects/wall closer than 1m or for high avg distance reading indicating that
// the robot is directly facing a very close wall or corner
//if (minDistance < 1 || avgDist >= 9.0)
if(avgDist <= 0.6)

 // ROS_INFO("minDistance: %f", minDistance);
 // ROS_INFO("avgDist: %f", avgDist);
  // do not move forward
  linearVel = 0.0;
  //Make waiter turtlebot wait for 5 seconds *****
  // choose rotation direction based on location of minimum distance
  if (minIndex <= 320 && rotateDirSet == 0 )
    angularVel = 0.4;
  else if (rotateDirSet == 0)
    angularVel = -0.4;
  // set flag to ...
edit retag flag offensive close merge delete


Please put code snippets into the code block to improve readability. I took the freedom to edit your post accordingly.

bit-pirate gravatar image bit-pirate  ( 2013-06-18 14:17:25 -0500 )edit

Thank you very much, I forgot how to place the code into a code block.

mickey11592 gravatar image mickey11592  ( 2013-06-19 04:39:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-14 06:09:16 -0500

dornhege gravatar image

How did you setup your robot? What are you launching to run it?

The Turtlebot 2 launches come with a velocity mux preconfigured. If you run that, maybe your velocity commands are fighting other things like the joystick. In that case you probably want to use the input/navi topic in the mobile base launch.

edit flag offensive delete link more


I've edited the question to include the launch file

mickey11592 gravatar image mickey11592  ( 2013-06-14 06:38:02 -0500 )edit

can you post the full code? Cannot see the loop rate nor the velocities you send

jorge gravatar image jorge  ( 2013-06-18 13:57:08 -0500 )edit

It's also missing where the abort flag that causes the robot to stop comes from.

dornhege gravatar image dornhege  ( 2013-06-19 00:30:03 -0500 )edit

The high loop rate was changed gradually from 10 up until the 8000 it is because I noticed that when I increased it (up to a certain point) the turtlebot would receive the error less often and would move a little more smoothly.

mickey11592 gravatar image mickey11592  ( 2013-06-19 04:41:21 -0500 )edit

8000 seems very extreme... Can you try publishing to /cmd_vel_mux/input/navi instead of the mobile_base directly?

dornhege gravatar image dornhege  ( 2013-06-19 07:48:24 -0500 )edit

I changed the loop rate to 10 and published to /cmd_vel_mux/input/navi like you said and it appears to work perfectly. Thank you!

mickey11592 gravatar image mickey11592  ( 2013-06-19 08:00:42 -0500 )edit

cmd_vel_mux ( is written for Groovy/hydro. I am using P3AT robot on Fuerte. So can I use this package directly by simply modifying subscriber and publisher? Is there any problem with communication between nodelet and normal nodes? I have seen in here Where mobile_base has to be a nodelet as well. PLEASE REPLY

RB gravatar image RB  ( 2014-02-05 19:27:47 -0500 )edit

Please open a question if you have a new question. In short: I don't know if that works in fuerte, but it very well might.

dornhege gravatar image dornhege  ( 2014-02-05 22:42:45 -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


Asked: 2013-06-14 04:20:30 -0500

Seen: 1,553 times

Last updated: Jun 19 '13