Skip to content

Commit cbe0645

Browse files
authored
Refactor JTC command interface assignment (#2489)
1 parent 5e2efbb commit cbe0645

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
147147
// Configuration for every joint if it wraps around (ie. is continuous, position error is
148148
// normalized)
149149
std::vector<bool> joints_angle_wraparound_;
150-
// reserved storage for result of the command when closed loop pid adapter is used
151-
std::vector<double> tmp_command_;
150+
// Preallocated storage for closed-loop PID command output.
151+
std::vector<double> closed_loop_pid_command_;
152152

153153
// If true, enable calculations to stop all joints using constant deceleration
154154
bool should_decelerate_on_cancel_ = false;

joint_trajectory_controller/src/joint_trajectory_controller.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ controller_interface::return_type JointTrajectoryController::update(
459459
// If effort interface only, add desired effort as feed forward
460460
// If velocity interface, ignore desired effort
461461
size_t index_cmd_joint = map_cmd_to_joints_[i];
462-
tmp_command_[index_cmd_joint] =
462+
closed_loop_pid_command_[index_cmd_joint] =
463463
(command_next_.velocities[index_cmd_joint] * ff_velocity_scale_[i]) +
464464
(has_effort_command_interface_ ? command_next_.effort[index_cmd_joint] : 0.0) +
465465
pids_[i]->compute_command(
@@ -475,30 +475,19 @@ controller_interface::return_type JointTrajectoryController::update(
475475
}
476476
if (has_velocity_command_interface_)
477477
{
478-
if (use_closed_loop_pid_adapter_)
479-
{
480-
assign_interface_from_point(joint_command_interface_[1], tmp_command_);
481-
}
482-
else
483-
{
484-
assign_interface_from_point(joint_command_interface_[1], command_next_.velocities);
485-
}
478+
assign_interface_from_point(
479+
joint_command_interface_[1],
480+
use_closed_loop_pid_adapter_ ? closed_loop_pid_command_ : command_next_.velocities);
486481
}
487482
if (has_acceleration_command_interface_)
488483
{
489484
assign_interface_from_point(joint_command_interface_[2], command_next_.accelerations);
490485
}
491486
if (has_effort_command_interface_)
492487
{
493-
if (use_closed_loop_pid_adapter_)
494-
{
495-
assign_interface_from_point(joint_command_interface_[3], tmp_command_);
496-
}
497-
else
498-
{
499-
// If position and effort command interfaces, only pass desired effort
500-
assign_interface_from_point(joint_command_interface_[3], state_desired_.effort);
501-
}
488+
assign_interface_from_point(
489+
joint_command_interface_[3],
490+
use_closed_loop_pid_adapter_ ? closed_loop_pid_command_ : state_desired_.effort);
502491
}
503492

504493
// store the previous command and time used in open-loop control mode
@@ -941,7 +930,7 @@ controller_interface::CallbackReturn JointTrajectoryController::on_configure(
941930
(has_velocity_command_interface_ && params_.command_interfaces.size() == 1) ||
942931
(has_effort_command_interface_ && params_.command_interfaces.size() == 1);
943932

944-
tmp_command_.resize(dof_, 0.0);
933+
closed_loop_pid_command_.resize(dof_, 0.0);
945934

946935
if (use_closed_loop_pid_adapter_)
947936
{

0 commit comments

Comments
 (0)