Skip to content

Commit 8af2e4c

Browse files
haider8645Mulo01chhtz
authored
Add unit tests (#18)
* Add unit tests for environmentxyztheta * Add boost::filesystem library (must be after ugv_nav4d) * Add unit tests * Cleanup headers * Use set locale to C for grid resolution parameter from cli for gui * Throw error if translation or angular velocity is 0.0 * Add unit tests for computed motions * Update readme for unit tests * Test costs calculation for only one motion * Check if final pose of full and sampled splines * Check validity of underlying values in generated trajectories * Use the ugv_nav4d target for tests * Use rock executable macro for tests * Add filesystem dependency to all ugv_nav4d dependent tests --------- Co-authored-by: Mulo01 <[email protected]> Co-authored-by: Christoph Hertzberg <[email protected]>
1 parent 03ac049 commit 8af2e4c

9 files changed

+709
-395
lines changed

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,8 @@ cd build
106106
cmake -DCMAKE_INSTALL_PREFIX=./install -DTESTS_ENABLED=ON -DENABLE_DEBUG_DRAWINGS=OFF -DCMAKE_BUILD_TYPE=RELEASE ..
107107
make install
108108
```
109-
Run the unit tests using the executable
110-
```
111-
test_ugv_nav4d ../test_data/Plane1Mio.ply
112-
```
113109

114-
At the end you should see the output
115-
```
116-
[----------] Global test environment tear-down
117-
[==========] 6 tests from 2 test suites ran. (10297 ms total)
118-
[ PASSED ] 6 tests.
119-
```
110+
The test executables are in the folder: `build/src/test/`.
120111

121112
---
122113
# ROS 2 Humble Test Environment with Gazebo Fortress

src/Mobility.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ struct Mobility {
4343
Mobility() :
4444
translationSpeed(1.0),
4545
rotationSpeed(1.0),
46-
minTurningRadius(0.0),
47-
spline_sampling_resolution(0.01),
48-
remove_goal_offset(true),
46+
minTurningRadius(1.0),
47+
spline_sampling_resolution(0.05),
48+
remove_goal_offset(false),
4949
multiplierForward(1),
50-
multiplierBackward(1),
51-
multiplierLateral(1),
52-
multiplierForwardTurn(1),
53-
multiplierBackwardTurn(1),
54-
multiplierPointTurn(1),
55-
multiplierLateralCurve(1),
56-
searchRadius(2.0),
50+
multiplierBackward(2),
51+
multiplierLateral(4),
52+
multiplierForwardTurn(2),
53+
multiplierBackwardTurn(3),
54+
multiplierPointTurn(3),
55+
multiplierLateralCurve(4),
56+
searchRadius(1.0),
5757
searchProgressSteps(0.1),
58-
maxMotionCurveLength(1.2)
58+
maxMotionCurveLength(100)
5959
{
6060
}
6161

src/PreComputedMotions.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ void PreComputedMotions::computeSplinePrimCost(const SplinePrimitive& prim,
296296
int Motion::calculateCost(double translationalDist, double angularDist, double translationVelocity,
297297
double angularVelocity, double costMultiplier)
298298
{
299+
if (translationVelocity == 0.0 || angularVelocity == 0.0) {
300+
LOG_ERROR_S << "ERROR calculateCost: Division by zero translation or angular velocity.";
301+
throw std::runtime_error("ERROR calculateCost: Division by zero translation or angular velocity.");
302+
303+
}
299304
const double translationTime = translationalDist / translationVelocity;
300305
const double angularTime = angularDist / angularVelocity;
301306

@@ -304,7 +309,7 @@ int Motion::calculateCost(double translationalDist, double angularDist, double t
304309

305310
if(cost > std::numeric_limits<int>::max())
306311
{
307-
std::cerr << "WARNING: primitive cost too large for int. Clipping to int_max." << std::endl;
312+
LOG_ERROR_S << "WARNING: primitive cost too large for int. Clipping to int_max.";
308313
return std::numeric_limits<int>::max();
309314
}
310315
else

src/test/CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
find_package(Boost REQUIRED COMPONENTS filesystem)
1+
find_package(Boost REQUIRED COMPONENTS filesystem serialization)
22

3-
4-
rock_executable(test_ugv_nav4d
5-
SOURCES test_ugv_nav4d.cpp
3+
rock_executable(test_Planner
4+
SOURCES test_Planner.cpp
5+
DEPS Boost::filesystem
66
DEPS_PKGCONFIG ugv_nav4d
77
)
88

99
rock_executable(test_EnvironmentXYZTheta
1010
SOURCES test_EnvironmentXYZTheta.cpp
11-
DEPS Boost::filesystem
11+
DEPS Boost::filesystem Boost::serialization
12+
DEPS_PKGCONFIG ugv_nav4d
13+
)
14+
15+
rock_executable(test_DiscreteTheta
16+
SOURCES test_DiscreteTheta.cpp
17+
DEPS_PKGCONFIG ugv_nav4d
18+
)
19+
20+
rock_executable(test_PreComputedMotions
21+
SOURCES test_PreComputedMotions.cpp
22+
DEPS Boost::filesystem
1223
DEPS_PKGCONFIG ugv_nav4d
1324
)

src/test/test_DiscreteTheta.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define BOOST_TEST_MODULE DiscreteThetaModule
2+
#include <boost/test/included/unit_test.hpp>
3+
4+
#include "ugv_nav4d/DiscreteTheta.hpp"
5+
6+
BOOST_AUTO_TEST_CASE(check_discrete_theta_init) {
7+
DiscreteTheta theta = DiscreteTheta(0, 16);
8+
BOOST_CHECK_CLOSE_FRACTION(theta.getRadian(), 0, 0.01);
9+
10+
theta = DiscreteTheta(1, 16);
11+
BOOST_CHECK_EQUAL(theta.getNumAngles(), 16);
12+
BOOST_CHECK_CLOSE_FRACTION(theta.getRadian(), 0.3926, 0.01);
13+
14+
theta = DiscreteTheta(-1, 16);
15+
BOOST_CHECK_EQUAL(theta.getTheta(), 15);
16+
BOOST_CHECK_CLOSE_FRACTION(theta.getRadian(), 5.8904, 0.01);
17+
18+
theta = DiscreteTheta(18, 16);
19+
BOOST_CHECK_EQUAL(theta.getTheta(), 2);
20+
21+
theta = DiscreteTheta(16, 16);
22+
BOOST_CHECK_EQUAL(theta.getTheta(), 0);
23+
24+
theta = DiscreteTheta(5.90, 16);
25+
BOOST_CHECK_EQUAL(theta.getTheta(), 15);
26+
27+
theta = DiscreteTheta(5.45, 16);
28+
BOOST_CHECK_CLOSE_FRACTION(theta.getRadian(), 5.45, 0.01);
29+
BOOST_CHECK_EQUAL(theta.getTheta(), 14);
30+
31+
DiscreteTheta thetaA = DiscreteTheta(3, 16);
32+
DiscreteTheta thetaB = DiscreteTheta(5, 16);
33+
BOOST_CHECK_EQUAL(thetaA.shortestDist(thetaB).getTheta(), 2);
34+
35+
thetaA = DiscreteTheta(2, 16);
36+
thetaB = DiscreteTheta(14, 16);
37+
BOOST_CHECK_EQUAL(thetaA.shortestDist(thetaB).getTheta(), 4);
38+
}

0 commit comments

Comments
 (0)