Skip to content

Commit fde616b

Browse files
committed
Address first part of reviewrs comments.
1 parent 74f7f52 commit fde616b

File tree

5 files changed

+163
-163
lines changed

5 files changed

+163
-163
lines changed

joint_trajectory_controller/doc/userdoc.rst

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,80 @@ Other features
3030

3131
Proper handling of wrapping (continuous) joints.
3232

33-
Robust to system clock changes: Discontinuous system clock changes do not cause discontinuities in the execution of already queued trajectory segments.
33+
Robust to system clock changes: Discontinuous system clock changes do not cause discontinuities in the execution of already queued trajectory segments.
34+
35+
36+
Using Joint Trajectory Controller(s)
37+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
The controller expects at least position feedback from the hardware.
40+
Joint velocities and accelerations are optional.
41+
Currently the controller does not internally integrate velocity from acceleration and position from velocity.
42+
Therefore if the hardware provides only acceleration or velocity states they have to be integrated in the hardware-interface implementation of velocity and position to use these controllers.
43+
44+
The generic version of Joint Trajectory controller is implemented in this package.
45+
A yaml file for using it could be:
46+
47+
.. code-block:: yaml
48+
49+
controller_manager:
50+
ros__parameters:
51+
joint_trajectory_controller:
52+
type: "joint_trajectory_controller/JointTrajectoryController"
53+
54+
joint_trajectory_controller:
55+
ros__parameters:
56+
joints:
57+
- joint0
58+
- joint1
59+
- joint2
60+
- joint3
61+
- joint4
62+
- joint5
63+
64+
command_interfaces:
65+
- position
66+
67+
state_interfaces:
68+
- position
69+
- velocity
70+
71+
state_publish_rate: 50.0 # Defaults to 50
72+
action_monitor_rate: 20.0 # Defaults to 20
73+
74+
allow_partial_joints_goal: false # Defaults to false
75+
hardware_state_has_offset: true
76+
deduce_states_from_derivatives: true
77+
constraints:
78+
stopped_velocity_tolerance: 0.01 # Defaults to 0.01
79+
goal_time: 0.0 # Defaults to 0.0 (start immediately)
80+
81+
82+
Specialized versions of JointTrajectoryController (TBD in ...)
83+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
85+
The controller types are placed into namespaces according to their command types for the hardware (see `general introduction into controllers <../../index.rst>`_).
86+
87+
The following version of the Joint Trajectory Controller are available mapping the following interfaces:
88+
89+
- position_controllers::JointTrajectoryController
90+
- Input: position, [velocity, [acceleration]]
91+
- Output: position
92+
- position_velocity_controllers::JointTrajectoryController
93+
- Input: position, [velocity, [acceleration]]
94+
- Output: position and velocity
95+
- position_velocity_acceleration_controllers::JointTrajectoryController
96+
- Input: position, [velocity, [acceleration]]
97+
- Output: position, velocity and acceleration
98+
.. - velocity_controllers::JointTrajectoryController
99+
.. - Input: position, [velocity, [acceleration]]
100+
.. - Output: velocity
101+
.. TODO(anyone): would it be possible to output velocty and acceleration?
102+
.. (to have an vel_acc_controllers)
103+
.. - effort_controllers::JointTrajectoryController
104+
.. - Input: position, [velocity, [acceleration]]
105+
.. - Output: effort
106+
107+
The controller uses `common hardware interface definitions`_.
108+
109+
(*Not implemented yet*) When using pure ``velocity`` or ``effort`` controllers a command is generated using the desired state and state error using a velocity feedforward term plus a corrective PID term. (#171)

joint_trajectory_controller/docs/index.rst

Lines changed: 0 additions & 59 deletions
This file was deleted.

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
132132
std::vector<std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>>>
133133
joint_state_interface_;
134134

135+
bool has_velocity_state_interface_ = false;
136+
bool has_acceleration_state_interface_ = false;
137+
bool has_position_command_interface_ = false;
138+
bool has_velocity_command_interface_ = false;
139+
bool has_acceleration_command_interface_ = false;
140+
135141
/// If true, a velocity feedforward term plus corrective PID term is used
136142
bool use_closed_loop_pid_adapter = false;
137143

@@ -211,7 +217,7 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
211217
const JointTrajectoryPoint & state_error);
212218

