Skip to content

Commit 51f2168

Browse files
author
Vortex
committed
new waypoint mode
1 parent 1a72fa8 commit 51f2168

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

vortex_utils/include/vortex/utils/types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ enum class WaypointMode : uint8_t {
454454
LEVEL_ORIENTATION =
455455
7, ///< Hold current position and yaw; drive roll=pitch=0.
456456
ONLY_Z = 8, ///< Hold current x, y, orientation; control z only.
457+
POS_Z_LEVEL_ORIENTATION =
458+
9, ///< Control z; hold current x, y; drive roll=pitch=0, hold yaw.
457459
};
458460

459461
/**

vortex_utils/src/waypoint_utils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ std::string waypoint_mode_to_string(WaypointMode mode) {
2626
return "LEVEL_ORIENTATION";
2727
case WaypointMode::ONLY_Z:
2828
return "ONLY_Z";
29+
case WaypointMode::POS_Z_LEVEL_ORIENTATION:
30+
return "POS_Z_LEVEL_ORIENTATION";
2931
default:
3032
return "UNKNOWN";
3133
}
@@ -50,6 +52,8 @@ WaypointMode string_to_waypoint_mode(const std::string& str) {
5052
return WaypointMode::LEVEL_ORIENTATION;
5153
if (str == "ONLY_Z" || str == "only_z")
5254
return WaypointMode::ONLY_Z;
55+
if (str == "POS_Z_LEVEL_ORIENTATION" || str == "pos_z_level_orientation")
56+
return WaypointMode::POS_Z_LEVEL_ORIENTATION;
5357
throw std::runtime_error("Unknown WaypointMode string: '" + str + "'");
5458
}
5559

@@ -75,6 +79,8 @@ WaypointMode int_to_waypoint_mode(int value) {
7579
return WaypointMode::LEVEL_ORIENTATION;
7680
case static_cast<int>(WaypointMode::ONLY_Z):
7781
return WaypointMode::ONLY_Z;
82+
case static_cast<int>(WaypointMode::POS_Z_LEVEL_ORIENTATION):
83+
return WaypointMode::POS_Z_LEVEL_ORIENTATION;
7884
default:
7985
throw std::runtime_error("Unknown WaypointMode numeric value: " +
8086
std::to_string(value));
@@ -215,6 +221,16 @@ Pose compute_waypoint_goal(const Pose& incoming_waypoint,
215221
waypoint_out.y = current_state.y;
216222
waypoint_out.set_ori(current_state.ori_quaternion());
217223
break;
224+
225+
case WaypointMode::POS_Z_LEVEL_ORIENTATION: {
226+
waypoint_out.x = current_state.x;
227+
waypoint_out.y = current_state.y;
228+
const double current_yaw = vortex::utils::math::quat_to_euler(
229+
current_state.ori_quaternion())(2);
230+
waypoint_out.set_ori(Eigen::Quaterniond(
231+
Eigen::AngleAxisd(current_yaw, Eigen::Vector3d::UnitZ())));
232+
break;
233+
}
218234
}
219235

220236
return waypoint_out;
@@ -247,6 +263,8 @@ bool has_converged(const Pose& state,
247263
return ea.head<2>().norm();
248264
case WaypointMode::ONLY_Z:
249265
return std::abs(ep(2));
266+
case WaypointMode::POS_Z_LEVEL_ORIENTATION:
267+
return std::sqrt(ep(2) * ep(2) + ea.head<2>().squaredNorm());
250268
case WaypointMode::FULL_POSE:
251269
default:
252270
return std::sqrt(ep.squaredNorm() + ea.squaredNorm());

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ inline WaypointMode waypoint_mode_from_ros(
3535
return WaypointMode::LEVEL_ORIENTATION;
3636
case vortex_msgs::msg::WaypointMode::ONLY_Z:
3737
return WaypointMode::ONLY_Z;
38+
case vortex_msgs::msg::WaypointMode::POS_Z_LEVEL_ORIENTATION:
39+
return WaypointMode::POS_Z_LEVEL_ORIENTATION;
3840
default:
3941
throw std::invalid_argument("Invalid ROS waypoint mode: " +
4042
std::to_string(mode_msg.mode));
@@ -75,6 +77,10 @@ inline vortex_msgs::msg::WaypointMode waypoint_mode_to_ros(
7577
case WaypointMode::ONLY_Z:
7678
ros_mode.mode = vortex_msgs::msg::WaypointMode::ONLY_Z;
7779
break;
80+
case WaypointMode::POS_Z_LEVEL_ORIENTATION:
81+
ros_mode.mode =
82+
vortex_msgs::msg::WaypointMode::POS_Z_LEVEL_ORIENTATION;
83+
break;
7884
}
7985
return ros_mode;
8086
}

0 commit comments

Comments
 (0)