Skip to content

Commit cb7ba7b

Browse files
committed
altitude convergence field + wp modes
1 parent fdba632 commit cb7ba7b

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

vortex_utils/include/vortex/utils/types.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ enum class WaypointMode : uint8_t {
451451
XY_AND_YAW = 5, ///< Control x, y and yaw; hold z, force roll=pitch=0.
452452
XY_FORWARD_DIR =
453453
6, ///< Control x, y; hold z; yaw auto-computed toward target.
454+
LEVEL_ORIENTATION =
455+
7, ///< Hold current position and yaw; drive roll=pitch=0.
456+
ONLY_Z = 8, ///< Hold current x, y, orientation; control z only.
454457
};
455458

456459
/**
@@ -461,6 +464,7 @@ struct Waypoint {
461464
WaypointMode mode = WaypointMode::FULL_POSE;
462465
bool keep_altitude{false};
463466
double desired_altitude{0.0};
467+
bool require_altitude_convergence{false};
464468
};
465469

466470
struct SonarInfo {

vortex_utils/include/vortex/utils/waypoint_utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct WaypointGoal {
1919
double convergence_threshold{0.1};
2020
bool keep_altitude{false};
2121
double desired_altitude{0.0};
22+
bool require_altitude_convergence{false};
2223
};
2324

2425
/**

vortex_utils/src/waypoint_utils.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ WaypointMode string_to_waypoint_mode(const std::string& str) {
2121
return WaypointMode::XY_AND_YAW;
2222
if (str == "XY_FORWARD_DIR" || str == "xy_forward_dir")
2323
return WaypointMode::XY_FORWARD_DIR;
24+
if (str == "LEVEL_ORIENTATION" || str == "level_orientation")
25+
return WaypointMode::LEVEL_ORIENTATION;
26+
if (str == "ONLY_Z" || str == "only_z")
27+
return WaypointMode::ONLY_Z;
2428
throw std::runtime_error("Unknown WaypointMode string: '" + str + "'");
2529
}
2630

@@ -42,6 +46,10 @@ WaypointMode int_to_waypoint_mode(int value) {
4246
return WaypointMode::XY_AND_YAW;
4347
case static_cast<int>(WaypointMode::XY_FORWARD_DIR):
4448
return WaypointMode::XY_FORWARD_DIR;
49+
case static_cast<int>(WaypointMode::LEVEL_ORIENTATION):
50+
return WaypointMode::LEVEL_ORIENTATION;
51+
case static_cast<int>(WaypointMode::ONLY_Z):
52+
return WaypointMode::ONLY_Z;
4553
default:
4654
throw std::runtime_error("Unknown WaypointMode numeric value: " +
4755
std::to_string(value));
@@ -167,6 +175,21 @@ Pose compute_waypoint_goal(const Pose& incoming_waypoint,
167175
Eigen::AngleAxisd(forward_heading, Eigen::Vector3d::UnitZ())));
168176
break;
169177
}
178+
179+
case WaypointMode::LEVEL_ORIENTATION: {
180+
waypoint_out.set_pos(current_state.pos_vector());
181+
const double current_yaw = vortex::utils::math::quat_to_euler(
182+
current_state.ori_quaternion())(2);
183+
waypoint_out.set_ori(Eigen::Quaterniond(
184+
Eigen::AngleAxisd(current_yaw, Eigen::Vector3d::UnitZ())));
185+
break;
186+
}
187+
188+
case WaypointMode::ONLY_Z:
189+
waypoint_out.x = current_state.x;
190+
waypoint_out.y = current_state.y;
191+
waypoint_out.set_ori(current_state.ori_quaternion());
192+
break;
170193
}
171194

172195
return waypoint_out;
@@ -195,6 +218,10 @@ bool has_converged(const Pose& state,
195218
return std::sqrt(ep.head<2>().squaredNorm() + ea(2) * ea(2));
196219
case WaypointMode::XY_FORWARD_DIR:
197220
return ep.head<2>().norm();
221+
case WaypointMode::LEVEL_ORIENTATION:
222+
return ea.head<2>().norm();
223+
case WaypointMode::ONLY_Z:
224+
return std::abs(ep(2));
198225
case WaypointMode::FULL_POSE:
199226
default:
200227
return std::sqrt(ep.squaredNorm() + ea.squaredNorm());
@@ -271,6 +298,7 @@ WaypointGoal load_waypoint_goal_from_yaml(const std::string& file_path,
271298

272299
bool keep_altitude = false;
273300
double desired_altitude = 0.0;
301+
bool require_altitude_convergence = false;
274302
if (wp["keep_altitude"]) {
275303
keep_altitude = wp["keep_altitude"].as<bool>();
276304
}
@@ -281,13 +309,19 @@ WaypointGoal load_waypoint_goal_from_yaml(const std::string& file_path,
281309
"required field 'desired_altitude'");
282310
}
283311
desired_altitude = wp["desired_altitude"].as<double>();
312+
if (wp["require_altitude_convergence"]) {
313+
require_altitude_convergence =
314+
wp["require_altitude_convergence"].as<bool>();
315+
}
284316
}
285317

286318
return WaypointGoal{.pose = pose,
287319
.mode = mode,
288320
.convergence_threshold = convergence_threshold,
289321
.keep_altitude = keep_altitude,
290-
.desired_altitude = desired_altitude};
322+
.desired_altitude = desired_altitude,
323+
.require_altitude_convergence =
324+
require_altitude_convergence};
291325
}
292326

293327
LandmarkConvergenceGoal load_landmark_goal_from_yaml(

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ inline WaypointMode waypoint_mode_from_ros(
3131
return WaypointMode::XY_AND_YAW;
3232
case vortex_msgs::msg::WaypointMode::XY_FORWARD_DIR:
3333
return WaypointMode::XY_FORWARD_DIR;
34+
case vortex_msgs::msg::WaypointMode::LEVEL_ORIENTATION:
35+
return WaypointMode::LEVEL_ORIENTATION;
36+
case vortex_msgs::msg::WaypointMode::ONLY_Z:
37+
return WaypointMode::ONLY_Z;
3438
default:
3539
throw std::invalid_argument("Invalid ROS waypoint mode: " +
3640
std::to_string(mode_msg.mode));
@@ -65,6 +69,12 @@ inline vortex_msgs::msg::WaypointMode waypoint_mode_to_ros(
6569
case WaypointMode::XY_FORWARD_DIR:
6670
ros_mode.mode = vortex_msgs::msg::WaypointMode::XY_FORWARD_DIR;
6771
break;
72+
case WaypointMode::LEVEL_ORIENTATION:
73+
ros_mode.mode = vortex_msgs::msg::WaypointMode::LEVEL_ORIENTATION;
74+
break;
75+
case WaypointMode::ONLY_Z:
76+
ros_mode.mode = vortex_msgs::msg::WaypointMode::ONLY_Z;
77+
break;
6878
}
6979
return ros_mode;
7080
}
@@ -79,6 +89,7 @@ inline vortex::utils::types::Waypoint waypoint_from_ros(
7989
wp.mode = waypoint_mode_from_ros(ros_wp.waypoint_mode);
8090
wp.keep_altitude = ros_wp.keep_altitude;
8191
wp.desired_altitude = ros_wp.desired_altitude;
92+
wp.require_altitude_convergence = ros_wp.require_altitude_convergence;
8293
return wp;
8394
}
8495

0 commit comments

Comments
 (0)