Skip to content

Commit 6123c8f

Browse files
jorgenfjvortexuser
andauthored
waypoint xy forward dir mode (#52)
Co-authored-by: vortexuser <vortex.git@vortexntnu.no>
1 parent 6c576b2 commit 6123c8f

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

vortex_utils/include/vortex/utils/types.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ enum class WaypointMode : uint8_t {
448448
FORWARD_HEADING = 2, ///< Control x, y, z with yaw toward target.
449449
ONLY_ORIENTATION = 3, ///< Control roll, pitch, yaw; hold current position.
450450
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.
451+
XY_AND_YAW = 5, ///< Control x, y and yaw; hold z, force roll=pitch=0.
452+
XY_FORWARD_DIR = 6, ///< Control x, y; hold z; yaw auto-computed toward target.
452453
};
453454

454455
/**

vortex_utils/src/waypoint_utils.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ WaypointMode string_to_waypoint_mode(const std::string& str) {
1919
return WaypointMode::POSITION_AND_YAW;
2020
if (str == "XY_AND_YAW" || str == "xy_and_yaw")
2121
return WaypointMode::XY_AND_YAW;
22+
if (str == "XY_FORWARD_DIR" || str == "xy_forward_dir")
23+
return WaypointMode::XY_FORWARD_DIR;
2224
throw std::runtime_error("Unknown WaypointMode string: '" + str + "'");
2325
}
2426

@@ -38,6 +40,8 @@ WaypointMode int_to_waypoint_mode(int value) {
3840
return WaypointMode::POSITION_AND_YAW;
3941
case static_cast<int>(WaypointMode::XY_AND_YAW):
4042
return WaypointMode::XY_AND_YAW;
43+
case static_cast<int>(WaypointMode::XY_FORWARD_DIR):
44+
return WaypointMode::XY_FORWARD_DIR;
4145
default:
4246
throw std::runtime_error("Unknown WaypointMode numeric value: " +
4347
std::to_string(value));
@@ -63,7 +67,8 @@ Pose load_pose_for_mode(const YAML::Node& node, WaypointMode mode) { //
6367
mode == WaypointMode::ONLY_POSITION ||
6468
mode == WaypointMode::FORWARD_HEADING ||
6569
mode == WaypointMode::POSITION_AND_YAW ||
66-
mode == WaypointMode::XY_AND_YAW);
70+
mode == WaypointMode::XY_AND_YAW ||
71+
mode == WaypointMode::XY_FORWARD_DIR);
6772
const bool needs_orientation = (mode == WaypointMode::FULL_POSE ||
6873
mode == WaypointMode::ONLY_ORIENTATION ||
6974
mode == WaypointMode::POSITION_AND_YAW ||
@@ -152,6 +157,16 @@ Pose compute_waypoint_goal(const Pose& incoming_waypoint,
152157
Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ())));
153158
break;
154159
}
160+
161+
case WaypointMode::XY_FORWARD_DIR: {
162+
waypoint_out.z = current_state.z;
163+
const double dx = incoming_waypoint.x - current_state.x;
164+
const double dy = incoming_waypoint.y - current_state.y;
165+
const double forward_heading = std::atan2(dy, dx);
166+
waypoint_out.set_ori(Eigen::Quaterniond(
167+
Eigen::AngleAxisd(forward_heading, Eigen::Vector3d::UnitZ())));
168+
break;
169+
}
155170
}
156171

157172
return waypoint_out;
@@ -178,6 +193,8 @@ bool has_converged(const Pose& state,
178193
return std::sqrt(ep.squaredNorm() + ea(2) * ea(2));
179194
case WaypointMode::XY_AND_YAW:
180195
return std::sqrt(ep.head<2>().squaredNorm() + ea(2) * ea(2));
196+
case WaypointMode::XY_FORWARD_DIR:
197+
return ep.head<2>().norm();
181198
case WaypointMode::FULL_POSE:
182199
default:
183200
return std::sqrt(ep.squaredNorm() + ea.squaredNorm());

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ inline WaypointMode waypoint_mode_from_ros(
2929
return WaypointMode::POSITION_AND_YAW;
3030
case vortex_msgs::msg::WaypointMode::XY_AND_YAW:
3131
return WaypointMode::XY_AND_YAW;
32+
case vortex_msgs::msg::WaypointMode::XY_FORWARD_DIR:
33+
return WaypointMode::XY_FORWARD_DIR;
3234
default:
3335
throw std::invalid_argument("Invalid ROS waypoint mode: " +
3436
std::to_string(mode_msg.mode));
@@ -60,6 +62,9 @@ inline vortex_msgs::msg::WaypointMode waypoint_mode_to_ros(
6062
case WaypointMode::XY_AND_YAW:
6163
ros_mode.mode = vortex_msgs::msg::WaypointMode::XY_AND_YAW;
6264
break;
65+
case WaypointMode::XY_FORWARD_DIR:
66+
ros_mode.mode = vortex_msgs::msg::WaypointMode::XY_FORWARD_DIR;
67+
break;
6368
}
6469
return ros_mode;
6570
}

0 commit comments

Comments
 (0)