Skip to content

Commit c4e7004

Browse files
jorgenfjvortexuser
andauthored
new waypoint modes (#51)
Co-authored-by: vortexuser <vortex.git@vortexntnu.no>
1 parent 0e38e57 commit c4e7004

3 files changed

Lines changed: 66 additions & 12 deletions

File tree

vortex_utils/include/vortex/utils/types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ enum class WaypointMode : uint8_t {
447447
ONLY_POSITION = 1, ///< Control x, y, z; hold current orientation.
448448
FORWARD_HEADING = 2, ///< Control x, y, z with yaw toward target.
449449
ONLY_ORIENTATION = 3, ///< Control roll, pitch, yaw; hold current position.
450+
POSITION_AND_YAW = 4, ///< Control x, y, z and yaw; force roll=pitch=0.
451+
XY_AND_YAW = 5, ///< Control x, y and yaw; hold z, force roll=pitch=0.
450452
};
451453

452454
/**

vortex_utils/src/waypoint_utils.cpp

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

140183
Pose 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);

vortex_utils_ros/include/vortex/utils/ros/waypoint_ros_conversions.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ inline WaypointMode waypoint_mode_from_ros(
2525
return WaypointMode::FORWARD_HEADING;
2626
case vortex_msgs::msg::WaypointMode::ONLY_ORIENTATION:
2727
return WaypointMode::ONLY_ORIENTATION;
28+
case vortex_msgs::msg::WaypointMode::POSITION_AND_YAW:
29+
return WaypointMode::POSITION_AND_YAW;
30+
case vortex_msgs::msg::WaypointMode::XY_AND_YAW:
31+
return WaypointMode::XY_AND_YAW;
2832
default:
2933
throw std::invalid_argument("Invalid ROS waypoint mode: " +
3034
std::to_string(mode_msg.mode));
@@ -50,6 +54,12 @@ inline vortex_msgs::msg::WaypointMode waypoint_mode_to_ros(
5054
case WaypointMode::ONLY_ORIENTATION:
5155
ros_mode.mode = vortex_msgs::msg::WaypointMode::ONLY_ORIENTATION;
5256
break;
57+
case WaypointMode::POSITION_AND_YAW:
58+
ros_mode.mode = vortex_msgs::msg::WaypointMode::POSITION_AND_YAW;
59+
break;
60+
case WaypointMode::XY_AND_YAW:
61+
ros_mode.mode = vortex_msgs::msg::WaypointMode::XY_AND_YAW;
62+
break;
5363
}
5464
return ros_mode;
5565
}

0 commit comments

Comments
 (0)