@@ -15,6 +15,10 @@ WaypointMode string_to_waypoint_mode(const std::string& str) {
1515 return WaypointMode::FORWARD_HEADING ;
1616 if (str == " ONLY_ORIENTATION" || str == " only_orientation" )
1717 return WaypointMode::ONLY_ORIENTATION ;
18+ if (str == " POSITION_AND_YAW" || str == " position_and_yaw" )
19+ return WaypointMode::POSITION_AND_YAW ;
20+ if (str == " XY_AND_YAW" || str == " xy_and_yaw" )
21+ return WaypointMode::XY_AND_YAW ;
1822 throw std::runtime_error (" Unknown WaypointMode string: '" + str + " '" );
1923}
2024
@@ -32,14 +36,18 @@ WaypointMode load_mode(const YAML::Node& node) {
3236 }
3337}
3438
35- Pose load_pose_for_mode (const YAML ::Node& node, WaypointMode mode) { //
39+ Pose load_pose_for_mode (const YAML ::Node& node, WaypointMode mode) { //
3640 Pose pose; // defaults: x=y=z=0, qw=1, qx=qy=qz=0
3741
3842 const bool needs_position = (mode == WaypointMode::FULL_POSE ||
3943 mode == WaypointMode::ONLY_POSITION ||
40- mode == WaypointMode::FORWARD_HEADING );
44+ mode == WaypointMode::FORWARD_HEADING ||
45+ mode == WaypointMode::POSITION_AND_YAW ||
46+ mode == WaypointMode::XY_AND_YAW );
4147 const bool needs_orientation = (mode == WaypointMode::FULL_POSE ||
42- mode == WaypointMode::ONLY_ORIENTATION );
48+ mode == WaypointMode::ONLY_ORIENTATION ||
49+ mode == WaypointMode::POSITION_AND_YAW ||
50+ mode == WaypointMode::XY_AND_YAW );
4351
4452 if (needs_position) {
4553 pose.x = node[" position" ][" x" ].as <double >();
@@ -48,10 +56,16 @@ Pose load_pose_for_mode(const YAML::Node& node, WaypointMode mode) { //
4856 }
4957
5058 if (needs_orientation) {
59+ const bool force_level = (mode == WaypointMode::POSITION_AND_YAW ||
60+ mode == WaypointMode::XY_AND_YAW );
5161 const double roll =
52- node[" orientation" ][" roll" ].as <double >() * (M_PI / 180.0 );
62+ force_level
63+ ? 0.0
64+ : node[" orientation" ][" roll" ].as <double >() * (M_PI / 180.0 );
5365 const double pitch =
54- node[" orientation" ][" pitch" ].as <double >() * (M_PI / 180.0 );
66+ force_level
67+ ? 0.0
68+ : node[" orientation" ][" pitch" ].as <double >() * (M_PI / 180.0 );
5569 const double yaw =
5670 node[" orientation" ][" yaw" ].as <double >() * (M_PI / 180.0 );
5771 const Eigen::Quaterniond q =
@@ -93,6 +107,31 @@ Pose compute_waypoint_goal(const Pose& incoming_waypoint,
93107 case WaypointMode::ONLY_ORIENTATION :
94108 waypoint_out.set_pos (current_state.pos_vector ());
95109 break ;
110+
111+ case WaypointMode::POSITION_AND_YAW : {
112+ const double raw_yaw = vortex::utils::math::quat_to_euler (
113+ incoming_waypoint.ori_quaternion ())(2 );
114+ const double current_yaw = vortex::utils::math::quat_to_euler (
115+ current_state.ori_quaternion ())(2 );
116+ const double yaw =
117+ current_yaw + vortex::utils::math::ssa (raw_yaw - current_yaw);
118+ waypoint_out.set_ori (Eigen::Quaterniond (
119+ Eigen::AngleAxisd (yaw, Eigen::Vector3d::UnitZ ())));
120+ break ;
121+ }
122+
123+ case WaypointMode::XY_AND_YAW : {
124+ waypoint_out.z = current_state.z ;
125+ const double raw_yaw = vortex::utils::math::quat_to_euler (
126+ incoming_waypoint.ori_quaternion ())(2 );
127+ const double current_yaw = vortex::utils::math::quat_to_euler (
128+ current_state.ori_quaternion ())(2 );
129+ const double yaw =
130+ current_yaw + vortex::utils::math::ssa (raw_yaw - current_yaw);
131+ waypoint_out.set_ori (Eigen::Quaterniond (
132+ Eigen::AngleAxisd (yaw, Eigen::Vector3d::UnitZ ())));
133+ break ;
134+ }
96135 }
97136
98137 return waypoint_out;
@@ -115,6 +154,10 @@ bool has_converged(const Pose& state,
115154 return ea.norm ();
116155 case WaypointMode::FORWARD_HEADING :
117156 return std::sqrt (ep.squaredNorm () + ea (2 ) * ea (2 ));
157+ case WaypointMode::POSITION_AND_YAW :
158+ return std::sqrt (ep.squaredNorm () + ea (2 ) * ea (2 ));
159+ case WaypointMode::XY_AND_YAW :
160+ return std::sqrt (ep.head <2 >().squaredNorm () + ea (2 ) * ea (2 ));
118161 case WaypointMode::FULL_POSE :
119162 default :
120163 return std::sqrt (ep.squaredNorm () + ea.squaredNorm ());
@@ -138,7 +181,7 @@ Pose apply_pose_offset(const Pose& base, const Pose& offset) {
138181}
139182
140183Pose load_pose_from_yaml (const std::string& file_path,
141- const std::string& identifier) { //
184+ const std::string& identifier) { //
142185 YAML ::Node root = YAML::LoadFile (file_path);
143186
144187 if (!root[identifier]) {
@@ -152,12 +195,11 @@ Pose load_pose_from_yaml(const std::string& file_path,
152195 const double y = pose[" position" ][" y" ].as <double >();
153196 const double z = pose[" position" ][" z" ].as <double >();
154197
155- const double roll = pose[" orientation" ][" roll" ].as <double >() *
156- (M_PI / 180.0 );
157- const double pitch = pose[" orientation" ][" pitch" ].as <double >() *
158- (M_PI / 180.0 );
159- const double yaw = pose[" orientation" ][" yaw" ].as <double >() *
160- (M_PI / 180.0 );
198+ const double roll =
199+ pose[" orientation" ][" roll" ].as <double >() * (M_PI / 180.0 );
200+ const double pitch =
201+ pose[" orientation" ][" pitch" ].as <double >() * (M_PI / 180.0 );
202+ const double yaw = pose[" orientation" ][" yaw" ].as <double >() * (M_PI / 180.0 );
161203
162204 const Eigen::Quaterniond q =
163205 vortex::utils::math::euler_to_quat (roll, pitch, yaw);
0 commit comments