Skip to content

Commit b1e7ac7

Browse files
committed
Friction model controller
Adds a friction model controller to control the viscous and coulomb parameters used with the direct_torque effort interface.
1 parent 9aff85a commit b1e7ac7

16 files changed

+854
-2
lines changed

ur_controllers/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ generate_parameter_library(
6262
src/force_mode_controller_parameters.yaml
6363
)
6464

65+
generate_parameter_library(
66+
friction_model_controller_parameters
67+
src/friction_model_controller_parameters.yaml
68+
)
69+
6570
generate_parameter_library(
6671
gpio_controller_parameters
6772
src/gpio_controller_parameters.yaml
@@ -95,6 +100,7 @@ generate_parameter_library(
95100
add_library(${PROJECT_NAME} SHARED
96101
src/tool_contact_controller.cpp
97102
src/force_mode_controller.cpp
103+
src/friction_model_controller.cpp
98104
src/scaled_joint_trajectory_controller.cpp
99105
src/speed_scaling_state_broadcaster.cpp
100106
src/freedrive_mode_controller.cpp
@@ -108,6 +114,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
108114
target_link_libraries(${PROJECT_NAME}
109115
tool_contact_controller_parameters
110116
force_mode_controller_parameters
117+
friction_model_controller_parameters
111118
gpio_controller_parameters
112119
speed_scaling_state_broadcaster_parameters
113120
scaled_joint_trajectory_controller_parameters
@@ -191,6 +198,14 @@ if(BUILD_TESTING)
191198
controller_manager::controller_manager
192199
ros2_control_test_assets::ros2_control_test_assets
193200
)
201+
ament_add_gmock(test_load_friction_model_controller
202+
test/test_load_friction_model_controller.cpp
203+
)
204+
target_link_libraries(test_load_friction_model_controller
205+
${PROJECT_NAME}
206+
controller_manager::controller_manager
207+
ros2_control_test_assets::ros2_control_test_assets
208+
)
194209
endif()
195210

196211
ament_package()

ur_controllers/controller_plugins.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
Controller to use UR's force_mode.
2020
</description>
2121
</class>
22+
<class name="ur_controllers/FrictionModelController" type="ur_controllers::FrictionModelController" base_class_type="controller_interface::ControllerInterface">
23+
<description>
24+
Controller to set per-joint viscous and Coulomb friction scale factors for direct torque control.
25+
</description>
26+
</class>
2227
<class name="ur_controllers/FreedriveModeController" type="ur_controllers::FreedriveModeController" base_class_type="controller_interface::ControllerInterface">
2328
<description>
2429
This controller handles the activation of the freedrive mode.

ur_controllers/doc/index.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,38 @@ gain_scaling
349349
Force mode gain scaling factor. Scales the gain in force mode. scaling parameter is in range [0;2], default is 0.5.
350350
A value larger than 1 can make force mode unstable, e.g. in case of collisions or pushing against hard surfaces.
351351

352+
.. _friction_model_controller:
353+
354+
ur_controllers/FrictionModelController
355+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
356+
357+
This controller allows setting per-joint viscous and Coulomb friction scale factors for direct
358+
torque control. The friction model scales control how much internal friction compensation the robot
359+
applies during direct torque control mode.
360+
361+
Parameters
362+
""""""""""
363+
364+
+------------------------------------+--------+---------------+----------------------------------------------------------------------+
365+
| Parameter name | Type | Default value | Description |
366+
| | | | |
367+
+------------------------------------+--------+---------------+----------------------------------------------------------------------+
368+
| ``tf_prefix`` | string | <empty> | Urdf prefix of the corresponding arm |
369+
+------------------------------------+--------+---------------+----------------------------------------------------------------------+
370+
| ``check_io_successful_retries`` | int | 10 | Amount of retries for checking if setting friction scales was |
371+
| | | | successful |
372+
+------------------------------------+--------+---------------+----------------------------------------------------------------------+
373+
374+
Service interface / usage
375+
"""""""""""""""""""""""""
376+
377+
The controller provides a service for setting friction scale factors. To use this service, the
378+
controller has to be in ``active`` state.
379+
380+
* ``~/set_friction_model_parameters [ur_msgs/srv/SetFrictionModelParameters]``: Set per-joint viscous and Coulomb
381+
friction scale factors for direct torque control. Each array must contain exactly one value for each joint in
382+
range [0-1] where 0 means no compensation and 1 means full compensation.
383+
352384
.. _freedrive_mode_controller:
353385

354386
ur_controllers/FreedriveModeController
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2026, 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 Rune Søe-Knudsen rsk@universal-robots.com
33+
* \date 2026-03-02
34+
*
35+
*/
36+
//----------------------------------------------------------------------
37+
38+
#pragma once
39+
#include <array>
40+
41+
#include <controller_interface/controller_interface.hpp>
42+
#include <rclcpp/rclcpp.hpp>
43+
#include <realtime_tools/realtime_thread_safe_box.hpp>
44+
#include <ur_msgs/srv/set_friction_model_parameters.hpp>
45+
46+
#include "ur_controllers/friction_model_controller_parameters.hpp"
47+
48+
namespace ur_controllers
49+
{
50+
namespace friction_model
51+
{
52+
enum CommandInterfaces
53+
{
54+
FRICTION_MODEL_VISCOUS_0 = 0u,
55+
FRICTION_MODEL_VISCOUS_1 = 1,
56+
FRICTION_MODEL_VISCOUS_2 = 2,
57+
FRICTION_MODEL_VISCOUS_3 = 3,
58+
FRICTION_MODEL_VISCOUS_4 = 4,
59+
FRICTION_MODEL_VISCOUS_5 = 5,
60+
FRICTION_MODEL_COULOMB_0 = 6,
61+
FRICTION_MODEL_COULOMB_1 = 7,
62+
FRICTION_MODEL_COULOMB_2 = 8,
63+
FRICTION_MODEL_COULOMB_3 = 9,
64+
FRICTION_MODEL_COULOMB_4 = 10,
65+
FRICTION_MODEL_COULOMB_5 = 11,
66+
FRICTION_MODEL_ASYNC_SUCCESS = 12,
67+
};
68+
} // namespace friction_model
69+
70+
struct FrictionModelParameters
71+
{
72+
std::array<double, 6> viscous_scale;
73+
std::array<double, 6> coulomb_scale;
74+
};
75+
76+
class FrictionModelController : public controller_interface::ControllerInterface
77+
{
78+
public:
79+
controller_interface::InterfaceConfiguration command_interface_configuration() const override;
80+
81+
controller_interface::InterfaceConfiguration state_interface_configuration() const override;
82+
83+
controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;
84+
85+
CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) override;
86+
87+
CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override;
88+
89+
CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;
90+
91+
CallbackReturn on_init() override;
92+
93+
CallbackReturn on_cleanup(const rclcpp_lifecycle::State& previous_state) override;
94+
95+
private:
96+
bool setFrictionModelParameters(const ur_msgs::srv::SetFrictionModelParameters::Request::SharedPtr req,
97+
ur_msgs::srv::SetFrictionModelParameters::Response::SharedPtr resp);
98+
99+
rclcpp::Service<ur_msgs::srv::SetFrictionModelParameters>::SharedPtr set_friction_model_parameters_srv_;
100+
101+
std::shared_ptr<friction_model_controller::ParamListener> param_listener_;
102+
friction_model_controller::Params params_;
103+
104+
realtime_tools::RealtimeThreadSafeBox<FrictionModelParameters> friction_model_params_buffer_;
105+
std::atomic<bool> change_requested_;
106+
std::atomic<double> async_state_;
107+
108+
static constexpr double ASYNC_WAITING = 2.0;
109+
bool waitForAsyncCommand(std::function<double(void)> get_value);
110+
};
111+
} // namespace ur_controllers

0 commit comments

Comments
 (0)