@@ -29,7 +29,9 @@ DistanceTraveledCondition::DistanceTraveledCondition(
2929 const BT ::NodeConfiguration & conf)
3030: BT ::ConditionNode(condition_name, conf),
3131 distance_ (1.0 ),
32- transform_tolerance_(0.1 )
32+ transform_tolerance_(0.1 ),
33+ is_global_(false ),
34+ current_run_id_(" " )
3335{
3436}
3537
@@ -45,19 +47,45 @@ void DistanceTraveledCondition::initialize()
4547 node_, " global_frame" , this );
4648 robot_base_frame_ = BT ::deconflictPortAndParamFrame<std::string>(
4749 node_, " robot_base_frame" , this );
50+ is_global_ = node_->declare_or_get_parameter (" is_global" , false );
4851}
4952
5053BT ::NodeStatus DistanceTraveledCondition::tick ()
5154{
5255 if (!BT::isStatusActive (status ())) {
5356 initialize ();
54- if (!nav2_util::getCurrentPose (
55- start_pose_, *tf_, global_frame_, robot_base_frame_,
56- transform_tolerance_))
57- {
58- RCLCPP_DEBUG (node_->get_logger (), " Current robot pose is not available." );
57+ if (!is_global_) {
58+ if (!nav2_util::getCurrentPose (
59+ start_pose_, *tf_, global_frame_, robot_base_frame_,
60+ transform_tolerance_))
61+ {
62+ RCLCPP_DEBUG (node_->get_logger (), " Current robot pose is not available." );
63+ }
64+ return BT ::NodeStatus::FAILURE ;
65+ } else if (start_pose_.header .frame_id .empty ()) {
66+ if (!nav2_util::getCurrentPose (
67+ start_pose_, *tf_, global_frame_, robot_base_frame_,
68+ transform_tolerance_))
69+ {
70+ RCLCPP_DEBUG (node_->get_logger (), " Current robot pose is not available." );
71+ }
72+ }
73+ }
74+
75+ // Global mode: on RunID change fall through without resetting start_pose_
76+ if (is_global_) {
77+ std::string new_run_id;
78+ try {
79+ new_run_id = config ().blackboard ->template get <std::string>(" run_id" );
80+ } catch (const std::exception & e) {
81+ throw std::runtime_error (
82+ " is_global=true requires 'run_id' to be set on the blackboard for condition: " +
83+ std::string (name ()));
84+ }
85+ if (new_run_id != current_run_id_) {
86+ current_run_id_ = new_run_id;
87+ // Do not reset start_pose_ to preserve distance measurement across runs
5988 }
60- return BT ::NodeStatus::FAILURE ;
6189 }
6290
6391 // Determine distance travelled since we've started this iteration
0 commit comments