Skip to content

Commit 856e8e2

Browse files
destoglbmagyar
andauthored
Enable JTC for hardware having offset from state measurements (ros-controls#189)
* Avoid "jumps" with states that have tracking error. All test are passing but separatelly. Is there some kind of timeout? * Remove allow_integration_flag * Add reading from command interfaces when restarting controller * Rename variable according to review * Use even more clear name * Remove debug lines. * Update documentation * Apply suggestions from code review Co-authored-by: Bence Magyar <[email protected]> * Move methods to cpp file as per reviewers comment. Co-authored-by: Bence Magyar <[email protected]>
1 parent 12ba94f commit 856e8e2

File tree

8 files changed

+567
-90
lines changed

8 files changed

+567
-90
lines changed

doc/controllers_index.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
.. _controllers:
22

3-
========================
3+
#################
44
ros2_controllers
5-
========================
5+
#################
66

77
`GitHub Repository <https://github.com/ros-controls/ros2_controllers>`_
88

9+
910
Nomenclature
10-
-------------
11+
************
12+
1113
The ros2_control framework uses namespaces to sort controller according to the type of command interface they are using.
1214
The controllers are using `common hardware interface definitions`_.
1315
The controllers' namespaces are commanding the following command interface types:
@@ -19,7 +21,7 @@ The controllers' namespaces are commanding the following command interface types
1921

2022

2123
Controllers
22-
--------------
24+
***********
2325

2426
The following standard controllers are implemented:
2527

@@ -30,7 +32,7 @@ The following standard controllers are implemented:
3032

3133

3234
Guidelines and Best Practices
33-
=============================
35+
*****************************
3436

3537
.. toctree::
3638
:titlesonly:

joint_trajectory_controller/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if(BUILD_TESTING)
7070
ament_add_gtest(test_trajectory_controller
7171
test/test_trajectory_controller.cpp
7272
ENV config_file=${CMAKE_CURRENT_SOURCE_DIR}/test/config/test_joint_trajectory_controller.yaml)
73-
set_tests_properties(test_trajectory_controller PROPERTIES TIMEOUT 120)
73+
set_tests_properties(test_trajectory_controller PROPERTIES TIMEOUT 180)
7474
target_include_directories(test_trajectory_controller PRIVATE include)
7575
target_link_libraries(test_trajectory_controller
7676
joint_trajectory_controller

joint_trajectory_controller/doc/userdoc.rst

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ joint_trajectory_controller
66
Controller for executing joint-space trajectories on a group of joints. Trajectories are specified as a set of waypoints to be reached at specific time instants, which the controller attempts to execute as well as the mechanism allows. Waypoints consist of positions, and optionally velocities and accelerations.
77

88
Trajectory representation
9-
^^^^^^^^^^^^^^^^^^^^^^^^^
9+
-------------------------
1010

1111
The controller is templated to work with multiple trajectory representations. By default, a spline interpolator is provided, but it's possible to support other representations. The spline interpolator uses the following interpolation strategies depending on the waypoint specification:
1212

@@ -17,14 +17,14 @@ The controller is templated to work with multiple trajectory representations. By
1717
Quintic: Position, velocity and acceleration are specified: Guarantees continuity at the acceleration level.
1818

1919
Hardware interface type
20-
^^^^^^^^^^^^^^^^^^^^^^^
20+
-----------------------
2121

2222
The controller is templated to work with multiple hardware interface types. Currently joints with position, velocity and effort interfaces are supported. For position-controlled joints, desired positions are simply forwarded to the joints; while for velocity (effort) joints, the position+velocity trajectory following error is mapped to velocity (effort) commands through a PID loop. Example controller configurations can be found here.
2323

2424
Similarly to the trajectory representation case above, it's possible to support new hardware interfaces, or alternative mappings to an already supported interface (eg. a proxy controller for generating effort commands).
2525

2626
Other features
27-
^^^^^^^^^^^^^^
27+
--------------
2828

2929
Realtime-safe implementation.
3030

@@ -34,7 +34,7 @@ Other features
3434

3535

3636
Using Joint Trajectory Controller(s)
37-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
------------------------------------
3838

3939
The controller expects at least position feedback from the hardware.
4040
Joint velocities and accelerations are optional.
@@ -54,12 +54,12 @@ A yaml file for using it could be:
5454
joint_trajectory_controller:
5555
ros__parameters:
5656
joints:
57-
- joint0
5857
- joint1
5958
- joint2
6059
- joint3
6160
- joint4
6261
- joint5
62+
- joint6
6363
6464
command_interfaces:
6565
- position
@@ -68,19 +68,93 @@ A yaml file for using it could be:
6868
- position
6969
- velocity
7070
71-
state_publish_rate: 50.0 # Defaults to 50
72-
action_monitor_rate: 20.0 # Defaults to 20
71+
state_publish_rate: 50.0
72+
action_monitor_rate: 20.0
7373
74-
allow_partial_joints_goal: false # Defaults to false
75-
hardware_state_has_offset: true
76-
deduce_states_from_derivatives: true
74+
allow_partial_joints_goal: false
75+
open_loop_control: true
7776
constraints:
78-
stopped_velocity_tolerance: 0.01 # Defaults to 0.01
79-
goal_time: 0.0 # Defaults to 0.0 (start immediately)
77+
stopped_velocity_tolerance: 0.01
78+
goal_time: 0.0
79+
joint1:
80+
trajectory: 0.05
81+
goal: 0.03
82+
83+
84+
Details about parameters
85+
^^^^^^^^^^^^^^^^^^^^^^^^
86+
87+
joint (list(string)):
88+
Joint names to control.
89+
90+
command_interface (list(string)):
91+
Command interfaces provided by the hardware interface for all joints.
92+
93+
Values: [position | velocity | acceleration] (multiple allowed)
94+
95+
state_interfaces (list(string)):
96+
State interfaces provided by the hardware for all joints.
97+
98+
Values: position (mandatory) [velocity, [acceleration]].
99+
Acceleration interface can only be used in combination with position and velocity.
100+
101+
Default: 50.0
102+
103+
state_publish_rate (double):
104+
Publish-rate of the controller's "state" topic.
105+
106+
Default: 20.0
107+
108+
action_monitor_rate (double):
109+
Rate to monitor status changes when the controller is executing action (control_msgs::action::FollowJointTrajectory).
110+
111+
allow_partial_joints_goal (boolean):
112+
Allow joint goals defining trajectory for only some joints.
113+
114+
open_loop_control (boolean):
115+
Use controller in open-loop control mode using ignoring the states provided by hardware interface and using last commands as states in the next control step. This is useful if hardware states are not following commands, i.e., an offset between those (typical for hydraulic manipulators).
116+
117+
If this flag is set, the controller tries to read the values from the command interfaces on starting. If they have real numeric values, those will be used instead of state interfaces. Therefore it is important set command interfaces to NaN (std::numeric_limits<double>::quiet_NaN()) or state values when the hardware is started.
118+
119+
constraints (structure)
120+
Default values for tolerances if no explicit values are states in JointTrajectory message.
121+
122+
constraints.stopped_velocity_tolerance (double)
123+
Default value for end velocity deviation.
124+
125+
Default: 0.01
126+
127+
constraints.goal_time (double)
128+
Maximally allowed tolerance for not reaching the end of the trajectory in a predefined time.
129+
130+
Default: 0.0 (not checked)
131+
132+
constraints.<joint_name>.trajectory
133+
Maximally allowed deviation from the target trajectory for a given joint.
134+
135+
Default: 0.0 (tolerance is not enforced)
136+
137+
constraints.<joint_name>.goal
138+
Maximally allowed deviation from the goal (end of the trajectory) for a given joint.
139+
140+
Default: 0.0 (tolerance is not enforced)
141+
142+
143+
ROS2 interface of the controller
144+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145+
146+
~/joint_trajectory (input topic) [trajectory_msgs::msg::JointTrajectory]
147+
Topic for commanding the controller.
148+
149+
~/state (output topic) [control_msgs::msg::JointTrajectoryControllerState]
150+
Topic publishing internal states.
151+
152+
~/follow_joint_trajectory (action server) [control_msgs::action::FollowJointTrajectory]
153+
Action server for commanding the controller.
80154

81155

82156
Specialized versions of JointTrajectoryController (TBD in ...)
83-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157+
--------------------------------------------------------------
84158

85159
The controller types are placed into namespaces according to their command types for the hardware (see `general introduction into controllers <../../index.rst>`_).
86160

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
126126
hardware_interface::HW_IF_EFFORT,
127127
};
128128

129+
// Parameters for some special cases, e.g. hydraulics powered robots
130+
/// Run he controller in open-loop, i.e., read hardware states only when starting controller.
131+
/// This is useful when robot is not exactly following the commanded trajectory.
132+
bool open_loop_control_ = false;
133+
trajectory_msgs::msg::JointTrajectoryPoint last_commanded_state_;
134+
129135
// The interfaces are defined as the types in 'allowed_interface_types_' member.
130136
// For convenience, for each type the interfaces are ordered so that i-th position
131137
// matches i-th index in joint_names_
@@ -142,6 +148,9 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
142148
bool has_acceleration_command_interface_ = false;
143149

144150
/// If true, a velocity feedforward term plus corrective PID term is used
151+
// TODO(anyone): This flag is not used for now
152+
// There should be PID-approach used as in ROS1:
153+
// https://github.com/ros-controls/ros_controllers/blob/noetic-devel/joint_trajectory_controller/include/joint_trajectory_controller/hardware_interface_adapter.h#L283
145154
bool use_closed_loop_pid_adapter = false;
146155

147156
// TODO(karsten1987): eventually activate and deactive subscriber directly when its supported
@@ -231,13 +240,16 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
231240
const JointTrajectoryPoint & current_state,
232241
const JointTrajectoryPoint & state_error);
233242

