Skip to content

Commit 10e5897

Browse files
authored
Merge pull request #656 from vortexntnu/638-task-operation-mode-manager
Operation mode manager implementation :3
2 parents 1ae24c2 + 2955e8d commit 10e5897

File tree

28 files changed

+839
-134
lines changed

28 files changed

+839
-134
lines changed

auv_setup/config/robots/orca.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@
136136
reference_filter: "reference_filter"
137137
los: "los_guidance"
138138

139+
services:
140+
set_operation_mode: "set_operation_mode"
141+
set_killswitch: "set_killswitch"
142+
toggle_killswitch: "toggle_killswitch"
143+
get_operation_mode: "get_operation_mode"
144+
139145
fsm:
140146
docking:
141147
docking_station_offset: -1.0

auv_setup/launch/topside.launch.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ def generate_launch_description() -> LaunchDescription:
4444
)
4545
)
4646

47-
return LaunchDescription([set_env_var, joy_node, joystick_interface_launch])
47+
return LaunchDescription(
48+
[
49+
set_env_var,
50+
joy_node,
51+
joystick_interface_launch,
52+
]
53+
)

control/dp_adapt_backs_controller/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ find_package(vortex_msgs REQUIRED)
2222
find_package(fmt REQUIRED)
2323
find_package(spdlog REQUIRED)
2424

25+
2526
include_directories(include)
2627

2728
set(LIB_NAME "${PROJECT_NAME}_component")

