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+
89130void 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
182225void 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
0 commit comments