-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port robot_state_helper to ROS2 (#933)
--------- Co-authored-by: Felix Durchdewald <[email protected]> Co-authored-by: Felix Exner <[email protected]>
- Loading branch information
1 parent
7c63057
commit d4947aa
Showing
10 changed files
with
676 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.. _controller_stopper: | ||
|
||
Controller stopper | ||
================== | ||
|
||
As explained in the section :ref:`robot_startup_program`, the robot needs to run a program in order | ||
to receive motion commands from the ROS driver. When the program is not running, commands sent to | ||
the robot will have no effect. | ||
|
||
To make that transparent, the ``controller_stopper`` node mirrors that state in the ROS | ||
controller's state. It listens to the ``/io_and_status_controller/robot_program_running`` topic and | ||
deactivates all motion controllers (or any controller not explicitly marked as "consistent", see | ||
below)when the program is not running. | ||
|
||
Once the program is running again, any previously active motion controller will be activated again. | ||
|
||
This way, when sending commands to an inactive controller the caller should be transparently | ||
informed, that the controller cannot accept commands at the moment. | ||
|
||
In the same way, any running action on the ROS controller will be aborted, as the controller gets | ||
deactivated by the controller_stopper. | ||
|
||
Parameters | ||
---------- | ||
|
||
- ``~consistent_controllers`` (list of strings, default: ``[]``) | ||
|
||
A list of controller names that should not be stopped when the program is not running. Any | ||
controller that doesn't require the robot program to be running should be in that list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.. _robot_state_helper: | ||
|
||
Robot state helper | ||
================== | ||
After switching on the robot, it has to be manually started, the brakes have to be released and a | ||
program has to be started in order to make the robot ready to use. This is usually done using the | ||
robot's teach pendant. | ||
|
||
Whenever the robot encounters an error, manual intervention is required to resolve the issue. For | ||
example, if the robot goes into a protective stop, the error has to be acknowledged and the robot | ||
program has to be unpaused. | ||
|
||
When the robot is in :ref:`remote_control_mode <operation_modes>`, most interaction with the robot can be done | ||
without using the teach pendant, many of that through the :ref:`dashboard client | ||
<dashboard_client_ros2>`. | ||
|
||
The ROS driver provides a helper node that can be used to automate some of these tasks. The | ||
``robot_state_helper`` node can be used to start the robot, release the brakes, and (re-)start the | ||
program through an action call. It is started by default and provides a | ||
`dashboard_msgs/action/SetMode | ||
<https://github.com/UniversalRobots/Universal_Robots_ROS2_Driver/blob/main/ur_dashboard_msgs/action/SetMode.action>`_ action. | ||
|
||
For example, to make the robot ready to be used by the ROS driver, call | ||
|
||
.. code-block:: console | ||
$ ros2 action send_goal /ur_robot_state_helper/set_mode ur_dashboard_msgs/action/SetMode "{ target_robot_mode: 7, stop_program: true, play_program: true}" | ||
The ``target_robot_mode`` can be one of the following: | ||
|
||
.. table:: target_robot_mode | ||
:widths: auto | ||
|
||
===== ===== | ||
index meaning | ||
===== ===== | ||
3 POWER_OFF -- Robot is powered off | ||
5 IDLE -- Robot is powered on, but brakes are engaged | ||
7 RUNNING -- Robot is powered on, brakes are released, ready to run a program | ||
===== ===== | ||
|
||
.. note:: | ||
|
||
When the ROBOT_STATE is in ``RUNNING``, that is equivalent to the robot showing the green dot in | ||
the lower left corner of the teach pendant (On PolyScope 5). The program state is independent of | ||
that and shows with the text next to that button. | ||
|
||
The ``stop_program`` flag is used to stop the currently running program before changing the robot | ||
state. In combination with the :ref:`controller_stopper`, this will deactivate any motion | ||
controller and therefore stop any ROS action being active on those controllers. | ||
|
||
.. warning:: | ||
A robot's protective stop or emergency stop is only pausing the running program. If the program | ||
is resumed after the P-Stop or EM-Stop is released, the robot will continue executing what it | ||
has been doing. Therefore, it is advised to stop and re-start the program when recovering from a | ||
fault. | ||
|
||
The ``play_program`` flag is used to start the program after the robot state has been set. This has | ||
the same effects as explained in :ref:`continuation_after_interruptions`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
ur_robot_driver/include/ur_robot_driver/robot_state_helper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2024, FZI Forschungszentrum Informatik, Created on behalf of Universal Robots A/S | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// * Neither the name of the {copyright_holder} nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
|
||
#ifndef UR_ROBOT_DRIVER__ROBOT_STATE_HELPER_HPP_ | ||
#define UR_ROBOT_DRIVER__ROBOT_STATE_HELPER_HPP_ | ||
|
||
#include <chrono> | ||
#include <memory> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "rclcpp_action/create_server.hpp" | ||
#include "std_msgs/msg/bool.hpp" | ||
#include "std_srvs/srv/trigger.hpp" | ||
|
||
#include "ur_dashboard_msgs/action/set_mode.hpp" | ||
#include "ur_dashboard_msgs/msg/safety_mode.hpp" | ||
#include "ur_dashboard_msgs/msg/robot_mode.hpp" | ||
#include "ur_client_library/ur/datatypes.h" | ||
|
||
namespace ur_robot_driver | ||
{ | ||
class RobotStateHelper | ||
{ | ||
public: | ||
using SetModeGoalHandle = rclcpp_action::ServerGoalHandle<ur_dashboard_msgs::action::SetMode>; | ||
|
||
explicit RobotStateHelper(const rclcpp::Node::SharedPtr& node); | ||
RobotStateHelper() = delete; | ||
virtual ~RobotStateHelper() = default; | ||
|
||
private: | ||
rclcpp::Node::SharedPtr node_; | ||
|
||
void robotModeCallback(ur_dashboard_msgs::msg::RobotMode::SharedPtr msg); | ||
void safetyModeCallback(ur_dashboard_msgs::msg::SafetyMode::SharedPtr msg); | ||
|
||
void updateRobotState(); | ||
|
||
bool recoverFromSafety(); | ||
bool doTransition(const urcl::RobotMode target_mode); | ||
bool jumpToRobotMode(const urcl::RobotMode target_mode); | ||
|
||
bool safeDashboardTrigger(rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr srv); | ||
|
||
bool stopProgram(); | ||
|
||
void setModeAcceptCallback(const std::shared_ptr<SetModeGoalHandle> goal_handle); | ||
rclcpp_action::GoalResponse setModeGoalCallback(const rclcpp_action::GoalUUID& uuid, | ||
std::shared_ptr<const ur_dashboard_msgs::action::SetMode::Goal> goal); | ||
rclcpp_action::CancelResponse setModeCancelCallback(const std::shared_ptr<SetModeGoalHandle> goal_handle); | ||
|
||
void setModeExecute(const std::shared_ptr<SetModeGoalHandle> goal_handle); | ||
|
||
bool headless_mode_; | ||
|
||
std::shared_ptr<ur_dashboard_msgs::action::SetMode::Result> result_; | ||
std::shared_ptr<ur_dashboard_msgs::action::SetMode::Feedback> feedback_; | ||
std::shared_ptr<const ur_dashboard_msgs::action::SetMode::Goal> goal_; | ||
std::shared_ptr<SetModeGoalHandle> current_goal_handle_; | ||
|
||
std::atomic<urcl::RobotMode> robot_mode_; | ||
std::atomic<urcl::SafetyMode> safety_mode_; | ||
std::atomic<bool> error_ = false; | ||
std::atomic<bool> in_action_; | ||
std::atomic<bool> program_running_; | ||
std::mutex goal_mutex_; | ||
|
||
rclcpp_action::Server<ur_dashboard_msgs::action::SetMode>::SharedPtr set_mode_as_; | ||
|
||
rclcpp::CallbackGroup::SharedPtr robot_mode_sub_cb_; | ||
|
||
rclcpp::Subscription<ur_dashboard_msgs::msg::RobotMode>::SharedPtr robot_mode_sub_; | ||
rclcpp::Subscription<ur_dashboard_msgs::msg::SafetyMode>::SharedPtr safety_mode_sub_; | ||
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr program_running_sub; | ||
|
||
rclcpp::CallbackGroup::SharedPtr service_cb_grp_; | ||
|
||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr unlock_protective_stop_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr restart_safety_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr power_on_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr power_off_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr brake_release_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr stop_program_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr play_program_srv_; | ||
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr resend_robot_program_srv_; | ||
}; | ||
} // namespace ur_robot_driver | ||
|
||
#endif // UR_ROBOT_DRIVER__ROBOT_STATE_HELPER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.