control/dp_adapt_backs_controller/include/dp_adapt_backs_controller/dp_adapt_backs_controller_ros.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <std_msgs/msg/string.hpp>
1515
#include <string>
1616
#include <vortex/utils/types.hpp>
17+
#include <vortex_msgs/msg/operation_mode.hpp>
1718
#include <vortex_msgs/msg/reference_filter.hpp>
19+
#include <vortex_msgs/srv/get_operation_mode.hpp>
1820
#include "dp_adapt_backs_controller/dp_adapt_backs_controller.hpp"
1921
#include "dp_adapt_backs_controller/typedefs.hpp"
2022
#include "typedefs.hpp"
@@ -28,13 +30,18 @@ class DPAdaptBacksControllerNode : public rclcpp::Node {
2830
const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
2931

3032
private:
33+
// @brief Client for the GetOperationMode service
34+
rclcpp::Client<vortex_msgs::srv::GetOperationMode>::SharedPtr
35+
get_operation_mode_client_;
36+
3137
// @brief Callback function for the killswitch topic
3238
// @param msg: Bool message containing the killswitch status
3339
void killswitch_callback(const std_msgs::msg::Bool::SharedPtr msg);
3440

3541
// @brief Callback function for the software mode topic
3642
// @param msg: String message containing the software mode
37-
void software_mode_callback(const std_msgs::msg::String::SharedPtr msg);
43+
void operation_mode_callback(
44+
const vortex_msgs::msg::OperationMode::SharedPtr msg);
3845

3946
// @brief Callback function for the pose topic
4047
// @param msg: PoseWithCovarianceStamped message containing the AUV pose
@@ -55,6 +62,10 @@ class DPAdaptBacksControllerNode : public rclcpp::Node {
5562
// @brief Set the subscriber and publisher for the node
5663
void set_subscribers_and_publisher();
5764

65+
// @brief Initialize the operation mode by calling the GetOperationMode
66+
// service
67+
void initialize_operation_mode();
68+
5869
// @brief Callback function for the guidance topic
5970
// @param msg: ReferenceFilter message containing the desired vehicle pose
6071
// and velocity
@@ -63,7 +74,8 @@ class DPAdaptBacksControllerNode : public rclcpp::Node {
6374

6475
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr killswitch_sub_{};
6576

66-
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr software_mode_sub_{};
77+
rclcpp::Subscription<vortex_msgs::msg::OperationMode>::SharedPtr
78+
operation_mode_sub_{};
6779

6880
rclcpp::Subscription<
6981
geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr pose_sub_{};
@@ -88,9 +100,10 @@ class DPAdaptBacksControllerNode : public rclcpp::Node {
88100

89101
std::unique_ptr<DPAdaptBacksController> dp_adapt_backs_controller_{};
90102

91-
bool killswitch_on_{false};
103+
bool killswitch_on_{true};
92104

93-
std::string software_mode_{};
105+
vortex::utils::types::Mode operation_mode_{
106+
vortex::utils::types::Mode::manual};
94107
};
95108

96109
} // namespace vortex::control

control/dp_adapt_backs_controller/src/dp_adapt_backs_controller_ros.cpp

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string>
55
#include <vortex/utils/math.hpp>
66
#include <vortex/utils/ros/qos_profiles.hpp>
7+
#include <vortex/utils/ros/ros_conversions.hpp>
78
#include <vortex/utils/types.hpp>
89
#include "dp_adapt_backs_controller/dp_adapt_backs_controller_utils.hpp"
910
#include "dp_adapt_backs_controller/typedefs.hpp"
@@ -25,6 +26,7 @@ DPAdaptBacksControllerNode::DPAdaptBacksControllerNode(
2526
time_step_ = std::chrono::milliseconds(10);
2627

2728
set_subscribers_and_publisher();
29+
initialize_operation_mode();
2830

2931
tau_pub_timer_ = this->create_wall_timer(
3032
time_step_, std::bind(&DPAdaptBacksControllerNode::publish_tau, this));
@@ -74,10 +76,11 @@ void DPAdaptBacksControllerNode::set_subscribers_and_publisher() {
7476
this->declare_parameter<std::string>("topics.operation_mode");
7577
std::string software_operation_mode_topic =
7678
this->get_parameter("topics.operation_mode").as_string();
77-
software_mode_sub_ = this->create_subscription<std_msgs::msg::String>(
78-
software_operation_mode_topic, qos_reliable,
79-
std::bind(&DPAdaptBacksControllerNode::software_mode_callback, this,
80-
std::placeholders::_1));
79+
operation_mode_sub_ =
80+
this->create_subscription<vortex_msgs::msg::OperationMode>(
81+
software_operation_mode_topic, qos_reliable,
82+
std::bind(&DPAdaptBacksControllerNode::operation_mode_callback,
83+
this, std::placeholders::_1));
8184

8285
this->declare_parameter<std::string>("topics.wrench_input");
8386
std::string control_topic =
@@ -86,6 +89,44 @@ void DPAdaptBacksControllerNode::set_subscribers_and_publisher() {
8689
control_topic, qos_sensor_data);
8790
}
8891

92+
void DPAdaptBacksControllerNode::initialize_operation_mode() {
93+
this->declare_parameter<std::string>("services.get_operation_mode");
94+
std::string get_operation_mode_service =
95+
this->get_parameter("services.get_operation_mode").as_string();
96+
97+
get_operation_mode_client_ =
98+
this->create_client<vortex_msgs::srv::GetOperationMode>(
99+
get_operation_mode_service);
100+
101+
while (!get_operation_mode_client_->wait_for_service(
102+
std::chrono::seconds(1))) {
103+
spdlog::warn("Waiting for GetOperationMode service to be available...");
104+
}
105+
106+
auto request =
107+
std::make_shared<vortex_msgs::srv::GetOperationMode::Request>();
108+
get_operation_mode_client_->async_send_request(
109+
request,
110+
[this](rclcpp::Client<vortex_msgs::srv::GetOperationMode>::SharedFuture
111+
future) {
112+
try {
113+
auto response = future.get();
114+
operation_mode_ =
115+
vortex::utils::ros_conversions::convert_from_ros(
116+
response->current_operation_mode);
117+
killswitch_on_ = response->killswitch_status;
118+
spdlog::info(
119+
"Initial operation mode: {} | Killswitch status: {}",
120+
vortex::utils::types::mode_to_string(operation_mode_),
121+
killswitch_on_ ? "on" : "off");
122+
} catch (const std::exception& e) {
123+
spdlog::error("Failed to get initial operation mode: {}",
124+
e.what());
125+
killswitch_on_ = true;
126+
}
127+
});
128+
}
129+
89130
void DPAdaptBacksControllerNode::killswitch_callback(
90131
const std_msgs::msg::Bool::SharedPtr msg) {
91132
killswitch_on_ = msg->data;
@@ -94,12 +135,14 @@ void DPAdaptBacksControllerNode::killswitch_callback(
94135
spdlog::info("Killswitch: {}", killswitch_on_ ? "on" : "off");
95136
}
96137

97-
void DPAdaptBacksControllerNode::software_mode_callback(
98-
const std_msgs::msg::String::SharedPtr msg) {
99-
software_mode_ = msg->data;
100-
spdlog::info("Software mode: {}", software_mode_);
138+
void DPAdaptBacksControllerNode::operation_mode_callback(
139+
const vortex_msgs::msg::OperationMode::SharedPtr msg) {
140+
operation_mode_ = vortex::utils::ros_conversions::convert_from_ros(*msg);
141+
spdlog::info("Operation mode: {}",
142+
vortex::utils::types::mode_to_string(operation_mode_));
101143

102-
if (software_mode_ == "autonomous mode") {
144+
if (operation_mode_ == vortex::utils::types::Mode::autonomous ||
145+
operation_mode_ == vortex::utils::types::Mode::reference) {
103146
pose_d_ = pose_;
104147
}
105148
}
@@ -180,7 +223,8 @@ void DPAdaptBacksControllerNode::set_adap_params() {
180223
}
181224

182225
void DPAdaptBacksControllerNode::publish_tau() {
183-
if (killswitch_on_ || software_mode_ != "autonomous mode") {
226+
if (killswitch_on_ ||
227+
operation_mode_ == vortex::utils::types::Mode::manual) {
184228
return;
185229
}
186230

control/pid_controller_dp/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8)
22
project(pid_controller_dp)
33

44
if(NOT CMAKE_CXX_STANDARD)
5-
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD 20)
66
endif()
77

88
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -16,6 +16,8 @@ find_package(geometry_msgs REQUIRED)
1616
find_package(Eigen3 REQUIRED)
1717
find_package(tf2 REQUIRED)
1818
find_package(vortex_msgs REQUIRED)
19+
find_package(vortex_utils REQUIRED)
20+
find_package(vortex_utils_ros REQUIRED)
1921

2022
include_directories(include)
2123

@@ -34,6 +36,8 @@ ament_target_dependencies(pid_controller_node
3436
Eigen3
3537
tf2
3638
vortex_msgs
39+
vortex_utils
40+
vortex_utils_ros
3741
)
3842

3943
install(TARGETS

control/pid_controller_dp/include/pid_controller_dp/pid_controller_ros.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#include <std_msgs/msg/string.hpp>
1414
#include <string>
1515
#include <variant>
16+
#include <vortex/utils/types.hpp>
17+
#include <vortex_msgs/msg/operation_mode.hpp>
1618
#include <vortex_msgs/msg/reference_filter.hpp>
19+
#include <vortex_msgs/srv/get_operation_mode.hpp>
1720
#include "pid_controller_dp/pid_controller.hpp"
1821
#include "pid_controller_dp/typedefs.hpp"
1922

@@ -29,7 +32,8 @@ class PIDControllerNode : public rclcpp::Node {
2932

3033
// @brief Callback function for the software mode topic
3134
// @param msg: String message containing the software mode
32-
void software_mode_callback(const std_msgs::msg::String::SharedPtr msg);
35+
void operation_mode_callback(
36+
const vortex_msgs::msg::OperationMode::SharedPtr msg);
3337

3438
// @brief Callback function for the pose topic
3539
// @param msg: PoseWithCovarianceStamped message containing the AUV pose
@@ -50,17 +54,25 @@ class PIDControllerNode : public rclcpp::Node {
5054
// @brief Set the subscriber and publisher for the node
5155
void set_subscribers_and_publisher();
5256

57+
// @brief Initialize the operation mode by calling the GetOperationMode
58+
// service
59+
void initialize_operation_mode();
60+
5361
// @brief Callback function for the guidance topic
5462
// @param msg: ReferenceFilter message containing the desired vehicle pose
5563
// and velocity
5664
void guidance_callback(
5765
const vortex_msgs::msg::ReferenceFilter::SharedPtr msg);
5866

67+
rclcpp::Client<vortex_msgs::srv::GetOperationMode>::SharedPtr
68+
get_operation_mode_client_;
69+
5970
PIDController pid_controller_;
6071

6172
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr killswitch_sub_;
6273

63-
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr software_mode_sub_;
74+
rclcpp::Subscription<vortex_msgs::msg::OperationMode>::SharedPtr
75+
operation_mode_sub_;
6476

6577
rclcpp::Subscription<
6678
geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr pose_sub_;
@@ -91,9 +103,10 @@ class PIDControllerNode : public rclcpp::Node {
91103

92104
types::Eta eta_dot_d_;
93105

94-
bool killswitch_on_;
106+
bool killswitch_on_{true};
95107

96-
std::string software_mode_;
108+
vortex::utils::types::Mode operation_mode_{
109+
vortex::utils::types::Mode::manual};
97110
};
98111

99112
#endif // PID_CONTROLLER_DP__PID_CONTROLLER_ROS_HPP_

control/pid_controller_dp/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<depend>eigen</depend>
1616
<depend>tf2</depend>
1717
<depend>vortex_msgs</depend>
18+
<depend>vortex_utils</depend>
19+
<depend>vortex_utils_ros</depend>
1820

1921
<export>
2022
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)