Skip to content

Commit 20d9046

Browse files
authored
Merge pull request #181 from cogip/180-planner-allow-forcing-backward-motions
180 planner allow forcing backward motions
2 parents ecd0f89 + 002093d commit 20d9046

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+570
-318
lines changed

cogip/cpp/libraries/models/PoseOrder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PoseOrder::PoseOrder(
2626
double angle,
2727
std::uint8_t max_speed_linear,
2828
std::uint8_t max_speed_angular,
29-
bool allow_reverse,
29+
MotionDirection motion_direction,
3030
bool bypass_anti_blocking,
3131
bool bypass_final_orientation,
3232
std::uint32_t timeout_ms,
@@ -42,7 +42,7 @@ PoseOrder::PoseOrder(
4242
data_->angle = angle;
4343
data_->max_speed_linear = max_speed_linear;
4444
data_->max_speed_angular = max_speed_angular;
45-
data_->allow_reverse = allow_reverse;
45+
data_->motion_direction = motion_direction;
4646
data_->bypass_anti_blocking = bypass_anti_blocking;
4747
data_->bypass_final_orientation = bypass_final_orientation;
4848
data_->timeout_ms = timeout_ms;

cogip/cpp/libraries/models/PoseOrderList.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void PoseOrderList::append(
1414
double angle,
1515
std::uint8_t max_speed_linear,
1616
std::uint8_t max_speed_angular,
17-
bool allow_reverse,
17+
MotionDirection motion_direction,
1818
bool bypass_anti_blocking,
1919
bool bypass_final_orientation,
2020
std::uint32_t timeout_ms,
@@ -29,7 +29,7 @@ void PoseOrderList::append(
2929
list_->elems[list_->count].angle = angle;
3030
list_->elems[list_->count].max_speed_linear = max_speed_linear;
3131
list_->elems[list_->count].max_speed_angular = max_speed_angular;
32-
list_->elems[list_->count].allow_reverse = allow_reverse;
32+
list_->elems[list_->count].motion_direction = motion_direction;
3333
list_->elems[list_->count].bypass_anti_blocking = bypass_anti_blocking;
3434
list_->elems[list_->count].bypass_final_orientation = bypass_final_orientation;
3535
list_->elems[list_->count].timeout_ms = timeout_ms;
@@ -44,7 +44,7 @@ void PoseOrderList::set(
4444
double angle,
4545
std::uint8_t max_speed_linear,
4646
std::uint8_t max_speed_angular,
47-
bool allow_reverse,
47+
MotionDirection motion_direction,
4848
bool bypass_anti_blocking,
4949
bool bypass_final_orientation,
5050
std::uint32_t timeout_ms,
@@ -58,7 +58,7 @@ void PoseOrderList::set(
5858
list_->elems[index].angle = angle;
5959
list_->elems[index].max_speed_linear = max_speed_linear;
6060
list_->elems[index].max_speed_angular = max_speed_angular;
61-
list_->elems[index].allow_reverse = allow_reverse;
61+
list_->elems[index].motion_direction = motion_direction;
6262
list_->elems[index].bypass_anti_blocking = bypass_anti_blocking;
6363
list_->elems[index].bypass_final_orientation = bypass_final_orientation;
6464
list_->elems[index].timeout_ms = timeout_ms;

cogip/cpp/libraries/models/binding.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ NB_MODULE(models, m) {
2929

3030
m.doc() = "models module for Python bindings";
3131

32+
// Bind MotionDirection enum
33+
nb::enum_<MotionDirection>(m, "MotionDirection", "Motion direction mode for path navigation")
34+
.value("bidirectional", MotionDirection::bidirectional, "Robot can move forward or backward (choose optimal)")
35+
.value("forward_only", MotionDirection::forward_only, "Force forward motion only")
36+
.value("backward_only", MotionDirection::backward_only, "Force backward motion only")
37+
.export_values();
38+
3239
// Bind coords_t structure
3340
nb::class_<coords_t>(m, "CoordsT")
3441
.def_rw("x", &coords_t::x, "X-coordinate")
@@ -204,7 +211,7 @@ NB_MODULE(models, m) {
204211
.def_rw("angle", &pose_order_t::angle, "Orientation angle of the pose in degrees")
205212
.def_rw("max_speed_linear", &pose_order_t::max_speed_linear, "Maximum linear speed for the pose (in percent of the robot max speed)")
206213
.def_rw("max_speed_angular", &pose_order_t::max_speed_angular, "Maximum angular speed for the pose (in percent of the robot max speed)")
207-
.def_rw("allow_reverse", &pose_order_t::allow_reverse, "True if the pose allows reverse movement, false otherwise")
214+
.def_rw("motion_direction", &pose_order_t::motion_direction, "Motion direction mode (bidirectional, forward_only, or backward_only)")
208215
.def_rw("bypass_anti_blocking", &pose_order_t::bypass_anti_blocking, "True if the pose bypasses anti-blocking, false otherwise")
209216
.def_rw("bypass_final_orientation", &pose_order_t::bypass_final_orientation, "True if the pose bypasses final orientation, false otherwise")
210217
.def_rw("timeout_ms", &pose_order_t::timeout_ms, "Timeout in milliseconds for the pose to be reached")
@@ -219,14 +226,14 @@ NB_MODULE(models, m) {
219226
// Bind PoseOrder class
220227
nb::class_<PoseOrder>(m, "PoseOrder")
221228
.def(
222-
nb::init<double, double, double, std::uint8_t, std::uint8_t, bool, bool, bool, std::uint32_t, bool, pose_order_t*>(),
229+
nb::init<double, double, double, std::uint8_t, std::uint8_t, MotionDirection, bool, bool, std::uint32_t, bool, pose_order_t*>(),
223230
"Constructor with initial values",
224231
"x"_a = 0.0,
225232
"y"_a = 0.0,
226233
"angle"_a = 0.0,
227234
"max_speed_linear"_a = 100,
228235
"max_speed_angular"_a = 100,
229-
"allow_reverse"_a = false,
236+
"motion_direction"_a = MotionDirection::bidirectional,
230237
"bypass_anti_blocking"_a = false,
231238
"bypass_final_orientation"_a = false,
232239
"timeout_ms"_a = 0,
@@ -240,7 +247,7 @@ NB_MODULE(models, m) {
240247
.def_prop_rw("angle", &PoseOrder::angle, &PoseOrder::set_angle, "Get or set the orientation angle")
241248
.def_prop_rw("max_speed_linear", &PoseOrder::max_speed_linear, &PoseOrder::set_max_speed_linear, "Get or set the maximum linear speed (in percent of the robot max speed)")
242249
.def_prop_rw("max_speed_angular", &PoseOrder::max_speed_angular, &PoseOrder::set_max_speed_angular, "Get or set the maximum angular speed (in percent of the robot max speed)")
243-
.def_prop_rw("allow_reverse", &PoseOrder::allow_reverse, &PoseOrder::set_allow_reverse, "Get or set if reverse movement is allowed")
250+
.def_prop_rw("motion_direction", &PoseOrder::motion_direction, &PoseOrder::set_motion_direction, "Get or set the motion direction mode")
244251
.def_prop_rw("bypass_anti_blocking", &PoseOrder::bypass_anti_blocking, &PoseOrder::set_bypass_anti_blocking, "Get or set if anti-blocking is bypassed")
245252
.def_prop_rw("bypass_final_orientation", &PoseOrder::bypass_final_orientation, &PoseOrder::set_bypass_final_orientation, "Get or set if final orientation is bypassed")
246253
.def_prop_rw("timeout_ms", &PoseOrder::timeout_ms, &PoseOrder::set_timeout_ms, "Get or set the timeout in milliseconds for the pose to be reached")
@@ -276,27 +283,27 @@ NB_MODULE(models, m) {
276283
.def("max_size", &PoseOrderList::max_size, "Get the maximum number of pose orders")
277284
.def("get", &PoseOrderList::get, "Get PoseOrder at index", "index"_a)
278285
.def("__getitem__", &PoseOrderList::operator[], "Get PoseOrder at index", "index"_a)
279-
.def("append", nb::overload_cast<double, double, double, std::uint8_t, std::uint8_t, bool, bool, bool, std::uint32_t, bool>(&PoseOrderList::append), "Append PoseOrder with initial values",
286+
.def("append", nb::overload_cast<double, double, double, std::uint8_t, std::uint8_t, MotionDirection, bool, bool, std::uint32_t, bool>(&PoseOrderList::append), "Append PoseOrder with initial values",
280287
"x"_a = 0.0,
281288
"y"_a = 0.0,
282289
"angle"_a = 0.0,
283290
"max_speed_linear"_a = 100,
284291
"max_speed_angular"_a = 100,
285-
"allow_reverse"_a = false,
292+
"motion_direction"_a = MotionDirection::bidirectional,
286293
"bypass_anti_blocking"_a = false,
287294
"bypass_final_orientation"_a = false,
288295
"timeout_ms"_a = 0,
289296
"is_intermediate"_a = false
290297
)
291298
.def("append", nb::overload_cast<const PoseOrder&>(&PoseOrderList::append), "Append PoseOrder object", "pose_order"_a)
292-
.def("set", nb::overload_cast<std::size_t, double, double, double, std::uint8_t, std::uint8_t, bool, bool, bool, std::uint32_t, bool>(&PoseOrderList::set), "Set PoseOrder at index",
299+
.def("set", nb::overload_cast<std::size_t, double, double, double, std::uint8_t, std::uint8_t, MotionDirection, bool, bool, std::uint32_t, bool>(&PoseOrderList::set), "Set PoseOrder at index",
293300
"index"_a,
294301
"x"_a = 0.0,
295302
"y"_a = 0.0,
296303
"angle"_a = 0.0,
297304
"max_speed_linear"_a = 100,
298305
"max_speed_angular"_a = 100,
299-
"allow_reverse"_a = false,
306+
"motion_direction"_a = MotionDirection::bidirectional,
300307
"bypass_anti_blocking"_a = false,
301308
"bypass_final_orientation"_a = false,
302309
"timeout_ms"_a = 0,

cogip/cpp/libraries/models/include/models/PoseOrder.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PoseOrder {
3737
double angle=0.0, ///< [in] orientation
3838
std::uint8_t max_speed_linear=66, ///< [in] Maximum linear speed for the pose (in percent of the robot max speed).
3939
std::uint8_t max_speed_angular=66, ///< [in] Maximum linear speed for the pose (in percent of the robot max speed).
40-
bool allow_reverse=true, ///< [in] True if the pose allows reverse movement, false otherwise.
40+
MotionDirection motion_direction=MotionDirection::bidirectional, ///< [in] Motion direction mode.
4141
bool bypass_anti_blocking=false, ///< [in] True if the pose bypasses anti-blocking, false otherwise.
4242
bool bypass_final_orientation=false, ///< [in] True if the pose bypasses final orientation, false otherwise.
4343
std::uint32_t timeout_ms=0, ///< [in] Timeout in milliseconds for the pose to be reached.
@@ -91,13 +91,13 @@ class PoseOrder {
9191
std::uint8_t max_speed_angular ///< [in] new maximum angular speed for the pose (in percent of the robot max speed)
9292
) { data_->max_speed_angular = max_speed_angular; }
9393

94-
/// Return true if the pose allows reverse movement, false otherwise.
95-
bool allow_reverse(void) const { return data_->allow_reverse; }
94+
/// Return motion direction mode.
95+
MotionDirection motion_direction(void) const { return data_->motion_direction; }
9696

97-
/// Set whether the pose allows reverse movement.
98-
void set_allow_reverse(
99-
bool allow_reverse ///< [in] true if the pose allows reverse movement, false otherwise
100-
) { data_->allow_reverse = allow_reverse; }
97+
/// Set motion direction mode.
98+
void set_motion_direction(
99+
MotionDirection motion_dir ///< [in] motion direction mode (bidirectional, forward_only, or backward_only)
100+
) { data_->motion_direction = motion_dir; }
101101

102102
/// Return true if the pose bypasses anti-blocking, false otherwise.
103103
bool bypass_anti_blocking(void) const { return data_->bypass_anti_blocking; }
@@ -148,9 +148,9 @@ inline std::ostream& operator<<(std::ostream& os, PoseOrder data) {
148148
<< "x=" << data.x() << ", "
149149
<< "y=" << data.y() << ", "
150150
<< "angle=" << data.angle() << ", "
151-
<< "max_speed_linear=" << data.max_speed_linear() << ", "
152-
<< "max_speed_angular=" << data.max_speed_angular() << ", "
153-
<< "allow_reverse=" << data.allow_reverse() << ", "
151+
<< "max_speed_linear=" << static_cast<int>(data.max_speed_linear()) << ", "
152+
<< "max_speed_angular=" << static_cast<int>(data.max_speed_angular()) << ", "
153+
<< "motion_direction=" << static_cast<int>(data.motion_direction()) << ", "
154154
<< "bypass_anti_blocking=" << data.bypass_anti_blocking() << ", "
155155
<< "bypass_final_orientation=" << data.bypass_final_orientation() << ", "
156156
<< "timeout_ms=" << data.timeout_ms() << ", "

cogip/cpp/libraries/models/include/models/PoseOrderList.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PoseOrderList: public List<pose_order_t, PoseOrder, pose_order_list_t, POS
2929
double angle = 0.0,
3030
std::uint8_t max_speed_linear = 66,
3131
std::uint8_t max_speed_angular = 66,
32-
bool allow_reverse = true,
32+
MotionDirection motion_direction = MotionDirection::bidirectional,
3333
bool bypass_anti_blocking = false,
3434
bool bypass_final_orientation = false,
3535
std::uint32_t timeout_ms = 0,
@@ -42,7 +42,7 @@ class PoseOrderList: public List<pose_order_t, PoseOrder, pose_order_list_t, POS
4242
elem->angle,
4343
elem->max_speed_linear,
4444
elem->max_speed_angular,
45-
elem->allow_reverse,
45+
elem->motion_direction,
4646
elem->bypass_anti_blocking,
4747
elem->bypass_final_orientation,
4848
elem->timeout_ms,
@@ -56,7 +56,7 @@ class PoseOrderList: public List<pose_order_t, PoseOrder, pose_order_list_t, POS
5656
elem.angle(),
5757
elem.max_speed_linear(),
5858
elem.max_speed_angular(),
59-
elem.allow_reverse(),
59+
elem.motion_direction(),
6060
elem.bypass_anti_blocking(),
6161
elem.bypass_final_orientation(),
6262
elem.timeout_ms(),
@@ -70,7 +70,7 @@ class PoseOrderList: public List<pose_order_t, PoseOrder, pose_order_list_t, POS
7070
double angle = 0.0,
7171
std::uint8_t max_speed_linear = 66,
7272
std::uint8_t max_speed_angular = 66,
73-
bool allow_reverse = true,
73+
MotionDirection motion_direction = MotionDirection::bidirectional,
7474
bool bypass_anti_blocking = false,
7575
bool bypass_final_orientation = false,
7676
std::uint32_t timeout_ms = 0,
@@ -84,7 +84,7 @@ class PoseOrderList: public List<pose_order_t, PoseOrder, pose_order_list_t, POS
8484
elem->angle,
8585
elem->max_speed_linear,
8686
elem->max_speed_angular,
87-
elem->allow_reverse,
87+
elem->motion_direction,
8888
elem->bypass_anti_blocking,
8989
elem->bypass_final_orientation,
9090
elem->timeout_ms,
@@ -99,7 +99,7 @@ class PoseOrderList: public List<pose_order_t, PoseOrder, pose_order_list_t, POS
9999
elem.angle(),
100100
elem.max_speed_linear(),
101101
elem.max_speed_angular(),
102-
elem.allow_reverse(),
102+
elem.motion_direction(),
103103
elem.bypass_anti_blocking(),
104104
elem.bypass_final_orientation(),
105105
elem.timeout_ms(),

cogip/cpp/libraries/models/include/models/pose_order.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ namespace cogip {
1717

1818
namespace models {
1919

20+
/// Motion direction mode for path navigation.
21+
enum class MotionDirection : std::uint8_t {
22+
bidirectional = 0, ///< Robot can move forward or backward (choose optimal)
23+
forward_only = 1, ///< Force forward motion only
24+
backward_only = 2 ///< Force backward motion only
25+
};
26+
2027
/// Represents a pose in 2D space with an orientation.
2128
typedef struct {
2229
double x; ///< X-coordinate of the pose.
2330
double y; ///< Y-coordinate of the pose.
2431
double angle; ///< Orientation angle of the pose in degrees.
2532
std::uint8_t max_speed_linear; ///< Maximum linear speed for the pose (in percent of the robot max speed).
2633
std::uint8_t max_speed_angular; ///< Maximum linear speed for the pose (in percent of the robot max speed).
27-
bool allow_reverse; ///< True if the pose allows reverse movement, false otherwise.
34+
MotionDirection motion_direction; ///< Motion direction mode (bidirectional, forward_only, or backward_only).
2835
bool bypass_anti_blocking; ///< True if the pose bypasses anti-blocking, false otherwise.
2936
bool bypass_final_orientation; ///< True if the pose bypasses final orientation, false otherwise.
3037
std::uint32_t timeout_ms; ///< Timeout in milliseconds for the pose to be reached.
@@ -41,9 +48,9 @@ inline std::ostream& operator<<(std::ostream& os, const pose_order_t& data) {
4148
<< "x=" << data.x << ", "
4249
<< "y=" << data.y << ", "
4350
<< "angle=" << data.angle << ", "
44-
<< "max_speed_linear=" << data.max_speed_linear << ", "
45-
<< "max_speed_angular=" << data.max_speed_angular << ", "
46-
<< "allow_reverse=" << data.allow_reverse << ", "
51+
<< "max_speed_linear=" << static_cast<int>(data.max_speed_linear) << ", "
52+
<< "max_speed_angular=" << static_cast<int>(data.max_speed_angular) << ", "
53+
<< "motion_direction=" << static_cast<int>(data.motion_direction) << ", "
4754
<< "bypass_anti_blocking=" << data.bypass_anti_blocking << ", "
4855
<< "bypass_final_orientation=" << data.bypass_final_orientation << ", "
4956
<< "timeout_ms=" << data.timeout_ms << ", "

cogip/models/models.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import math
11+
from enum import IntEnum
1112

1213
import numpy as np
1314
from numpy.typing import ArrayLike
@@ -18,6 +19,14 @@
1819
from cogip.protobuf import PB_PathPose
1920

2021

22+
class MotionDirection(IntEnum):
23+
"""Motion direction mode for path navigation."""
24+
25+
BIDIRECTIONAL = 0 # Robot can move forward or backward (choose optimal)
26+
FORWARD_ONLY = 1 # Force forward motion only
27+
BACKWARD_ONLY = 2 # Force backward motion only
28+
29+
2130
class MenuEntry(BaseModel):
2231
"""
2332
Represents one entry in a firmware's shell menu
@@ -118,7 +127,7 @@ class PathPose(Pose):
118127
O: 0-orientation
119128
max_speed_linear: max linear speed in percentage of the robot max linear speed
120129
max_speed_angular: max angular speed in percentage of the robot max angular speed
121-
allow_reverse: reverse mode
130+
motion_direction: motion direction mode (bidirectional, forward_only, or backward_only)
122131
bypass_anti_blocking: send pose_reached if robot is blocked
123132
timeout_ms: max time is milliseconds to reach the pose, the robot stops if timeout is reached, 0 for no timeout
124133
bypass_final_orientation: do not set orientation pose order
@@ -127,7 +136,7 @@ class PathPose(Pose):
127136

128137
max_speed_linear: int = 66
129138
max_speed_angular: int = 66
130-
allow_reverse: bool = True
139+
motion_direction: MotionDirection = MotionDirection.BIDIRECTIONAL
131140
bypass_anti_blocking: bool = False
132141
timeout_ms: int = 0
133142
bypass_final_orientation: bool = False
@@ -149,7 +158,7 @@ def copy_pb(self, pb_path_pose: PB_PathPose) -> None:
149158
pb_path_pose.pose.O = int(self.O) # noqa
150159
pb_path_pose.max_speed_ratio_linear = self.max_speed_linear
151160
pb_path_pose.max_speed_ratio_angular = self.max_speed_angular
152-
pb_path_pose.allow_reverse = self.allow_reverse
161+
pb_path_pose.motion_direction = self.motion_direction.value
153162
pb_path_pose.bypass_anti_blocking = self.bypass_anti_blocking
154163
pb_path_pose.timeout_ms = self.timeout_ms
155164
pb_path_pose.bypass_final_orientation = self.bypass_final_orientation
@@ -169,7 +178,7 @@ def to_shared(self, shared_pose_order: SharedPoseOrder | None) -> None:
169178
shared_pose_order.angle = int(self.O) # noqa
170179
shared_pose_order.max_speed_linear = self.max_speed_linear
171180
shared_pose_order.max_speed_angular = self.max_speed_angular
172-
shared_pose_order.allow_reverse = self.allow_reverse
181+
shared_pose_order.motion_direction = self.motion_direction.value
173182
shared_pose_order.bypass_anti_blocking = self.bypass_anti_blocking
174183
shared_pose_order.bypass_final_orientation = self.bypass_final_orientation
175184
shared_pose_order.timeout_ms = self.timeout_ms
@@ -194,7 +203,7 @@ def from_shared(cls, shared_pose: SharedPose | SharedPoseOrder) -> "PathPose":
194203
if isinstance(shared_pose, SharedPoseOrder):
195204
path_pose.max_speed_linear = shared_pose.max_speed_linear
196205
path_pose.max_speed_angular = shared_pose.max_speed_angular
197-
path_pose.allow_reverse = shared_pose.allow_reverse
206+
path_pose.motion_direction = shared_pose.motion_direction
198207
path_pose.bypass_anti_blocking = shared_pose.bypass_anti_blocking
199208
path_pose.timeout_ms = shared_pose.timeout_ms
200209
path_pose.bypass_final_orientation = shared_pose.bypass_final_orientation

0 commit comments

Comments
 (0)