Skip to content

[B] Usage: Base

Jan edited this page May 13, 2016 · 1 revision

The basic usage for the base is the same as for the arm.

This tutorial only introduces the base-specific functions. Position Command

At the current stage the base API only supports one method for position commands. The move() method moves the youBot base to the specified goal position relative to the current position.

 void move(double x, double y, double theta) 

The arguments are:

  • x: Distance in x direction in meters. Positive x means the robot moves forward.
  • y: Distance in y direction in meters. Positive y means the robot moves to the left.
  • theta: Angle in radians. Positive theta means the robot rotates counter-clockwise.

The given theta is normalized to a range from -pi to +pi. This means the robot will never rotate more than 180° and e.g. 2*pi is equivalent to 0. Traveled Distance

The base API keeps track of the traveled distance. The traveled distance of all movement actions is accumulated until resetTraveledDistance()is called. The current values can be obtained by calling getTravelledDistance().

youbot_api::Pose2D getTraveledDistance()

This can be useful e.g. if the movement was aborted or if you want to return to the start position after a couple of different movements as shown in the following example.

// set traveled distance to zero
base.resetTraveledDistance();

// do some movements
base.move(...);
base.move(...);
base.move(...);
base.move(...);

// get traveled distance
youbot_api::Pose2D dist = base.getTraveledDistance();

// move back to start position
base.move(-dist.x, -dist.y, -dist.theta);

Notice that the traveled distance is only saved when executing position actions (with the move() method). If the base is controlled e.g. by velocity commands, getTraveledDistance() will return wrong values. In that case the current pose based on odometry can be obtained by the method getCurrentPose() and the traveled distance can be can be calculated from the pose before and after the movement. Velocity commands

Velocity commands are sent via ROS topics.

The message type is geometry_msgs/Twist.

The topic is /cmd_vel.