Skip to content

Commit 55131a9

Browse files
committed
Refactor: To use the new vortex msg type for action server
1 parent 4b7f65e commit 55131a9

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

guidance/los_guidance/include/los_guidance/los_guidance_ros.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <rclcpp/rclcpp.hpp>
1515
#include <rclcpp_action/rclcpp_action.hpp>
1616
#include <vortex/utils/math.hpp>
17-
#include <vortex_msgs/action/los_guidance.hpp>
17+
#include <vortex_msgs/action/set_waypoint.hpp>
1818
#include <vortex_msgs/msg/detail/los_guidance__struct.hpp>
1919
#include <vortex_msgs/msg/los_guidance.hpp>
2020
#include <vortex_msgs/msg/pose_euler_stamped.hpp>
@@ -139,7 +139,7 @@ class LosGuidanceNode : public rclcpp::Node {
139139
*/
140140
rclcpp_action::GoalResponse handle_goal(
141141
const rclcpp_action::GoalUUID& uuid,
142-
std::shared_ptr<const vortex_msgs::action::LOSGuidance::Goal> goal);
142+
std::shared_ptr<const vortex_msgs::action::SetWaypoint::Goal> goal);
143143

144144
/**
145145
* @brief Handles cancellation of an active LOS guidance goal.
@@ -149,22 +149,22 @@ class LosGuidanceNode : public rclcpp::Node {
149149
*/
150150
rclcpp_action::CancelResponse handle_cancel(
151151
const std::shared_ptr<
152-
rclcpp_action::ServerGoalHandle<vortex_msgs::action::LOSGuidance>>
152+
rclcpp_action::ServerGoalHandle<vortex_msgs::action::SetWaypoint>>
153153
goal_handle);
154154

155155
/**
156156
* @brief Handles an accepted LOS guidance goal.
157157
* @param goal_handle Handle to the accepted goal.
158158
*/
159159
void handle_accepted(const std::shared_ptr<rclcpp_action::ServerGoalHandle<
160-
vortex_msgs::action::LOSGuidance>> goal_handle);
160+
vortex_msgs::action::SetWaypoint>> goal_handle);
161161

162162
/**
163163
* @brief Executes the LOS guidance action.
164164
* @param goal_handle Handle to the active LOS guidance goal.
165165
*/
166166
void execute(const std::shared_ptr<rclcpp_action::ServerGoalHandle<
167-
vortex_msgs::action::LOSGuidance>> goal_handle);
167+
vortex_msgs::action::SetWaypoint>> goal_handle);
168168

169169
/**
170170
* @brief Service callback for changing the active LOS guidance method.
@@ -202,7 +202,7 @@ class LosGuidanceNode : public rclcpp::Node {
202202
*/
203203
bool is_goal_feasible(
204204
const types::Inputs& inputs,
205-
std::shared_ptr<const vortex_msgs::action::LOSGuidance::Goal> goal);
205+
std::shared_ptr<const vortex_msgs::action::SetWaypoint::Goal> goal);
206206