243+
void read_state_from_hardware(JointTrajectoryPoint & state);
244+
245+
bool read_state_from_command_interfaces(JointTrajectoryPoint & state);
246+
234247
private:
235248
bool contains_interface_type(
236-
const std::vector<std::string> & interface_type_list, const std::string & interface_type)
237-
{
238-
return std::find(interface_type_list.begin(), interface_type_list.end(), interface_type) !=
239-
interface_type_list.end();
240-
}
249+
const std::vector<std::string> & interface_type_list, const std::string & interface_type);
250+
251+
void resize_joint_trajectory_point(
252+
trajectory_msgs::msg::JointTrajectoryPoint & point, size_t size);
241253
};
242254

243255
} // namespace joint_trajectory_controller

joint_trajectory_controller/include/joint_trajectory_controller/tolerances.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ struct SegmentTolerances
7777
/**
7878
* \brief Populate trajectory segment tolerances using data from the ROS node.
7979
*
80-
* It is assumed that the following parameter structure is followed on the provided LifecycleNode. Unspecified parameters
81-
* will take the defaults shown in the comments:
80+
* It is assumed that the following parameter structure is followed on the provided LifecycleNode.
81+
* Unspecified parameters will take the defaults shown in the comments:
8282
*
8383
* \code
8484
* constraints:

0 commit comments

Comments
 (0)