Skip to content

Commit 9ce288b

Browse files
authored
[JTC] Command final waypoint identically when traj_point_active_ptr_ is nullptr (#682)
1 parent cd40ec0 commit 9ce288b

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

joint_trajectory_controller/src/joint_trajectory_controller.cpp

+51-51
Original file line numberDiff line numberDiff line change
@@ -241,57 +241,6 @@ controller_interface::return_type JointTrajectoryController::update(
241241
}
242242
}
243243

244-
// set values for next hardware write() if tolerance is met
245-
if (!tolerance_violated_while_moving && within_goal_time)
246-
{
247-
if (use_closed_loop_pid_adapter_)
248-
{
249-
// Update PIDs
250-
for (auto i = 0ul; i < dof_; ++i)
251-
{
252-
tmp_command_[i] = (state_desired_.velocities[i] * ff_velocity_scale_[i]) +
253-
pids_[i]->computeCommand(
254-
state_error_.positions[i], state_error_.velocities[i],
255-
(uint64_t)period.nanoseconds());
256-
}
257-
}
258-
259-
// set values for next hardware write()
260-
if (has_position_command_interface_)
261-
{
262-
assign_interface_from_point(joint_command_interface_[0], state_desired_.positions);
263-
}
264-
if (has_velocity_command_interface_)
265-
{
266-
if (use_closed_loop_pid_adapter_)
267-
{
268-
assign_interface_from_point(joint_command_interface_[1], tmp_command_);
269-
}
270-
else
271-
{
272-
assign_interface_from_point(joint_command_interface_[1], state_desired_.velocities);
273-
}
274-
}
275-
if (has_acceleration_command_interface_)
276-
{
277-
assign_interface_from_point(joint_command_interface_[2], state_desired_.accelerations);
278-
}
279-
if (has_effort_command_interface_)
280-
{
281-
if (use_closed_loop_pid_adapter_)
282-
{
283-
assign_interface_from_point(joint_command_interface_[3], tmp_command_);
284-
}
285-
else
286-
{
287-
assign_interface_from_point(joint_command_interface_[3], state_desired_.effort);
288-
}
289-
}
290-
291-
// store the previous command. Used in open-loop control mode
292-
last_commanded_state_ = state_desired_;
293-
}
294-
295244
const auto active_goal = *rt_active_goal_.readFromRT();
296245
if (active_goal)
297246
{
@@ -359,6 +308,57 @@ controller_interface::return_type JointTrajectoryController::update(
359308
set_hold_position();
360309
RCLCPP_ERROR(get_node()->get_logger(), "Holding position due to state tolerance violation");
361310
}
311+
312+
// set values for next hardware write() if tolerance is met
313+
if (!tolerance_violated_while_moving && within_goal_time)
314+
{
315+
if (use_closed_loop_pid_adapter_)
316+
{
317+
// Update PIDs
318+
for (auto i = 0ul; i < dof_; ++i)
319+
{
320+
tmp_command_[i] = (state_desired_.velocities[i] * ff_velocity_scale_[i]) +
321+
pids_[i]->computeCommand(
322+
state_error_.positions[i], state_error_.velocities[i],
323+
(uint64_t)period.nanoseconds());
324+
}
325+
}
326+
327+
// set values for next hardware write()
328+
if (has_position_command_interface_)
329+
{
330+
assign_interface_from_point(joint_command_interface_[0], state_desired_.positions);
331+
}
332+
if (has_velocity_command_interface_)
333+
{
334+
if (traj_point_active_ptr_ && use_closed_loop_pid_adapter_)
335+
{
336+
assign_interface_from_point(joint_command_interface_[1], tmp_command_);
337+
}
338+
else
339+
{
340+
assign_interface_from_point(joint_command_interface_[1], state_desired_.velocities);
341+
}
342+
}
343+
if (has_acceleration_command_interface_)
344+
{
345+
assign_interface_from_point(joint_command_interface_[2], state_desired_.accelerations);
346+
}
347+
if (has_effort_command_interface_)
348+
{
349+
if (traj_point_active_ptr_ && use_closed_loop_pid_adapter_)
350+
{
351+
assign_interface_from_point(joint_command_interface_[3], tmp_command_);
352+
}
353+
else
354+
{
355+
assign_interface_from_point(joint_command_interface_[3], state_desired_.effort);
356+
}
357+
}
358+
359+
// store the previous command. Used in open-loop control mode
360+
last_commanded_state_ = state_desired_;
361+
}
362362
}
363363
}
364364

0 commit comments

Comments
 (0)