207207
/**
208208
* @brief Checks if the LOS guidance goal has been missed based on the
@@ -214,7 +214,7 @@ class LosGuidanceNode : public rclcpp::Node {
214214

215215
bool has_active_segment_{false};
216216

217-
rclcpp_action::Server<vortex_msgs::action::LOSGuidance>::SharedPtr
217+
rclcpp_action::Server<vortex_msgs::action::SetWaypoint>::SharedPtr
218218
action_server_;
219219
rclcpp::Service<vortex_msgs::srv::SetLosMode>::SharedPtr los_mode_service_;
220220
rclcpp::Publisher<vortex_msgs::msg::LOSGuidance>::SharedPtr reference_pub_;
@@ -236,7 +236,7 @@ class LosGuidanceNode : public rclcpp::Node {
236236

237237
rclcpp_action::GoalUUID preempted_goal_id_;
238238
std::shared_ptr<
239-
rclcpp_action::ServerGoalHandle<vortex_msgs::action::LOSGuidance>>
239+
rclcpp_action::ServerGoalHandle<vortex_msgs::action::SetWaypoint>>
240240
goal_handle_;
241241

242242
types::Inputs path_inputs_{};

guidance/los_guidance/src/los_guidance_ros.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <eigen3/Eigen/src/Geometry/Quaternion.h>
33
#include <spdlog/spdlog.h>
44
#include <yaml-cpp/node/node.h>
5+
#include <geometry_msgs/msg/detail/point_stamped__struct.hpp>
56
#include <rclcpp_components/register_node_macro.hpp>
67
#include <vortex/utils/math.hpp>
78
#include <vortex/utils/ros/qos_profiles.hpp>
@@ -106,7 +107,7 @@ void LosGuidanceNode::set_action_server() {
106107
this->create_callback_group(rclcpp::CallbackGroupType::Reentrant);
107108

108109
action_server_ =
109-
rclcpp_action::create_server<vortex_msgs::action::LOSGuidance>(
110+
rclcpp_action::create_server<vortex_msgs::action::SetWaypoint>(
110111
this, action_server_name,
111112
std::bind(&LosGuidanceNode::handle_goal, this,
112113
std::placeholders::_1, std::placeholders::_2),
@@ -258,7 +259,7 @@ void LosGuidanceNode::odom_msg_callback(
258259

259260
rclcpp_action::GoalResponse LosGuidanceNode::handle_goal(
260261
const rclcpp_action::GoalUUID&,
261-
std::shared_ptr<const vortex_msgs::action::LOSGuidance::Goal> goal) {
262+
std::shared_ptr<const vortex_msgs::action::SetWaypoint::Goal> goal) {
262263
types::Inputs inputs_copy;
263264

264265
{
@@ -290,7 +291,7 @@ rclcpp_action::GoalResponse LosGuidanceNode::handle_goal(
290291

291292
rclcpp_action::CancelResponse LosGuidanceNode::handle_cancel(
292293
const std::shared_ptr<
293-
rclcpp_action::ServerGoalHandle<vortex_msgs::action::LOSGuidance>>
294+
rclcpp_action::ServerGoalHandle<vortex_msgs::action::SetWaypoint>>
294295
goal_handle) {
295296
spdlog::info("Received request to cancel goal");
296297
(void)goal_handle;
@@ -299,7 +300,7 @@ rclcpp_action::CancelResponse LosGuidanceNode::handle_cancel(
299300

300301
void LosGuidanceNode::handle_accepted(
301302
const std::shared_ptr<
302-
rclcpp_action::ServerGoalHandle<vortex_msgs::action::LOSGuidance>>
303+
rclcpp_action::ServerGoalHandle<vortex_msgs::action::SetWaypoint>>
303304
goal_handle) {
304305
std::thread{[this, goal_handle]() { execute(goal_handle); }}.detach();
305306
}
@@ -352,9 +353,9 @@ vortex_msgs::msg::LOSGuidance LosGuidanceNode::fill_los_reference(
352353

353354
bool LosGuidanceNode::is_goal_feasible(
354355
const types::Inputs& inputs,
355-
std::shared_ptr<const vortex_msgs::action::LOSGuidance::Goal> goal) {
356+
std::shared_ptr<const vortex_msgs::action::SetWaypoint::Goal> goal) {
356357
const auto& current_position = inputs.current_position;
357-
const auto& goal_point = goal->goal.point;
358+
const auto& goal_point = goal->waypoint.pose.position;
358359

359360
const double dx = goal_point.x - current_position.x;
360361
const double dy = goal_point.y - current_position.y;
@@ -422,7 +423,7 @@ void LosGuidanceNode::parse_common_config(YAML::Node common_config) {
422423

423424
void LosGuidanceNode::execute(
424425
const std::shared_ptr<
425-
rclcpp_action::ServerGoalHandle<vortex_msgs::action::LOSGuidance>>
426+
rclcpp_action::ServerGoalHandle<vortex_msgs::action::SetWaypoint>>
426427
goal_handle) {
427428
{
428429
std::unique_lock<std::mutex> lock(mutex_);
@@ -432,10 +433,10 @@ void LosGuidanceNode::execute(
432433

433434
spdlog::info("Executing goal");
434435

435-
const geometry_msgs::msg::PointStamped los_waypoint =
436-
goal_handle->get_goal()->goal;
436+
const geometry_msgs::msg::Point los_waypoint =
437+
goal_handle->get_goal()->waypoint.pose.position;
437438

438-
const auto new_wp = types::Point::point_from_ros(los_waypoint.point);
439+
const auto new_wp = types::Point::point_from_ros(los_waypoint);
439440

440441
{
441442
std::unique_lock<std::mutex> lock(mutex_);
@@ -452,7 +453,7 @@ void LosGuidanceNode::execute(
452453

453454
adaptive_los_->reset();
454455

455-
auto result = std::make_shared<vortex_msgs::action::LOSGuidance::Result>();
456+
auto result = std::make_shared<vortex_msgs::action::SetWaypoint::Result>();
456457
nearest_been_to_goal_ = std::numeric_limits<double>::infinity();
457458
time_since_nearest_goal_ = 0.0;
458459

0 commit comments

Comments
 (0)