@@ -133,6 +133,43 @@ namespace webots_ros2_control {
133133 return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
134134 }
135135
136+ hardware_interface::return_type Ros2ControlSystem::perform_command_mode_switch (
137+ const std::vector<std::string> &start_interfaces, const std::vector<std::string> &stop_interfaces) {
138+ for (Joint &joint : mJoints ) {
139+ for (const std::string &interface_name : stop_interfaces) {
140+ // Clear joint control method bits corresponding to stop interfaces
141+ if (interface_name == (joint.name + " /" + hardware_interface::HW_IF_POSITION)) {
142+ joint.controlPosition = false ;
143+ }
144+ if (interface_name == (joint.name + " /" + hardware_interface::HW_IF_VELOCITY)) {
145+ joint.controlVelocity = false ;
146+ }
147+ if (interface_name == (joint.name + " /" + hardware_interface::HW_IF_EFFORT)) {
148+ joint.controlEffort = false ;
149+ }
150+ }
151+
152+ // Set joint control method bits corresponding to start interfaces
153+ for (const std::string &interface_name : start_interfaces) {
154+ if (interface_name == (joint.name + " /" + hardware_interface::HW_IF_POSITION)) {
155+ joint.controlPosition = true ;
156+ }
157+ if (interface_name == (joint.name + " /" + hardware_interface::HW_IF_VELOCITY)) {
158+ joint.controlVelocity = true ;
159+ }
160+ if (interface_name == (joint.name + " /" + hardware_interface::HW_IF_EFFORT)) {
161+ joint.controlEffort = true ;
162+ }
163+ }
164+ if (joint.motor && joint.controlVelocity && !joint.controlPosition ) {
165+ wb_motor_set_position (joint.motor , INFINITY);
166+ wb_motor_set_velocity (joint.motor , 0.0 );
167+ }
168+ }
169+
170+ return hardware_interface::return_type::OK;
171+ }
172+
136173 hardware_interface::return_type Ros2ControlSystem::read (const rclcpp::Time & /* time*/ , const rclcpp::Duration & /* period*/ ) {
137174 static double lastReadTime = 0 ;
138175
0 commit comments