Skip to content

Commit 8e6dd3e

Browse files
Use box for tolerances
1 parent b21a7e1 commit 8e6dd3e

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "realtime_tools/realtime_buffer.hpp"
4242
#include "realtime_tools/realtime_publisher.hpp"
4343
#include "realtime_tools/realtime_server_goal_handle.hpp"
44+
#include "realtime_tools/realtime_thread_safe_box.hpp"
4445
#include "trajectory_msgs/msg/joint_trajectory.hpp"
4546
#include "trajectory_msgs/msg/joint_trajectory_point.hpp"
4647

@@ -235,7 +236,9 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
235236
// the tolerances from the node parameter
236237
SegmentTolerances default_tolerances_;
237238
// the tolerances used for the current goal
238-
realtime_tools::RealtimeBuffer<SegmentTolerances> active_tolerances_;
239+
realtime_tools::RealtimeThreadSafeBox<SegmentTolerances> goal_tolerances_;
240+
// preallocated memory for tolerances used in RT loop
241+
SegmentTolerances active_tol_;
239242

240243
void preempt_active_goal();
241244

joint_trajectory_controller/src/joint_trajectory_controller.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,16 @@ controller_interface::return_type JointTrajectoryController::update(
253253
bool outside_goal_tolerance = false;
254254
bool within_goal_time = true;
255255
const bool before_last_point = end_segment_itr != current_trajectory_->end();
256-
auto active_tol = active_tolerances_.readFromRT();
256+
auto active_tol_op = goal_tolerances_.try_get();
257+
if (active_tol_op.has_value())
258+
{
259+
active_tol_ = active_tol_op.value();
260+
}
261+
else
262+
{
263+
// fallback if try_get fails
264+
active_tol_ = default_tolerances_;
265+
}
257266

258267
// have we reached the end, are not holding position, and is a timeout configured?
259268
// Check independently of other tolerances
@@ -278,22 +287,22 @@ controller_interface::return_type JointTrajectoryController::update(
278287
if (
279288
(before_last_point || first_sample) && !rt_is_holding_ &&
280289
!check_state_tolerance_per_joint(
281-
state_error_, index, active_tol->state_tolerance[index], true /* show_errors */))
290+
state_error_, index, active_tol_.state_tolerance[index], true /* show_errors */))
282291
{
283292
tolerance_violated_while_moving = true;
284293
}
285294
// past the final point, check that we end up inside goal tolerance
286295
if (
287296
!before_last_point && !rt_is_holding_ &&
288297
!check_state_tolerance_per_joint(
289-
state_error_, index, active_tol->goal_state_tolerance[index], false /* show_errors */))
298+
state_error_, index, active_tol_.goal_state_tolerance[index], false /* show_errors */))
290299
{
291300
outside_goal_tolerance = true;
292301

293-
if (active_tol->goal_time_tolerance != 0.0)
302+
if (active_tol_.goal_time_tolerance != 0.0)
294303
{
295304
// if we exceed goal_time_tolerance set it to aborted
296-
if (time_difference > active_tol->goal_time_tolerance)
305+
if (time_difference > active_tol_.goal_time_tolerance)
297306
{
298307
within_goal_time = false;
299308
// print once, goal will be aborted afterwards
@@ -925,7 +934,7 @@ controller_interface::CallbackReturn JointTrajectoryController::on_configure(
925934

926935
// parse remaining parameters
927936
default_tolerances_ = get_segment_tolerances(logger, params_);
928-
active_tolerances_.initRT(default_tolerances_);
937+
goal_tolerances_.set(default_tolerances_);
929938
const std::string interpolation_string =
930939
get_node()->get_parameter("interpolation_method").as_string();
931940
interpolation_method_ = interpolation_methods::from_string(interpolation_string);
@@ -1412,7 +1421,7 @@ void JointTrajectoryController::goal_accepted_callback(
14121421

14131422
// Update tolerances if specified in the goal
14141423
auto logger = this->get_node()->get_logger();
1415-
active_tolerances_.writeFromNonRT(get_segment_tolerances(
1424+
goal_tolerances_.set(get_segment_tolerances(
14161425
logger, default_tolerances_, *(goal_handle->get_goal()), params_.joints));
14171426

14181427
// Set smartpointer to expire for create_wall_timer to delete previous entry from timer list

joint_trajectory_controller/test/test_trajectory_controller_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class TestableJointTrajectoryController
170170

171171
joint_trajectory_controller::SegmentTolerances get_active_tolerances()
172172
{
173-
return *(active_tolerances_.readFromRT());
173+
return goal_tolerances_.get();
174174
}
175175

176176
std::vector<PidPtr> get_pids() const { return pids_; }

0 commit comments

Comments
 (0)