213219
private:
214-
bool check_if_interface_type_exists(
220+
bool contains_interface_type(
215221
const std::vector<std::string> & interface_type_list, const std::string & interface_type)
216222
{
217223
return std::find(interface_type_list.begin(), interface_type_list.end(), interface_type) !=

joint_trajectory_controller/src/joint_trajectory_controller.cpp

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
namespace joint_trajectory_controller
4646
{
4747

48-
// TODO(anyone): remove this 'using namespace''
49-
using namespace std::chrono_literals;
50-
using lifecycle_msgs::msg::State;
51-
5248
JointTrajectoryController::JointTrajectoryController()
5349
: controller_interface::ControllerInterface(),
5450
joint_names_({})
@@ -108,7 +104,7 @@ state_interface_configuration() const
108104
controller_interface::return_type
109105
JointTrajectoryController::update()
110106
{
111-
if (get_current_state().id() == State::PRIMARY_STATE_INACTIVE) {
107+
if (get_current_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE) {
112108
if (!is_halted_) {
113109
halt();
114110
is_halted_ = true;
@@ -120,14 +116,10 @@ JointTrajectoryController::update()
120116
[&](trajectory_msgs::msg::JointTrajectoryPoint & point, size_t size)
121117
{
122118
point.positions.resize(size);
123-
if (check_if_interface_type_exists(
124-
state_interface_types_, hardware_interface::HW_IF_VELOCITY))
125-
{
119+
if (has_velocity_state_interface_) {
126120
point.velocities.resize(size);
127121
}
128-
if (check_if_interface_type_exists(
129-
state_interface_types_, hardware_interface::HW_IF_ACCELERATION))
130-
{
122+
if (has_acceleration_state_interface_) {
131123
point.accelerations.resize(size);
132124
}
133125
};
@@ -137,18 +129,10 @@ JointTrajectoryController::update()
137129
// error defined as the difference between current and desired
138130
error.positions[index] = angles::shortest_angular_distance(
139131
current.positions[index], desired.positions[index]);
140-
if (check_if_interface_type_exists(
141-
state_interface_types_, hardware_interface::HW_IF_VELOCITY) &&
142-
check_if_interface_type_exists(
143-
command_interface_types_, hardware_interface::HW_IF_VELOCITY))
144-
{
132+
if (has_velocity_state_interface_ && has_velocity_command_interface_) {
145133
error.velocities[index] = desired.velocities[index] - current.velocities[index];
146134
}
147-
if (check_if_interface_type_exists(
148-
state_interface_types_, hardware_interface::HW_IF_ACCELERATION) &&
149-
check_if_interface_type_exists(
150-
command_interface_types_, hardware_interface::HW_IF_ACCELERATION))
151-
{
135+
if (has_acceleration_state_interface_ && has_acceleration_command_interface_) {
152136
error.accelerations[index] = desired.accelerations[index] - current.accelerations[index];
153137
}
154138
};
@@ -190,13 +174,10 @@ JointTrajectoryController::update()
190174
// Position states always exist
191175
assign_point_from_interface(state_current.positions, joint_state_interface_[0]);
192176
// velocity and acceleration states are optional
193-
if (check_if_interface_type_exists(state_interface_types_, hardware_interface::HW_IF_VELOCITY)) {
177+
if (has_velocity_state_interface_) {
194178
assign_point_from_interface(state_current.velocities, joint_state_interface_[1]);
195179
// Acceleration is used only in combination with velocity
196-
if (check_if_interface_type_exists(
197-
state_interface_types_,
198-
hardware_interface::HW_IF_ACCELERATION))
199-
{
180+
if (has_acceleration_state_interface_) {
200181
assign_point_from_interface(state_current.accelerations, joint_state_interface_[2]);
201182
} else {
202183
// Make empty so the property is ignored during interpolation
@@ -230,22 +211,16 @@ JointTrajectoryController::update()
230211
const bool before_last_point = end_segment_itr != (*traj_point_active_ptr_)->end();
231212

232213
// set values for next hardware write()
233-
if (check_if_interface_type_exists(
234-
command_interface_types_, hardware_interface::HW_IF_POSITION))
235-
{
214+
if (has_position_command_interface_) {
236215
assign_interface_from_point(joint_command_interface_[0], state_desired.positions);
237216
}
238-
if (check_if_interface_type_exists(
239-
command_interface_types_, hardware_interface::HW_IF_VELOCITY))
240-
{
217+
if (has_velocity_command_interface_) {
241218
assign_interface_from_point(joint_command_interface_[1], state_desired.velocities);
242219
}
243-
if (check_if_interface_type_exists(
244-
command_interface_types_, hardware_interface::HW_IF_ACCELERATION))
245-
{
220+
if (has_acceleration_command_interface_) {
246221
assign_interface_from_point(joint_command_interface_[2], state_desired.accelerations);
247222
}
248-
// TODO(anyone): Add here "if using_closed_loop_hw_interface_adapter" (see ROS1)
223+
// TODO(anyone): Add here "if using_closed_loop_hw_interface_adapter" (see ROS1) - #171
249224
// if (check_if_interface_type_exist(
250225
// command_interface_types_, hardware_interface::HW_IF_EFFORT)) {
251226
// assign_interface_from_point(joint_command_interface_[3], state_desired.effort);
@@ -382,7 +357,7 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
382357
// 2. position [velocity, [acceleration]]
383358

384359
// effort can't be combined with other interfaces
385-
if (check_if_interface_type_exists(command_interface_types_, hardware_interface::HW_IF_EFFORT)) {
360+
if (contains_interface_type(command_interface_types_, hardware_interface::HW_IF_EFFORT)) {
386361
if (command_interface_types_.size() == 1) {
387362
// TODO(anyone): This flag is not used for now
388363
// There should be PID-approach used as in ROS1:
@@ -397,28 +372,32 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
397372
}
398373
}
399374

400-
if (check_if_interface_type_exists(
401-
command_interface_types_, hardware_interface::HW_IF_VELOCITY))
402-
{
375+
if (contains_interface_type(command_interface_types_, hardware_interface::HW_IF_POSITION)) {
376+
has_position_command_interface_ = true;
377+
}
378+
if (contains_interface_type(command_interface_types_, hardware_interface::HW_IF_VELOCITY)) {
379+
has_velocity_command_interface_ = true;
380+
}
381+
if (contains_interface_type(command_interface_types_, hardware_interface::HW_IF_ACCELERATION)) {
382+
has_acceleration_command_interface_ = true;
383+
}
384+
385+
if (has_velocity_command_interface_) {
403386
// if there is only velocity then use also PID adapter
404387
if (command_interface_types_.size() == 1) {
405388
use_closed_loop_pid_adapter = true;
406389
// TODO(anyone): remove this when implemented
407390
RCLCPP_ERROR(logger, "using 'velocity' command interface alone is not yet implemented yet.");
408391
return CallbackReturn::ERROR;
409392
// if velocity interface can be used without position if multiple defined
410-
} else if (!check_if_interface_type_exists(
411-
command_interface_types_, hardware_interface::HW_IF_POSITION))
412-
{
393+
} else if (!has_position_command_interface_) {
413394
RCLCPP_ERROR(
414395
logger, "'velocity' command interface can be used either alone or 'position' "
415396
"interface has to be present.");
416397
return CallbackReturn::ERROR;
417398
}
418399
// invalid: acceleration is defined and no velocity
419-
} else if (check_if_interface_type_exists(
420-
command_interface_types_, hardware_interface::HW_IF_ACCELERATION))
421-
{
400+
} else if (has_acceleration_command_interface_) {
422401
RCLCPP_ERROR(
423402
logger, "'acceleration' command interface can only be used if 'velocity' and "
424403
"'position' interfaces are present");
@@ -435,7 +414,7 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
435414
return CallbackReturn::ERROR;
436415
}
437416

438-
if (check_if_interface_type_exists(state_interface_types_, hardware_interface::HW_IF_EFFORT)) {
417+
if (contains_interface_type(state_interface_types_, hardware_interface::HW_IF_EFFORT)) {
439418
RCLCPP_ERROR(logger, "State interface type 'effort' not allowed!");
440419
return CallbackReturn::ERROR;
441420
}
@@ -453,19 +432,21 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
453432
}
454433
}
455434

456-
if (check_if_interface_type_exists(state_interface_types_, hardware_interface::HW_IF_VELOCITY)) {
457-
if (!check_if_interface_type_exists(
458-
state_interface_types_,
459-
hardware_interface::HW_IF_POSITION))
460-
{
435+
if (contains_interface_type(state_interface_types_, hardware_interface::HW_IF_VELOCITY)) {
436+
has_velocity_state_interface_ = true;
437+
}
438+
if (contains_interface_type(state_interface_types_, hardware_interface::HW_IF_ACCELERATION)) {
439+
has_acceleration_state_interface_ = true;
440+
}
441+
442+
if (has_velocity_state_interface_) {
443+
if (!contains_interface_type(state_interface_types_, hardware_interface::HW_IF_POSITION)) {
461444
RCLCPP_ERROR(
462445
logger, "'velocity' state interface cannot be used if 'position' interface "
463446
"is missing.");
464447
return CallbackReturn::ERROR;
465448
}
466-
} else if (check_if_interface_type_exists(
467-
state_interface_types_, hardware_interface::HW_IF_ACCELERATION))
468-
{
449+
} else if (has_acceleration_state_interface_) {
469450
RCLCPP_ERROR(
470451
logger, "'acceleration' state interface cannot be used if 'position' and 'velocity' "
471452
"interfaces are not present.");
@@ -543,14 +524,11 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
543524
state_publisher_->msg_.desired.accelerations.resize(n_joints);
544525
state_publisher_->msg_.actual.positions.resize(n_joints);
545526
state_publisher_->msg_.error.positions.resize(n_joints);
546-
if (check_if_interface_type_exists(state_interface_types_, hardware_interface::HW_IF_VELOCITY)) {
527+
if (has_velocity_state_interface_) {
547528
state_publisher_->msg_.actual.velocities.resize(n_joints);
548529
state_publisher_->msg_.error.velocities.resize(n_joints);
549530
}
550-
if (check_if_interface_type_exists(
551-
state_interface_types_,
552-
hardware_interface::HW_IF_ACCELERATION))
553-
{
531+
if (has_acceleration_state_interface_) {
554532
state_publisher_->msg_.actual.accelerations.resize(n_joints);
555533
state_publisher_->msg_.error.accelerations.resize(n_joints);
556534
}
@@ -754,15 +732,11 @@ void JointTrajectoryController::publish_state(
754732
state_publisher_->msg_.desired.accelerations = desired_state.accelerations;
755733
state_publisher_->msg_.actual.positions = current_state.positions;
756734
state_publisher_->msg_.error.positions = state_error.positions;
757-
if (check_if_interface_type_exists(
758-
state_interface_types_, hardware_interface::HW_IF_VELOCITY))
759-
{
735+
if (has_velocity_state_interface_) {
760736
state_publisher_->msg_.actual.velocities = current_state.velocities;
761737
state_publisher_->msg_.error.velocities = state_error.velocities;
762738
}
763-
if (check_if_interface_type_exists(
764-
state_interface_types_, hardware_interface::HW_IF_ACCELERATION))
765-
{
739+
if (has_acceleration_state_interface_) {
766740
state_publisher_->msg_.actual.accelerations = current_state.accelerations;
767741
state_publisher_->msg_.error.accelerations = state_error.accelerations;
768742
}

0 commit comments

Comments
 (0)