1+ // Copyright 2025, Universal Robots A/S
2+ //
3+ // Redistribution and use in source and binary forms, with or without
4+ // modification, are permitted provided that the following conditions are met:
5+ //
6+ // * Redistributions of source code must retain the above copyright
7+ // notice, this list of conditions and the following disclaimer.
8+ //
9+ // * Redistributions in binary form must reproduce the above copyright
10+ // notice, this list of conditions and the following disclaimer in the
11+ // documentation and/or other materials provided with the distribution.
12+ //
13+ // * Neither the name of the {copyright_holder} nor the names of its
14+ // contributors may be used to endorse or promote products derived from
15+ // this software without specific prior written permission.
16+ //
17+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+ // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+ // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+ // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+ // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+ // POSSIBILITY OF SUCH DAMAGE.
28+
29+ // ----------------------------------------------------------------------
30+ /* !\file
31+ *
32+ * \author Jacob Larsen [email protected] 33+ * \date 2025-01-07
34+ *
35+ *
36+ *
37+ *
38+ */
39+ // ----------------------------------------------------------------------
40+
41+ #ifndef UR_CONTROLLERS__TOOL_CONTACT_CONTROLLER_HPP_
42+ #define UR_CONTROLLERS__TOOL_CONTACT_CONTROLLER_HPP_
43+
44+ #include < controller_interface/chainable_controller_interface.hpp>
45+
46+ namespace ur_controllers
47+ {
48+ class ToolContactController : public controller_interface ::ChainableControllerInterface
49+ {
50+ public:
51+ CallbackReturn on_init () override ;
52+ controller_interface::InterfaceConfiguration command_interface_configuration () override ;
53+ controller_interface::InterfaceConfiguration state_interface_configuration () override ;
54+
55+ protected:
56+ // / Virtual method that each chainable controller should implement to export its read-only
57+ // / chainable interfaces.
58+ /* *
59+ * Each chainable controller implements this methods where all its state(read only) interfaces are
60+ * exported. The method has the same meaning as `export_state_interfaces` method from
61+ * hardware_interface::SystemInterface or hardware_interface::ActuatorInterface.
62+ *
63+ * \returns list of StateInterfaces that other controller can use as their inputs.
64+ */
65+ std::vector<hardware_interface::StateInterface> on_export_state_interfaces () override ;
66+
67+ // / Virtual method that each chainable controller should implement to export its read/write
68+ // / chainable interfaces.
69+ /* *
70+ * Each chainable controller implements this methods where all input (command) interfaces are
71+ * exported. The method has the same meaning as `export_command_interface` method from
72+ * hardware_interface::SystemInterface or hardware_interface::ActuatorInterface.
73+ *
74+ * \returns list of CommandInterfaces that other controller can use as their outputs.
75+ */
76+ std::vector<hardware_interface::CommandInterface> on_export_reference_interfaces () override ;
77+
78+ // / Virtual method that each chainable controller should implement to switch chained mode.
79+ /* *
80+ * Each chainable controller implements this methods to switch between "chained" and "external"
81+ * mode. In "chained" mode all external interfaces like subscriber and service servers are
82+ * disabled to avoid potential concurrency in input commands.
83+ *
84+ * \param[in] flag marking a switch to or from chained mode.
85+ *
86+ * \returns true if controller successfully switched between "chained" and "external" mode.
87+ * \default returns true so the method don't have to be overridden if controller can always switch
88+ * chained mode.
89+ */
90+ bool on_set_chained_mode (bool chained_mode) override ;
91+
92+ // / Update reference from input topics when not in chained mode.
93+ /* *
94+ * Each chainable controller implements this method to update reference from subscribers when not
95+ * in chained mode.
96+ *
97+ * \returns return_type::OK if update is successfully, otherwise return_type::ERROR.
98+ */
99+ controller_interface::return_type update_reference_from_subscribers (const rclcpp::Time& time,
100+ const rclcpp::Duration& period) override ;
101+
102+ // / Execute calculations of the controller and update command interfaces.
103+ /* *
104+ * Update method for chainable controllers.
105+ * In this method is valid to assume that \reference_interfaces_ hold the values for calculation
106+ * of the commands in the current control step.
107+ * This means that this method is called after \update_reference_from_subscribers if controller is
108+ * not in chained mode.
109+ *
110+ * \returns return_type::OK if calculation and writing of interface is successfully, otherwise
111+ * return_type::ERROR.
112+ */
113+ controller_interface::return_type update_and_write_commands (const rclcpp::Time& time,
114+ const rclcpp::Duration& period) override ;
115+ };
116+ } // namespace ur_controllers
117+
118+ #endif
0 commit comments