22
22
#include " nav_msgs/msg/path.hpp"
23
23
#include " nav2_util/path_utils.hpp"
24
24
25
- geometry_msgs::msg::PoseStamped createPose (double x, double y)
25
+ geometry_msgs::msg::PoseStamped createPoseStamped (double x, double y)
26
26
{
27
27
geometry_msgs::msg::PoseStamped pose;
28
28
pose.pose .position .x = x;
@@ -32,6 +32,16 @@ geometry_msgs::msg::PoseStamped createPose(double x, double y)
32
32
return pose;
33
33
}
34
34
35
+ geometry_msgs::msg::Pose createPose (double x, double y)
36
+ {
37
+ geometry_msgs::msg::Pose pose;
38
+ pose.position .x = x;
39
+ pose.position .y = y;
40
+ pose.position .z = 0.0 ;
41
+ pose.orientation .w = 1.0 ;
42
+ return pose;
43
+ }
44
+
35
45
void generateCirclePath (
36
46
nav_msgs::msg::Path & path,
37
47
double center_x, double center_y, double radius,
@@ -40,12 +50,25 @@ void generateCirclePath(
40
50
const double angle_step = (end_angle - start_angle) / (num_points - 1 );
41
51
for (int i = 0 ; i < num_points; ++i) {
42
52
const double angle = start_angle + i * angle_step;
43
- path.poses .push_back (createPose (
53
+ path.poses .push_back (createPoseStamped (
44
54
center_x + radius * std::cos (angle),
45
55
center_y + radius * std::sin (angle)));
46
56
}
47
57
}
48
58
59
+ void generateCircleTrajectory (
60
+ std::vector<geometry_msgs::msg::Pose> & path,
61
+ double center_x, double center_y, double radius,
62
+ int num_points, double start_angle = 0.0 , double end_angle = 2.0 * M_PI)
63
+ {
64
+ const double angle_step = (end_angle - start_angle) / (num_points - 1 );
65
+ for (int i = 0 ; i < num_points; ++i) {
66
+ const double angle = start_angle + i * angle_step;
67
+ path.push_back (createPose (
68
+ center_x + radius * std::cos (angle),
69
+ center_y + radius * std::sin (angle)));
70
+ }
71
+ }
49
72
class CloverleafPathTest : public ::testing::Test
50
73
{
51
74
protected:
@@ -57,14 +80,14 @@ class CloverleafPathTest : public ::testing::Test
57
80
generateCirclePath (target_path, 0.0 , 5.0 , 5.0 , 50 );
58
81
59
82
// Robot trajectory now also travels all three leaves, but with a radius of 4.8
60
- nav_msgs:: msg::Path robot_path;
61
- generateCirclePath (robot_path, 5.0 , 0.0 , 4.8 , 50 );
62
- generateCirclePath (robot_path, -5.0 , 0.0 , 4.8 , 50 );
63
- generateCirclePath (robot_path, 0.0 , 5.0 , 4.8 , 50 );
64
- robot_trajectory = robot_path. poses ;
83
+ std::vector<geometry_msgs:: msg::Pose> robot_path;
84
+ generateCircleTrajectory (robot_path, 5.0 , 0.0 , 4.8 , 50 );
85
+ generateCircleTrajectory (robot_path, -5.0 , 0.0 , 4.8 , 50 );
86
+ generateCircleTrajectory (robot_path, 0.0 , 5.0 , 4.8 , 50 );
87
+ robot_trajectory = robot_path;
65
88
}
66
89
nav_msgs::msg::Path target_path;
67
- std::vector<geometry_msgs::msg::PoseStamped > robot_trajectory;
90
+ std::vector<geometry_msgs::msg::Pose > robot_trajectory;
68
91
};
69
92
70
93
class RetracingCircleTest : public ::testing::Test
@@ -74,25 +97,25 @@ class RetracingCircleTest : public ::testing::Test
74
97
{
75
98
generateCirclePath (target_path, 0.0 , 0.0 , 5.0 , 50 , 0.0 , 2.0 * M_PI);
76
99
generateCirclePath (target_path, 0.0 , 0.0 , 5.0 , 50 , 2.0 * M_PI, 0.0 );
77
- nav_msgs:: msg::Path robot_path;
78
- generateCirclePath (robot_path, 0.0 , 0.0 , 5.2 , 50 , 0.0 , 2.0 * M_PI);
79
- generateCirclePath (robot_path, 0.0 , 0.0 , 5.2 , 50 , 2.0 * M_PI, 0.0 );
80
- robot_trajectory = robot_path. poses ;
100
+ std::vector<geometry_msgs:: msg::Pose> robot_path;
101
+ generateCircleTrajectory (robot_path, 0.0 , 0.0 , 5.2 , 50 , 0.0 , 2.0 * M_PI);
102
+ generateCircleTrajectory (robot_path, 0.0 , 0.0 , 5.2 , 50 , 2.0 * M_PI, 0.0 );
103
+ robot_trajectory = robot_path;
81
104
}
82
105
nav_msgs::msg::Path target_path;
83
- std::vector<geometry_msgs::msg::PoseStamped > robot_trajectory;
106
+ std::vector<geometry_msgs::msg::Pose > robot_trajectory;
84
107
};
85
108
86
109
class ZigZagPathTest : public ::testing::Test
87
110
{
88
111
protected:
89
112
void SetUp () override
90
113
{
91
- target_path.poses .push_back (createPose (0.0 , 0.0 ));
92
- target_path.poses .push_back (createPose (10.0 , 0.0 ));
93
- target_path.poses .push_back (createPose (10.0 , 5.0 ));
94
- target_path.poses .push_back (createPose (0.0 , 5.0 ));
95
- target_path.poses .push_back (createPose (0.0 , 10.0 ));
114
+ target_path.poses .push_back (createPoseStamped (0.0 , 0.0 ));
115
+ target_path.poses .push_back (createPoseStamped (10.0 , 0.0 ));
116
+ target_path.poses .push_back (createPoseStamped (10.0 , 5.0 ));
117
+ target_path.poses .push_back (createPoseStamped (0.0 , 5.0 ));
118
+ target_path.poses .push_back (createPoseStamped (0.0 , 10.0 ));
96
119
97
120
robot_trajectory = {
98
121
createPose (1.0 , 0.2 ), createPose (5.0 , 0.2 ), createPose (9.0 , 0.2 ),
@@ -102,18 +125,18 @@ class ZigZagPathTest : public ::testing::Test
102
125
};
103
126
}
104
127
nav_msgs::msg::Path target_path;
105
- std::vector<geometry_msgs::msg::PoseStamped > robot_trajectory;
128
+ std::vector<geometry_msgs::msg::Pose > robot_trajectory;
106
129
};
107
130
108
131
class HairpinTurnTest : public ::testing::Test
109
132
{
110
133
protected:
111
134
void SetUp () override
112
135
{
113
- target_path.poses .push_back (createPose (0.0 , 1.0 ));
114
- target_path.poses .push_back (createPose (10.0 , 1.0 ));
115
- target_path.poses .push_back (createPose (10.0 , -1.0 ));
116
- target_path.poses .push_back (createPose (0.0 , -1.0 ));
136
+ target_path.poses .push_back (createPoseStamped (0.0 , 1.0 ));
137
+ target_path.poses .push_back (createPoseStamped (10.0 , 1.0 ));
138
+ target_path.poses .push_back (createPoseStamped (10.0 , -1.0 ));
139
+ target_path.poses .push_back (createPoseStamped (0.0 , -1.0 ));
117
140
118
141
robot_trajectory = {
119
142
createPose (1.0 , 1.2 ), createPose (3.0 , 1.2 ), createPose (5.0 , 1.2 ),
@@ -124,17 +147,17 @@ class HairpinTurnTest : public ::testing::Test
124
147
};
125
148
}
126
149
nav_msgs::msg::Path target_path;
127
- std::vector<geometry_msgs::msg::PoseStamped > robot_trajectory;
150
+ std::vector<geometry_msgs::msg::Pose > robot_trajectory;
128
151
};
129
152
130
153
class CuttingCornerTest : public ::testing::Test
131
154
{
132
155
protected:
133
156
void SetUp () override
134
157
{
135
- target_path.poses .push_back (createPose (0.0 , 0.0 ));
136
- target_path.poses .push_back (createPose (10.0 , 0.0 ));
137
- target_path.poses .push_back (createPose (10.0 , 10.0 ));
158
+ target_path.poses .push_back (createPoseStamped (0.0 , 0.0 ));
159
+ target_path.poses .push_back (createPoseStamped (10.0 , 0.0 ));
160
+ target_path.poses .push_back (createPoseStamped (10.0 , 10.0 ));
138
161
139
162
robot_trajectory = {
140
163
createPose (0.0 , 0.2 ), createPose (2.0 , 0.2 ), createPose (4.0 , 0.2 ),
@@ -145,7 +168,7 @@ class CuttingCornerTest : public ::testing::Test
145
168
expected_distances = {0.2 , 0.2 , 0.2 , 0.2 , 0.2 , 1.0 , 0.2 , 0.2 , 0.2 , 0.2 , 0.2 };
146
169
}
147
170
nav_msgs::msg::Path target_path;
148
- std::vector<geometry_msgs::msg::PoseStamped > robot_trajectory;
171
+ std::vector<geometry_msgs::msg::Pose > robot_trajectory;
149
172
std::vector<double > expected_distances;
150
173
};
151
174
@@ -154,8 +177,8 @@ class RetracingPathTest : public ::testing::Test
154
177
protected:
155
178
void SetUp () override
156
179
{
157
- for (int i = 0 ; i <= 10 ; ++i) {target_path.poses .push_back (createPose (i, 0.0 ));}
158
- for (int i = 9 ; i >= 0 ; --i) {target_path.poses .push_back (createPose (i, 0.0 ));}
180
+ for (int i = 0 ; i <= 10 ; ++i) {target_path.poses .push_back (createPoseStamped (i, 0.0 ));}
181
+ for (int i = 9 ; i >= 0 ; --i) {target_path.poses .push_back (createPoseStamped (i, 0.0 ));}
159
182
for (int i = 0 ; i <= 10 ; ++i) {
160
183
robot_trajectory.push_back (createPose (i, 0.5 ));
161
184
}
@@ -164,7 +187,7 @@ class RetracingPathTest : public ::testing::Test
164
187
}
165
188
}
166
189
nav_msgs::msg::Path target_path;
167
- std::vector<geometry_msgs::msg::PoseStamped > robot_trajectory;
190
+ std::vector<geometry_msgs::msg::Pose > robot_trajectory;
168
191
};
169
192
170
193
TEST (PathUtilsTest, EmptyAndSinglePointPaths)
@@ -176,7 +199,7 @@ TEST(PathUtilsTest, EmptyAndSinglePointPaths)
176
199
EXPECT_EQ (result.distance , std::numeric_limits<double >::max ());
177
200
178
201
nav_msgs::msg::Path single_point_path;
179
- single_point_path.poses .push_back (createPose (0.0 , 0.0 ));
202
+ single_point_path.poses .push_back (createPoseStamped (0.0 , 0.0 ));
180
203
result = nav2_util::distance_from_path (single_point_path, robot_pose);
181
204
EXPECT_NEAR (result.distance , 7.071 , 0.01 );
182
205
}
@@ -303,8 +326,8 @@ TEST(PathUtilsWindowedTest, EdgeCases)
303
326
{
304
327
auto robot_pose = createPose (5.0 , 5.0 );
305
328
nav_msgs::msg::Path test_path;
306
- test_path.poses .push_back (createPose (0.0 , 0.0 ));
307
- test_path.poses .push_back (createPose (10.0 , 0.0 ));
329
+ test_path.poses .push_back (createPoseStamped (0.0 , 0.0 ));
330
+ test_path.poses .push_back (createPoseStamped (10.0 , 0.0 ));
308
331
309
332
auto result = nav2_util::distance_from_path (test_path, robot_pose, 0 , 5.0 );
310
333
EXPECT_NEAR (result.distance , 5.0 , 0.01 );
0 commit comments