Skip to content

Commit b064f9f

Browse files
committed
Merge branch 'main' into dp-quaternion-control
2 parents 9960a72 + 5dce04d commit b064f9f

21 files changed

Lines changed: 809 additions & 122 deletions

File tree

auv_setup/config/robots/orca.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
twist: "twist"
124124
operation_mode: "operation_mode"
125125
killswitch: "killswitch"
126-
aruco_board_pose_camera: "aruco_board_pose_camera"
126+
reference_pose: "reference_pose"
127127
waypoint: "waypoint"
128128
waypoint_list: "waypoint_list"
129129
guidance:

guidance/reference_filter_dp/include/reference_filter_dp/reference_filter_ros.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class ReferenceFilterNode : public rclcpp::Node {
7878

7979
Eigen::Vector6d apply_mode_logic(const Eigen::Vector6d& r_in, uint8_t mode);
8080

81+
void publish_hold_reference();
82+
8183
vortex_msgs::msg::ReferenceFilter fill_reference_msg();
8284

8385
rclcpp_action::Server<

guidance/reference_filter_dp/src/reference_filter_ros.cpp

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "reference_filter_dp/reference_filter_ros.hpp"
22
#include <spdlog/spdlog.h>
3+
#include <mutex>
34
#include <rclcpp_components/register_node_macro.hpp>
45
#include <string_view>
56
#include <vortex/utils/math.hpp>
@@ -34,20 +35,20 @@ void ReferenceFilterNode::set_subscribers_and_publisher() {
3435
this->declare_parameter<std::string>("topics.pose");
3536
this->declare_parameter<std::string>("topics.twist");
3637
this->declare_parameter<std::string>("topics.guidance.dp");
37-
this->declare_parameter<std::string>("topics.aruco_board_pose_camera");
38+
this->declare_parameter<std::string>("topics.reference_pose");
3839

3940
std::string pose_topic = this->get_parameter("topics.pose").as_string();
4041
std::string twist_topic = this->get_parameter("topics.twist").as_string();
4142
std::string guidance_topic =
4243
this->get_parameter("topics.guidance.dp").as_string();
43-
std::string aruco_board_pose_camera_topic =
44-
this->get_parameter("topics.aruco_board_pose_camera").as_string();
44+
std::string reference_pose_topic =
45+
this->get_parameter("topics.reference_pose").as_string();
4546

4647
auto qos_sensor_data = vortex::utils::qos_profiles::sensor_data_profile(1);
4748
reference_pub_ = this->create_publisher<vortex_msgs::msg::ReferenceFilter>(
4849
guidance_topic, qos_sensor_data);
4950
reference_sub_ = this->create_subscription<geometry_msgs::msg::PoseStamped>(
50-
aruco_board_pose_camera_topic, qos_sensor_data,
51+
reference_pose_topic, qos_sensor_data,
5152
std::bind(&ReferenceFilterNode::reference_callback, this,
5253
std::placeholders::_1));
5354
pose_sub_ = this->create_subscription<
@@ -111,11 +112,13 @@ void ReferenceFilterNode::reference_callback(
111112

112113
void ReferenceFilterNode::pose_callback(
113114
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg) {
115+
std::lock_guard<std::mutex> lock(mutex_);
114116
current_pose_ = *msg;
115117
}
116118

117119
void ReferenceFilterNode::twist_callback(
118120
const geometry_msgs::msg::TwistWithCovarianceStamped::SharedPtr msg) {
121+
std::lock_guard<std::mutex> lock(mutex_);
119122
current_twist_ = *msg;
120123
}
121124

@@ -268,6 +271,41 @@ Eigen::Vector6d ReferenceFilterNode::apply_mode_logic(
268271
return r_out;
269272
}
270273

274+
void ReferenceFilterNode::publish_hold_reference() {
275+
if (!reference_pub_) {
276+
return;
277+
}
278+
279+
const auto& p = current_pose_.pose.pose.position;
280+
const auto& o = current_pose_.pose.pose.orientation;
281+
282+
Eigen::Quaterniond q(o.w, o.x, o.y, o.z);
283+
if (q.norm() < 1e-9) {
284+
q = Eigen::Quaterniond::Identity();
285+
} else {
286+
q.normalize();
287+
}
288+
289+
Eigen::Vector3d euler_angles = vortex::utils::math::quat_to_euler(q);
290+
291+
vortex_msgs::msg::ReferenceFilter hold_msg;
292+
hold_msg.x = p.x;
293+
hold_msg.y = p.y;
294+
hold_msg.z = p.z;
295+
hold_msg.roll = vortex::utils::math::ssa(euler_angles(0));
296+
hold_msg.pitch = vortex::utils::math::ssa(euler_angles(1));
297+
hold_msg.yaw = vortex::utils::math::ssa(euler_angles(2));
298+
299+
hold_msg.x_dot = 0.0;
300+
hold_msg.y_dot = 0.0;
301+
hold_msg.z_dot = 0.0;
302+
hold_msg.roll_dot = 0.0;
303+
hold_msg.pitch_dot = 0.0;
304+
hold_msg.yaw_dot = 0.0;
305+
306+
reference_pub_->publish(hold_msg);
307+
}
308+
271309
void ReferenceFilterNode::execute(
272310
const std::shared_ptr<rclcpp_action::ServerGoalHandle<
273311
vortex_msgs::action::ReferenceFilterWaypoint>> goal_handle) {
@@ -307,16 +345,21 @@ void ReferenceFilterNode::execute(
307345
{
308346
std::lock_guard<std::mutex> lock(mutex_);
309347
if (goal_handle->get_goal_id() == preempted_goal_id_) {
348+
publish_hold_reference();
310349
result->success = false;
311350
goal_handle->abort(result);
312351
return;
313352
}
314353
}
315-
if (goal_handle->is_canceling()) {
316-
result->success = false;
317-
goal_handle->canceled(result);
318-
spdlog::info("Goal canceled");
319-
return;
354+
{
355+
std::lock_guard<std::mutex> lock(mutex_);
356+
if (goal_handle->is_canceling()) {
357+
publish_hold_reference();
358+
result->success = false;
359+
goal_handle->canceled(result);
360+
spdlog::info("Goal canceled");
361+
return;
362+
}
320363
}
321364
Eigen::Vector18d x_dot = reference_filter_->calculate_x_dot(x_, r_);
322365
x_ += x_dot * time_step_.count() / 1000.0;

mission/FSM/docking/COLCON_IGNORE

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef DOCKING__DOCKING_HPP_
22
#define DOCKING__DOCKING_HPP_
33

4-
#include <chrono>
5-
#include <iostream>
64
#include <memory>
75
#include <string>
86

@@ -38,112 +36,108 @@ using ReturnHomeAction = vortex_msgs::action::ReferenceFilterWaypoint;
3836
class FindDockingStationState
3937
: public yasmin_ros::ActionState<docking_fsm::FindDockingAction> {
4038
public:
41-
FindDockingStationState(
42-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
39+
explicit FindDockingStationState(
40+
std::shared_ptr<yasmin::Blackboard> blackboard);
4341

4442
docking_fsm::FindDockingAction::Goal create_goal_handler(
45-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
43+
std::shared_ptr<yasmin::Blackboard> blackboard);
4644

4745
std::string response_handler(
48-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
46+
std::shared_ptr<yasmin::Blackboard> blackboard,
4947
docking_fsm::FindDockingAction::Result::SharedPtr response);
5048

5149
void print_feedback(
52-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
50+
std::shared_ptr<yasmin::Blackboard> blackboard,
5351
std::shared_ptr<const docking_fsm::FindDockingAction::Feedback>
5452
feedback);
5553
};
5654

5755
class ApproachDockingStationState
5856
: public yasmin_ros::ActionState<docking_fsm::ApproachDockingAction> {
5957
public:
60-
ApproachDockingStationState(
61-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
58+
explicit ApproachDockingStationState(
59+
std::shared_ptr<yasmin::Blackboard> blackboard);
6260

6361
docking_fsm::ApproachDockingAction::Goal create_goal_handler(
64-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
62+
std::shared_ptr<yasmin::Blackboard> blackboard);
6563

6664
std::string response_handler(
67-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
65+
std::shared_ptr<yasmin::Blackboard> blackboard,
6866
docking_fsm::ApproachDockingAction::Result::SharedPtr response);
6967

7068
void print_feedback(
71-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
69+
std::shared_ptr<yasmin::Blackboard> blackboard,
7270
std::shared_ptr<const docking_fsm::ApproachDockingAction::Feedback>
7371
feedback);
7472
};
7573

7674
class GoAboveDockingStationState
7775
: public yasmin_ros::ActionState<docking_fsm::GoAboveDockingAction> {
7876
public:
79-
GoAboveDockingStationState(
80-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
77+
explicit GoAboveDockingStationState(
78+
std::shared_ptr<yasmin::Blackboard> blackboard);
8179

8280
docking_fsm::GoAboveDockingAction::Goal create_goal_handler(
83-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
81+
std::shared_ptr<yasmin::Blackboard> blackboard);
8482

8583
std::string response_handler(
86-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
84+
std::shared_ptr<yasmin::Blackboard> blackboard,
8785
docking_fsm::GoAboveDockingAction::Result::SharedPtr response);
8886

8987
void print_feedback(
90-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
88+
std::shared_ptr<yasmin::Blackboard> blackboard,
9189
std::shared_ptr<const docking_fsm::GoAboveDockingAction::Feedback>
9290
feedback);
9391
};
9492

95-
std::string DockedState(
96-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
93+
std::string DockedState(std::shared_ptr<yasmin::Blackboard> blackboard);
9794

9895
class ReturnHomeState
9996
: public yasmin_ros::ActionState<docking_fsm::ReturnHomeAction> {
10097
public:
101-
explicit ReturnHomeState(
102-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
98+
explicit ReturnHomeState(std::shared_ptr<yasmin::Blackboard> blackboard);
10399

104100
docking_fsm::ReturnHomeAction::Goal create_goal_handler(
105-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
101+
std::shared_ptr<yasmin::Blackboard> blackboard);
106102

107103
std::string response_handler(
108-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
104+
std::shared_ptr<yasmin::Blackboard> blackboard,
109105
docking_fsm::ReturnHomeAction::Result::SharedPtr response);
110106

111107
void print_feedback(
112-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
108+
std::shared_ptr<yasmin::Blackboard> blackboard,
113109
std::shared_ptr<const docking_fsm::ReturnHomeAction::Feedback>
114110
feedback);
115111
};
116112

117-
std::string AbortState(
118-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
113+
std::string AbortState(std::shared_ptr<yasmin::Blackboard> blackboard);
119114

120-
std::string ErrorState(
121-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
115+
std::string ErrorState(std::shared_ptr<yasmin::Blackboard> blackboard);
122116

123117
class ConvergeDockingStationState
124118
: public yasmin_ros::ActionState<docking_fsm::ConvergeDockingAction> {
125119
public:
126-
ConvergeDockingStationState(
127-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
120+
explicit ConvergeDockingStationState(
121+
std::shared_ptr<yasmin::Blackboard> blackboard);
128122

129123
docking_fsm::ConvergeDockingAction::Goal create_goal_handler(
130-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
124+
std::shared_ptr<yasmin::Blackboard> blackboard);
131125

132126
std::string response_handler(
133-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
127+
std::shared_ptr<yasmin::Blackboard> blackboard,
134128
docking_fsm::ConvergeDockingAction::Result::SharedPtr response);
135129

136130
void print_feedback(
137-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard,
131+
std::shared_ptr<yasmin::Blackboard> blackboard,
138132
std::shared_ptr<const docking_fsm::ConvergeDockingAction::Feedback>
139133
feedback);
140134
};
141135

142136
std::shared_ptr<yasmin::StateMachine> create_state_machines();
143137

144138
void add_states(std::shared_ptr<yasmin::StateMachine> sm,
145-
std::shared_ptr<yasmin::blackboard::Blackboard> blackboard);
139+
std::shared_ptr<yasmin::Blackboard> blackboard);
146140

147-
auto initialize_blackboard();
141+
std::shared_ptr<yasmin::Blackboard> initialize_blackboard();
148142

149143
#endif // DOCKING__DOCKING_HPP_

0 commit comments

Comments
 (0)