@@ -36,66 +36,60 @@ int main(int argc, char **argv)
3636 // This is the linear distance traveled per degree of wheel rotation.
3737 double distPerDegree = wheelCircumference / 360.0 ;
3838
39+ // Setup the wheel parameters, and initialize
3940 odom.SetWheelParams (wheelSeparation, wheelRadius, wheelRadius);
4041 auto startTime = std::chrono::steady_clock::now ();
4142 odom.Init (startTime);
4243
4344 // Sleep for a little while, then update the odometry with the new wheel
4445 // position.
45- std::cout << " --- Rotate the both wheels by 1 degree. ---" << ' \n ' ;
46+ std::cout << " --- Rotate both wheels by 1 degree. ---" << ' \n ' ;
4647 auto time1 = startTime + std::chrono::milliseconds (100 );
4748 odom.Update (IGN_DTOR (1.0 ), IGN_DTOR (1.0 ), time1);
4849
49- // Linear velocity should be dist_traveled / time_elapsed.
50- std::cout << " \t Linear velocity: " << distPerDegree / 0.1
51- << " Odom linear velocity: " << odom. LinearVelocity () << std::endl;
50+ std::cout << " \t Linear velocity: \t " << distPerDegree / 0.1 << " m/s "
51+ << " \n\t Odom linear velocity:\t " << odom. LinearVelocity () << " m/s "
52+ << std::endl;
5253
53- // Angular velocity should be zero since the "robot" is traveling in a
54- // straight line.
55- std::cout << " Angular velocity should be zero since the 'robot' is traveling"
56- << " in a straight line:\n "
57- << " \t Odom angular velocity: "
58- << *odom.AngularVelocity () << std::endl;
54+ std::cout << " Angular velocity should be zero since the \" robot\" is traveling\n "
55+ << " in a straight line:\n "
56+ << " \t Odom angular velocity:\t "
57+ << *odom.AngularVelocity () << " rad/s" << std::endl;
5958
6059 // Sleep again, this time rotate the right wheel by 1 degree.
6160 std::cout << " --- This time rotate the right wheel by 1 degree. ---"
6261 << std::endl;
6362 auto time2 = time1 + std::chrono::milliseconds (100 );
6463 odom.Update (IGN_DTOR (2.0 ), IGN_DTOR (3.0 ), time2);
6564
66- // The heading should be the arc tangent of the linear distance traveled
67- // by the right wheel (the left wheel was stationary) divided by the
68- // wheel separation.
69- std::cerr << " The heading should be the arc tangent of the linear distance"
70- << " traveled by the right wheel (the left wheel was stationary)"
71- << " divided by the wheel separation.\n "
72- << " \t Heading: " << atan2 (distPerDegree, wheelSeparation)
73- << " Odom Heading " << *odom.Heading () << ' \n ' ;
65+ std::cout << " The heading should be the arc tangent of the linear distance\n "
66+ << " traveled by the right wheel (the left wheel was stationary)\n "
67+ << " divided by the wheel separation.\n "
68+ << " \t Heading:\t\t " << atan2 (distPerDegree, wheelSeparation) << " rad"
69+ << " \n\t Odom Heading:\t\t " << *odom.Heading () << " rad" << ' \n ' ;
7470
7571 // The X odom reading should have increased by the sine of the heading *
7672 // half the wheel separation.
7773 double xDistTraveled =
7874 sin (atan2 (distPerDegree, wheelSeparation)) * wheelSeparation * 0.5 ;
7975 double prevXPos = distPerDegree * 2.0 ;
80- std::cout << " \t X distance traveled " << xDistTraveled + prevXPos
81- << " Odom X: " << odom.X () << std::endl;
76+ std::cout << " \t X distance traveled: \t " << xDistTraveled + prevXPos << " m "
77+ << " \n\t Odom X: \t\t " << odom.X () << " m " << std::endl;
8278
83- // The Y odom reading should have increased by the cosine of the header *
79+ // The Y odom reading should have increased by the cosine of the heading *
8480 // half the wheel separation.
8581 double yDistTraveled = (wheelSeparation * 0.5 ) -
8682 cos (atan2 (distPerDegree, wheelSeparation)) * wheelSeparation * 0.5 ;
8783 double prevYPos = 0.0 ;
88- std::cout << " \t Y distance traveled " << yDistTraveled + prevYPos
89- << " Odom Y: " << odom.Y () << std::endl;
84+ std::cout << " \t Y distance traveled: \t " << yDistTraveled + prevYPos << " m "
85+ << " \n\t Odom Y: \t\t " << odom.Y () << " m " << std::endl;
9086
91- // Angular velocity should be the difference between the x and y distance
92- // traveled divided by the wheel separation divided by the seconds
93- // elapsed.
94- std::cout << " Angular velocity should be the difference between the x and y"
95- << " distance traveled divided by the wheel separation divided by"
96- << " the seconds elapsed.\n "
97- << " \t Angular velocity "
98- << ((xDistTraveled - yDistTraveled) / wheelSeparation) / 0.1
99- << " Odom angular velocity: " << *odom.AngularVelocity () << std::endl;
87+ std::cout << " Angular velocity should be the difference between the x and y\n "
88+ << " distance traveled divided by the wheel separation divided by\n "
89+ << " the seconds elapsed.\n "
90+ << " \t Angular velocity:\t "
91+ << ((xDistTraveled - yDistTraveled) / wheelSeparation) / 0.1 << " rad/s"
92+ << " \n\t Odom angular velocity:\t " << *odom.AngularVelocity () << " rad/s"
93+ << std::endl;
10094}
10195// ! [complete]
0 commit comments