Skip to content

Commit fd39076

Browse files
author
Enrique Fernandez
committed
Add odometry unit test suite
1 parent c848559 commit fd39076

File tree

5 files changed

+713
-3
lines changed

5 files changed

+713
-3
lines changed

diff_drive_controller/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ if (CATKIN_ENABLE_TESTING)
8383
${catkin_INCLUDE_DIRS}
8484
${EIGEN_INCLUDE_DIRS})
8585

86+
catkin_add_gtest(odometry_test test/odometry_test.cpp)
87+
target_link_libraries(odometry_test ${PROJECT_NAME})
88+
8689
add_executable(diffbot test/diffbot.cpp)
8790
target_link_libraries(diffbot ${catkin_LIBRARIES})
8891

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*********************************************************************
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2016, Clearpath Robotics, Inc.
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
* * Neither the name of the PAL Robotics nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*********************************************************************/
34+
35+
/*
36+
* Author: Enrique Fernández
37+
*/
38+
39+
#ifndef RIGID_BODY_MOTION_H_
40+
#define RIGID_BODY_MOTION_H_
41+
42+
#include <Eigen/Dense>
43+
44+
#include <limits>
45+
46+
namespace diff_drive_controller
47+
{
48+
49+
/**
50+
* \brief Compute rigid body motion in SE(2) using element-wise equations.
51+
* \param[in, out] x Pose x component
52+
* \param[in, out] y Pose y component
53+
* \param[in, out] yaw Pose yaw component
54+
* \param[in] v_x Velocity/Twist x component
55+
* \param[in] v_y Velocity/Twist y component
56+
* \param[in] v_yaw Velocity/Twist yaw component
57+
* \param[in] dt Time step
58+
*/
59+
static void integrate_motion(double& x, double &y, double &yaw,
60+
const double v_x, const double v_y, const double v_yaw,
61+
const double dt)
62+
{
63+
const double cos_yaw = std::cos(yaw);
64+
const double sin_yaw = std::sin(yaw);
65+
66+
x += (v_x * cos_yaw - v_y * sin_yaw) * dt;
67+
y += (v_x * sin_yaw + v_y * cos_yaw) * dt;
68+
yaw += v_yaw * dt;
69+
}
70+
71+
/**
72+
* \brief Compute rigid body motion in SE(2) using element-wise equations.
73+
* Also computes the Jacobians wrt the pose and the velocity/twist.
74+
* \param[in, out] x Pose x component
75+
* \param[in, out] y Pose y component
76+
* \param[in, out] yaw Pose yaw component
77+
* \param[in] v_x Velocity/Twist x component
78+
* \param[in] v_y Velocity/Twist y component
79+
* \param[in] v_yaw Velocity/Twist yaw component
80+
* \param[in] dt Time step
81+
*/
82+
static void integrate_motion(double& x, double &y, double &yaw,
83+
const double v_x, const double v_y, const double v_yaw,
84+
const double dt,
85+
Eigen::Matrix3d& J_pose, Eigen::Matrix3d& J_twist)
86+
{
87+
const double cos_yaw = std::cos(yaw);
88+
const double sin_yaw = std::sin(yaw);
89+
90+
x += (v_x * cos_yaw - v_y * sin_yaw) * dt;
91+
y += (v_x * sin_yaw + v_y * cos_yaw) * dt;
92+
yaw += v_yaw * dt;
93+
94+
J_pose << 1.0, 0.0, (-v_x * sin_yaw - v_y * cos_yaw) * dt,
95+
0.0, 1.0, ( v_x * cos_yaw - v_y * sin_yaw) * dt,
96+
0.0, 0.0, 1.0;
97+
98+
J_twist << cos_yaw * dt, -sin_yaw * dt, 0.0,
99+
sin_yaw * dt, cos_yaw * dt, 0.0,
100+
0.0, 0.0, 1.0;
101+
}
102+
103+
}
104+
105+
#endif /* RIGID_BODY_MOTION_H_ */

diff_drive_controller/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<!--Tests-->
4747
<build_depend>rostest</build_depend>
4848

49+
<test_depend>gtest</test_depend>
4950
<test_depend>std_srvs</test_depend>
5051
<test_depend>controller_manager</test_depend>
5152
<test_depend>control_toolbox</test_depend>

diff_drive_controller/test/diff_drive_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
#include <tf/transform_listener.h>
3636

37-
#define POSE_COVARIANCE_MAX_CONDITION_NUMBER 1e8
38-
#define TWIST_COVARIANCE_MAX_CONDITION_NUMBER 1e8
37+
const double POSE_COVARIANCE_MAX_CONDITION_NUMBER = 1e8;
38+
const double TWIST_COVARIANCE_MAX_CONDITION_NUMBER = POSE_COVARIANCE_MAX_CONDITION_NUMBER;
3939

4040
// TEST CASES
4141
TEST_F(DiffDriveControllerTest, testNoMove)
@@ -147,7 +147,7 @@ TEST_F(DiffDriveControllerTest, testNoMove)
147147
// where Odometry::DEFAULT_MINIMUM_TWIST_COVARIANCE == 1e-9
148148
TwistCovariance minimum_twist_covariance = 1e-9 * TwistCovariance::Identity();
149149
EXPECT_TRUE(((twist_covariance - minimum_twist_covariance).array() == 0).all())
150-
<< "Twist covariance=\n" << twist_covariance.format(HeavyFmt);
150+
<< "Twist covariance =\n" << twist_covariance.format(HeavyFmt);
151151
}
152152

153153
TEST_F(DiffDriveControllerTest, testForward)

0 commit comments

Comments
 (0)