ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Right Angle Turn Problem

asked 2014-12-31 05:46:52 -0600

emreay gravatar image


I'm trying to move my urdf model on a rectangular/square trajectory in rviz. In order to do that I try to broadcast certain transforms within certain time intervals using a timer. But the robot cannot turn exact 90 degrees, instead it turns a bit less. The errors are summed and the trajectory becomes useless. What is the right way to do this ? Thanks.

My transform broadcaster node:


class rectangularTrajectory
    void moveAgv(double vx, double vy, double wth);
    void setPrevTime(ros::Time now);
    int getState();

    void timerCallback(const ros::TimerEvent&);
    void broadcastTF(tf::TransformBroadcaster *tf_broadcaster,
                    std::string device_frame,
                    double x, double y, double z,
                    double theta);
    ros::NodeHandle nh_;
    ros::Timer timer;
    tf::TransformBroadcaster broadcaster;
    double x, y, th, vx, vy, wth, dt, delta_x, delta_y, delta_th;
    ros::Time current_time, prev_time, duration;

    ROS_INFO("Calling the constructor of the class rectangularTrajectory");
    timer = nh_.createTimer(ros::Duration(1.0), &rectangularTrajectory::timerCallback, this);
    x = 0.0;
    y = 0.0;
    th = M_PI/2;

    ROS_INFO("Calling the deconstructor of the class rectangularTrajectory");

void rectangularTrajectory::broadcastTF(tf::TransformBroadcaster *tf_broadcaster,
                 std::string device_frame,
                 double x, double y, double z,
                 double theta)
    // broadcast Transform from vehicle to device
    geometry_msgs::TransformStamped odom_trans;
    odom_trans.header.stamp = ros::Time::now();
    odom_trans.header.frame_id = "odom";
    odom_trans.child_frame_id = device_frame;
    odom_trans.transform.translation.x = x;
    odom_trans.transform.translation.y = y;
    odom_trans.transform.translation.z = z;
    odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(theta);
    //broadcasting the transform

void rectangularTrajectory::moveAgv(double vx, double vy, double wth)
    current_time = ros::Time::now(); //set current time
    dt = (current_time - prev_time).toSec(); //time differential
    delta_x = vx*cos(th)*dt; //change in x axis in world frame
    delta_y = vx*sin(th)*dt; //change in y axis in world frame
    delta_th = wth*dt; //change in the orientation
    x += delta_x;
    y += delta_y;
    th += delta_th;
    //broadcast transforms
    //set previous time
    prev_time = current_time;

void rectangularTrajectory::setPrevTime(ros::Time now)
    prev_time =;

int rectangularTrajectory::getState()
    int state;  
    return state;

void rectangularTrajectory::timerCallback(const ros::TimerEvent&)
    int new_state;
    new_state = getState()+1;
    ROS_INFO("timer triggered, new state: %d",new_state);

//main function
int main(int argc, char** argv) 
    ros::init(argc, argv, "rectangular_tf"); //node initialize
    rectangularTrajectory rectangularTrajectory_;
    while (ros::ok())

        while((rectangularTrajectory_.getState())%2 == 0)

        while((rectangularTrajectory_.getState())%2 == 1)

    }//end of while
    return 0;
}//end of main

My launch file:

    <!-- RVIZ -->
    <node name="rviz" pkg="rviz" type="rviz" args="-d $(find agv)/urdf.rviz" />
    <arg name="gui" default="False" />
    <param name="robot_description" textfile="$(find agv)/urdf/agv_.urdf" />
    <param name="use_gui" value="$(arg gui)"/>
    <param name="state" value="0" type="int"/>
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
    <!-- RECTANGULAR TF ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-12-31 13:00:53 -0600

Airuno2L gravatar image

updated 2014-12-31 13:02:12 -0600

Unfortunately there is not a way to fix this problem with out adding additional sensors. Dead reckoning will always result in the type of errors you are experiencing. Whether inaccuracies are from the error in your measurement of your wheels, the wheels slipping every now and then, etc. those little errors add up very quickly. You'll need some way to sense the robot's environment, such as a LIDAR, Kinect, ultrasonic sensors, GPS, etc.

If you did have a LIDAR on board, ROS's navigation package is capable of doing really good localization.

edit flag offensive delete link more


Thank you for your answer. But I see that your answer is about localization of real robot in real world, however I'm just trying to achieve this 'ideal' trajectory with a model in rviz so there are no wheel measurement errors and slipping. My problem is code originated.

emreay gravatar image emreay  ( 2014-12-31 14:29:49 -0600 )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: 2014-12-31 05:46:52 -0600

Seen: 367 times

Last updated: Dec 31 '14