# Revision history [back]

### Simulate Odometry with Ackermann Locomotion

Hello,

I am trying to simulate odometry in an ackermann vehicle with gazebo but the error that I get after twenty meters is about 4 meters. I think the result of the GetAngle method is strange when the robot is stopped, because in every cycle the number representing the angle of the wheel decreases. The code that i have is the following:

        double currentLeftposition = frontLeft->GetAngle(positionAxis).Radian();
geometry_msgs::TransformStamped odom_trans;
nav_msgs::Odometry odom;
math::Pose currentPose;
math::Vector3 position;
math::Quaternion rotation;
double xPos,yPos,orientation;
double currentLinearVelocity=rear->GetVelocity(1);
double twoPI=2*M_PI;
double angleDiff=angles::shortest_angular_distance(prevRearWheelRotationAngle,rearWheelRotationAngle);
prevRearWheelRotationAngle=rearWheelRotationAngle;
double revolution=angleDiff/twoPI;
double revolution=(currentLinearVelocity*stepTime.Double())/twoPI;
double wheelCircuference=wheelDiameter*M_PI;
double distanceTravelledByWheel=revolution*wheelCircuference;
double steering=getMiddleWheelAngle(-currentLeftposition,-currentRightPosition);
double turningAngle=tan(steering)/distanceBetweenAxis;
double previousOrientation=previousPose.rot.GetYaw();
math::Vector3 previousPosition=previousPose.pos;
if(fabs(turningAngle)<0.001) //assume that the car is going ahead
{
xPos= previousPosition.x + distanceTravelledByWheel*cos(previousOrientation);
yPos= previousPosition.y + distanceTravelledByWheel*sin(previousOrientation);
orientation=previousOrientation;
}
else
{
double delta_theta=turningAngle*distanceTravelledByWheel;