66
77namespace vortex ::utils::waypoints {
88
9+ WaypointMode string_to_waypoint_mode (const std::string& str) {
10+ if (str == " FULL_POSE" || str == " full_pose" )
11+ return WaypointMode::FULL_POSE ;
12+ if (str == " ONLY_POSITION" || str == " only_position" )
13+ return WaypointMode::ONLY_POSITION ;
14+ if (str == " FORWARD_HEADING" || str == " forward_heading" )
15+ return WaypointMode::FORWARD_HEADING ;
16+ if (str == " ONLY_ORIENTATION" || str == " only_orientation" )
17+ return WaypointMode::ONLY_ORIENTATION ;
18+ throw std::runtime_error (" Unknown WaypointMode string: '" + str + " '" );
19+ }
20+
21+ namespace {
22+
23+ WaypointMode load_mode (const YAML ::Node& node) {
24+ const auto & m = node[" mode" ];
25+ if (!m) {
26+ throw std::runtime_error (" Missing required field 'mode'" );
27+ }
28+ try {
29+ return static_cast <WaypointMode>(m.as <uint8_t >());
30+ } catch (const YAML ::BadConversion&) {
31+ return string_to_waypoint_mode (m.as <std::string>());
32+ }
33+ }
34+
35+ Pose load_pose_for_mode (const YAML ::Node& node, WaypointMode mode) {
36+ Pose pose; // defaults: x=y=z=0, qw=1, qx=qy=qz=0
37+
38+ const bool needs_position = (mode == WaypointMode::FULL_POSE ||
39+ mode == WaypointMode::ONLY_POSITION ||
40+ mode == WaypointMode::FORWARD_HEADING );
41+ const bool needs_orientation = (mode == WaypointMode::FULL_POSE ||
42+ mode == WaypointMode::ONLY_ORIENTATION );
43+
44+ if (needs_position) {
45+ pose.x = node[" position" ][" x" ].as <double >();
46+ pose.y = node[" position" ][" y" ].as <double >();
47+ pose.z = node[" position" ][" z" ].as <double >();
48+ }
49+
50+ if (needs_orientation) {
51+ const double roll = node[" orientation" ][" roll" ].as <double >();
52+ const double pitch = node[" orientation" ][" pitch" ].as <double >();
53+ const double yaw = node[" orientation" ][" yaw" ].as <double >();
54+ const Eigen::Quaterniond q =
55+ vortex::utils::math::euler_to_quat (roll, pitch, yaw);
56+ pose.qw = q.w ();
57+ pose.qx = q.x ();
58+ pose.qy = q.y ();
59+ pose.qz = q.z ();
60+ }
61+
62+ return pose;
63+ }
64+
65+ } // namespace
66+
967Pose compute_waypoint_goal (const Pose& incoming_waypoint,
1068 WaypointMode mode,
1169 const Pose& current_state) {
@@ -118,9 +176,8 @@ WaypointGoal load_waypoint_goal_from_yaml(const std::string& file_path,
118176
119177 const auto & wp = root[identifier];
120178
121- Pose pose = load_pose_from_yaml (file_path, identifier);
122-
123- const auto mode = static_cast <WaypointMode>(wp[" mode" ].as <uint8_t >());
179+ const auto mode = load_mode (wp);
180+ const Pose pose = load_pose_for_mode (wp, mode);
124181
125182 double convergence_threshold = 0.1 ;
126183 if (wp[" convergence_threshold" ]) {
@@ -144,9 +201,8 @@ LandmarkConvergenceGoal load_landmark_goal_from_yaml(
144201
145202 const auto & entry = root[identifier];
146203
147- Pose convergence_offset = load_pose_from_yaml (file_path, identifier);
148-
149- const auto mode = static_cast <WaypointMode>(entry[" mode" ].as <uint8_t >());
204+ const auto mode = load_mode (entry);
205+ const Pose convergence_offset = load_pose_for_mode (entry, mode);
150206
151207 double convergence_threshold = 0.1 ;
152208 if (entry[" convergence_threshold" ]) {
0 commit comments