|
| 1 | +// Copyright 2019 FZI Forschungszentrum Informatik, Created on behalf of Universal Robots A/S |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +//---------------------------------------------------------------------- |
| 16 | +/*!\file |
| 17 | + * |
| 18 | + * \author Felix Exner [email protected] |
| 19 | + * \date 2019-06-12 |
| 20 | + * |
| 21 | + * \author Mads Holm Peters |
| 22 | + * \date 2022-02-25 |
| 23 | + * |
| 24 | + */ |
| 25 | +//---------------------------------------------------------------------- |
| 26 | +#ifndef UR_ROBOT_DRIVER__CONTROLLER_STOPPER_HPP_ |
| 27 | +#define UR_ROBOT_DRIVER__CONTROLLER_STOPPER_HPP_ |
| 28 | + |
| 29 | +#include <memory> |
| 30 | +#include <string> |
| 31 | +#include <vector> |
| 32 | + |
| 33 | +#include "rclcpp/rclcpp.hpp" |
| 34 | +#include "controller_manager_msgs/srv/list_controllers.hpp" |
| 35 | +#include "controller_manager_msgs/srv/switch_controller.hpp" |
| 36 | +#include "std_msgs/msg/bool.hpp" |
| 37 | + |
| 38 | +class ControllerStopper |
| 39 | +{ |
| 40 | +public: |
| 41 | + ControllerStopper() = delete; |
| 42 | + ControllerStopper(const rclcpp::Node::SharedPtr& node, bool stop_controllers_on_startup); |
| 43 | + virtual ~ControllerStopper() = default; |
| 44 | + |
| 45 | +private: |
| 46 | + void robotRunningCallback(const std_msgs::msg::Bool::ConstSharedPtr msg); |
| 47 | + |
| 48 | + /*! |
| 49 | + * \brief Queries running stoppable controllers and the controllers are stopped. |
| 50 | + * |
| 51 | + * Queries the controller manager for running controllers and compares the result with the |
| 52 | + * consistent_controllers_. The remaining running controllers are stored in stopped_controllers_ |
| 53 | + * and stopped afterwards. |
| 54 | + */ |
| 55 | + void findAndStopControllers(); |
| 56 | + |
| 57 | + /*! |
| 58 | + * \brief Starts the controllers stored in stopped_controllers_. |
| 59 | + * |
| 60 | + */ |
| 61 | + void startControllers(); |
| 62 | + |
| 63 | + std::shared_ptr<rclcpp::Node> node_; |
| 64 | + rclcpp::Client<controller_manager_msgs::srv::SwitchController>::SharedPtr controller_manager_srv_; |
| 65 | + rclcpp::Client<controller_manager_msgs::srv::ListControllers>::SharedPtr controller_list_srv_; |
| 66 | + |
| 67 | + rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr robot_running_sub_; |
| 68 | + |
| 69 | + std::vector<std::string> consistent_controllers_; |
| 70 | + std::vector<std::string> stopped_controllers_; |
| 71 | + |
| 72 | + bool stop_controllers_on_startup_; |
| 73 | + bool robot_running_; |
| 74 | +}; |
| 75 | +#endif // UR_ROBOT_DRIVER__CONTROLLER_STOPPER_HPP_ |
0 commit comments