SMACC2
Loading...
Searching...
No Matches
cl_nav2z::odom_tracker::CpOdomTracker Class Reference

#include <cp_odom_tracker.hpp>

Inheritance diagram for cl_nav2z::odom_tracker::CpOdomTracker:
Inheritance graph
Collaboration diagram for cl_nav2z::odom_tracker::CpOdomTracker:
Collaboration graph

Classes

struct  PathInfo
 

Public Member Functions

 CpOdomTracker (std::string odomtopicName="/odom", std::string odomFrame="odom", OdomTrackerStrategy strategy=OdomTrackerStrategy::ODOMETRY_SUBSCRIBER)
 
virtual void processNewPose (const geometry_msgs::msg::PoseStamped &odom)
 odom callback: Updates the path - this must be called periodically for each odometry message.
 
virtual void odomMessageCallback (const nav_msgs::msg::Odometry::SharedPtr odom)
 
virtual void update ()
 
void setWorkingMode (WorkingMode workingMode)
 
void setPublishMessages (bool value)
 
void pushPath ()
 
void pushPath (std::string pathname)
 
void popPath (int pathCount=1, bool keepPreviousPath=false)
 
void clearPath ()
 
void setStartPoint (const geometry_msgs::msg::PoseStamped &pose)
 
void setStartPoint (const geometry_msgs::msg::Pose &pose)
 
void setCurrentMotionGoal (const geometry_msgs::msg::PoseStamped &pose)
 
void setCurrentPathName (const std::string &currentPathName)
 
std::optional< geometry_msgs::msg::PoseStamped > getCurrentMotionGoal ()
 
nav_msgs::msg::Path getPath ()
 
void logStateString (bool debug=true)
 
void updateParameters ()
 
void setOdomFrame (std::string odomFrame)
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
 ISmaccComponent (const ISmaccComponent &)=delete
 
ISmaccComponent & operator= (const ISmaccComponent &)=delete
 
 ISmaccComponent (ISmaccComponent &&)=delete
 
ISmaccComponent & operator= (ISmaccComponent &&)=delete
 
virtual std::string getName () const
 

Protected Member Functions

void onInitialize () override
 
void logStateStringLocked (bool debug=true)
 
virtual void rtPublishPaths (rclcpp::Time timestamp)
 
virtual bool updateRecordPath (const geometry_msgs::msg::PoseStamped &odom)
 
virtual bool updateClearPath (const geometry_msgs::msg::PoseStamped &odom)
 
void updateAggregatedStackPath ()
 
rcl_interfaces::msg::SetParametersResult parametersCallback (const std::vector< rclcpp::Parameter > &parameters)
 
- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (const std::string &name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 

Protected Attributes

rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr robotBasePathPub_
 
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr robotBasePathStackedPub_
 
rclcpp::Subscription< nav_msgs::msg::Odometry >::SharedPtr odomSub_
 
cl_nav2z::CpPose * robotPose_ = nullptr
 
rclcpp::TimerBase::SharedPtr robotPoseTimer_
 
double recordPointDistanceThreshold_ = 0.005
 How much distance there is between two points of the path.
 
double recordAngularDistanceThreshold_ = 0.1
 Meters.
 
double clearPointDistanceThreshold_ = 0.05
 rads
 
double clearAngularDistanceThreshold_ = 0.1
 rads
 
std::string odomFrame_
 
std::string odomTopicName_
 
bool publishMessages
 
nav_msgs::msg::Path baseTrajectory_
 Processed path for the mouth of the reel.
 
WorkingMode workingMode_
 
std::vector< nav_msgs::msg::Path > pathStack_
 
std::vector< PathInfo > pathInfos_
 
nav_msgs::msg::Path aggregatedStackPathMsg_
 
OdomTrackerStrategy strategy_
 
std::optional< geometry_msgs::msg::PoseStamped > currentMotionGoal_
 
std::string currentPathName_
 
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr param_callback_handle_
 
std::mutex m_mutex_
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_ = nullptr
 
ISmaccClient * owner_ = nullptr
 

Detailed Description

This object tracks and saves the trajectories performed by the vehicle so that they can be used later to execute operations such as "undo motions"

Definition at line 60 of file cp_odom_tracker.hpp.

Constructor & Destructor Documentation

◆ CpOdomTracker()

cl_nav2z::odom_tracker::CpOdomTracker::CpOdomTracker ( std::string odomtopicName = "/odom",
std::string odomFrame = "odom",
OdomTrackerStrategy strategy = OdomTrackerStrategy::ODOMETRY_SUBSCRIBER )

Member Function Documentation

◆ clearPath()

void cl_nav2z::odom_tracker::CpOdomTracker::clearPath ( )

Definition at line 340 of file cp_odom_tracker.cpp.

341{
342 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex acquire to clear path");
343 std::lock_guard<std::mutex> lock(m_mutex_);
344 baseTrajectory_.poses.clear();
345
346 rtPublishPaths(getNode()->now());
347 this->logStateStringLocked();
349
350 this->currentMotionGoal_.reset();
351}
std::optional< geometry_msgs::msg::PoseStamped > currentMotionGoal_
nav_msgs::msg::Path baseTrajectory_
Processed path for the mouth of the reel.
virtual void rtPublishPaths(rclcpp::Time timestamp)
rclcpp::Logger getLogger() const
rclcpp::Node::SharedPtr getNode()

References baseTrajectory_, currentMotionGoal_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), logStateStringLocked(), m_mutex_, rtPublishPaths(), and updateAggregatedStackPath().

Referenced by cl_nav2z::CbNavigateBackwards::onEntry(), cl_nav2z::CbTrackPathOdometry::onEntry(), and cl_nav2z::CbTrackPathSLAM::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCurrentMotionGoal()

std::optional< geometry_msgs::msg::PoseStamped > cl_nav2z::odom_tracker::CpOdomTracker::getCurrentMotionGoal ( )

Definition at line 400 of file cp_odom_tracker.cpp.

401{
402 std::lock_guard<std::mutex> lock(m_mutex_);
403 return this->currentMotionGoal_;
404}

References currentMotionGoal_, and m_mutex_.

Referenced by cl_nav2z::CbRetry< TCbRelativeMotion >::onEntry().

Here is the caller graph for this function:

◆ getPath()

nav_msgs::msg::Path cl_nav2z::odom_tracker::CpOdomTracker::getPath ( )

Definition at line 406 of file cp_odom_tracker.cpp.

407{
408 std::lock_guard<std::mutex> lock(m_mutex_);
409 return this->baseTrajectory_;
410}

References baseTrajectory_, and m_mutex_.

Referenced by cl_nav2z::CbUndoPathBackwards::onEntry().

Here is the caller graph for this function:

◆ logStateString()

void cl_nav2z::odom_tracker::CpOdomTracker::logStateString ( bool debug = true)

Definition at line 292 of file cp_odom_tracker.cpp.

293{
294 std::lock_guard<std::mutex> lock(m_mutex_);
295 this->logStateStringLocked(debug);
296}

References logStateStringLocked(), and m_mutex_.

Referenced by cl_nav2z::CbUndoPathBackwards::onEntry(), and cl_nav2z::CbUndoPathBackwards::onExit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logStateStringLocked()

void cl_nav2z::odom_tracker::CpOdomTracker::logStateStringLocked ( bool debug = true)
protected

Definition at line 298 of file cp_odom_tracker.cpp.

299{
300 std::stringstream ss;
301 ss << "--- odom tracker state ---" << '\n';
302 ss
303 << " - path stack -" << currentPathName_ << " - size:"
304 << pathStack_.size()
305 //<< " goal: " << (getCurrentMotionGoal()? getCurrentMotionGoal()->pose: geometry_msgs::msg::Pose())
306 << '\n';
307 ss << " - [STACK-HEAD active path size: " << baseTrajectory_.poses.size() << "]" << '\n';
308 int i = 0;
309 for (auto & p : pathStack_ | boost::adaptors::reversed)
310 {
311 const auto & pathinfo = pathInfos_[pathInfos_.size() - i - 1];
312 std::string goalstr = "[]";
313 if (pathinfo.goalPose)
314 {
315 std::stringstream goalss;
316 goalss << *(pathinfo.goalPose);
317 goalstr = goalss.str();
318 }
319
320 ss << " - p " << i << "[" << p.header.stamp << "], size: " << p.poses.size() << " - "
321 << pathinfo.name << " - goal: " << goalstr << '\n';
322 i++;
323 }
324 ss << "---";
325
326 if (this->odomSub_ != nullptr && this->odomSub_->get_publisher_count() == 0)
327 {
328 ss << '\n'
329 << "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to "
330 "the odometry topic"
331 << '\n';
332 }
333
334 if (debug)
335 RCLCPP_DEBUG(getLogger(), "%s", ss.str().c_str());
336 else
337 RCLCPP_INFO(getLogger(), "%s", ss.str().c_str());
338}
rclcpp::Subscription< nav_msgs::msg::Odometry >::SharedPtr odomSub_
std::vector< nav_msgs::msg::Path > pathStack_

References baseTrajectory_, currentPathName_, smacc2::ISmaccComponent::getLogger(), odomSub_, pathInfos_, and pathStack_.

Referenced by clearPath(), logStateString(), popPath(), and pushPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ odomMessageCallback()

void cl_nav2z::odom_tracker::CpOdomTracker::odomMessageCallback ( const nav_msgs::msg::Odometry::SharedPtr odom)
virtual

odomMessageCallback()

Definition at line 586 of file cp_odom_tracker.cpp.

587{
588 geometry_msgs::msg::PoseStamped base_pose;
589 base_pose.pose = odom->pose.pose;
590 base_pose.header = odom->header;
591
592 processNewPose(base_pose);
593}
virtual void processNewPose(const geometry_msgs::msg::PoseStamped &odom)
odom callback: Updates the path - this must be called periodically for each odometry message.

References processNewPose().

Referenced by onInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onInitialize()

void cl_nav2z::odom_tracker::CpOdomTracker::onInitialize ( )
overrideprotectedvirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 62 of file cp_odom_tracker.cpp.

63{
64 auto nh = getNode();
65 RCLCPP_WARN(getLogger(), "[CpOdomTracker] Initializing Odometry Tracker");
66
67 parameterDeclareAndtryGetOrSet(nh, "odom_frame", this->odomFrame_);
69 nh, "record_point_distance_threshold", recordPointDistanceThreshold_);
71 nh, "record_angular_distance_threshold", recordAngularDistanceThreshold_);
73 nh, "clear_point_distance_threshold", clearPointDistanceThreshold_);
75 nh, "clear_angular_distance_threshold", clearAngularDistanceThreshold_);
76
77 param_callback_handle_ = getNode()->add_on_set_parameters_callback(
78 std::bind(&CpOdomTracker::parametersCallback, this, std::placeholders::_1));
79
81 nh->create_publisher<nav_msgs::msg::Path>("odom_tracker_path", rclcpp::QoS(1));
82
84 nh->create_publisher<nav_msgs::msg::Path>("odom_tracker_stacked_path", rclcpp::QoS(1));
85
87 {
88 RCLCPP_INFO_STREAM(
89 nh->get_logger(), "[CpOdomTracker] subscribing to odom topic: " << odomTopicName_);
90
91 rclcpp::SensorDataQoS qos;
92 odomSub_ = nh->create_subscription<nav_msgs::msg::Odometry>(
93 odomTopicName_, qos,
94 std::bind(&CpOdomTracker::odomMessageCallback, this, std::placeholders::_1));
95 }
97 {
98 this->requiresComponent(robotPose_, ComponentRequirement::HARD);
99 robotPoseTimer_ = nh->create_wall_timer(
100 std::chrono::milliseconds(100), std::bind(&CpOdomTracker::update, this));
101 }
102 else
103 {
104 RCLCPP_ERROR_STREAM(
105 nh->get_logger(), "[CpOdomTracker] unknown strategy: " << (int)this->strategy_);
106 }
107}
double recordPointDistanceThreshold_
How much distance there is between two points of the path.
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr param_callback_handle_
virtual void odomMessageCallback(const nav_msgs::msg::Odometry::SharedPtr odom)
rclcpp::TimerBase::SharedPtr robotPoseTimer_
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr robotBasePathStackedPub_
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr robotBasePathPub_
rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector< rclcpp::Parameter > &parameters)
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
void parameterDeclareAndtryGetOrSet(rclcpp::Node::SharedPtr &node, std::string param_name, T &value)

References clearAngularDistanceThreshold_, clearPointDistanceThreshold_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), cl_nav2z::odom_tracker::ODOMETRY_SUBSCRIBER, odomFrame_, odomMessageCallback(), odomSub_, odomTopicName_, param_callback_handle_, cl_nav2z::odom_tracker::parameterDeclareAndtryGetOrSet(), parametersCallback(), cl_nav2z::odom_tracker::POSE_COMPONENT, recordAngularDistanceThreshold_, recordPointDistanceThreshold_, smacc2::ISmaccComponent::requiresComponent(), robotBasePathPub_, robotBasePathStackedPub_, robotPose_, robotPoseTimer_, strategy_, and update().

Here is the call graph for this function:

◆ parametersCallback()

rcl_interfaces::msg::SetParametersResult cl_nav2z::odom_tracker::CpOdomTracker::parametersCallback ( const std::vector< rclcpp::Parameter > & parameters)
protected

parametersCallback()

Definition at line 114 of file cp_odom_tracker.cpp.

116{
117 std::lock_guard<std::mutex> lock(m_mutex_);
118 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex acquire");
119
120 for (const auto & param : parameters)
121 {
122 if (param.get_name() == "record_point_distance_threshold")
123 {
124 recordPointDistanceThreshold_ = param.as_double();
125 }
126 else if (param.get_name() == "record_angular_distance_threshold")
127 {
128 recordAngularDistanceThreshold_ = param.as_double();
129 }
130 else if (param.get_name() == "clear_point_distance_threshold")
131 {
132 clearPointDistanceThreshold_ = param.as_double();
133 }
134 else if (param.get_name() == "clear_angular_distance_threshold")
135 {
136 clearAngularDistanceThreshold_ = param.as_double();
137 }
138 else if (param.get_name() == "odom_frame")
139 {
140 odomFrame_ = param.as_string();
141 }
142 }
143
144 rcl_interfaces::msg::SetParametersResult result;
145 result.successful = true;
146 result.reason = "success";
147 return result;
148}

References clearAngularDistanceThreshold_, clearPointDistanceThreshold_, smacc2::ISmaccComponent::getLogger(), m_mutex_, odomFrame_, recordAngularDistanceThreshold_, and recordPointDistanceThreshold_.

Referenced by onInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ popPath()

void cl_nav2z::odom_tracker::CpOdomTracker::popPath ( int pathCount = 1,
bool keepPreviousPath = false )

Definition at line 247 of file cp_odom_tracker.cpp.

248{
249 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex acquire to pop path");
250 std::lock_guard<std::mutex> lock(m_mutex_);
251
252 RCLCPP_INFO(getLogger(), "POP PATH ENTRY");
253 this->logStateStringLocked();
254
255 if (this->odomSub_ != nullptr && this->odomSub_->get_publisher_count() == 0)
256 {
257 RCLCPP_ERROR_STREAM(
258 getLogger(),
259 "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to the "
260 "odometry topic");
261 }
262
263 if (!keepPreviousPath)
264 {
265 baseTrajectory_.poses.clear();
266 }
267
268 while (popCount > 0 && !pathStack_.empty())
269 {
270 auto & stackedPath = pathStack_.back().poses;
271 auto & stackedPathInfo = pathInfos_.back();
272
273 baseTrajectory_.poses.insert(
274 baseTrajectory_.poses.begin(), stackedPath.begin(), stackedPath.end());
275 this->currentMotionGoal_ = stackedPathInfo.goalPose;
276 pathStack_.pop_back();
277 pathInfos_.pop_back();
278 popCount--;
279
280 RCLCPP_INFO(getLogger(), "POP PATH Iteration ");
281 this->logStateStringLocked();
282 }
283
284 RCLCPP_INFO(getLogger(), "POP PATH EXITING");
285 this->logStateStringLocked();
286 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex release");
288
289 this->currentMotionGoal_.reset();
290}

References baseTrajectory_, currentMotionGoal_, smacc2::ISmaccComponent::getLogger(), logStateStringLocked(), m_mutex_, odomSub_, pathInfos_, pathStack_, and updateAggregatedStackPath().

Referenced by CpOdomTrackerActionServer::execute(), and cl_nav2z::CbUndoPathBackwards::onExit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processNewPose()

void cl_nav2z::odom_tracker::CpOdomTracker::processNewPose ( const geometry_msgs::msg::PoseStamped & odom)
virtual

odom callback: Updates the path - this must be called periodically for each odometry message.

processNewPose()

Definition at line 600 of file cp_odom_tracker.cpp.

601{
602 RCLCPP_INFO_THROTTLE(
603 getLogger(), *getNode()->get_clock(), 5000,
604 "[odom_tracker] processing odom msg update heartbeat");
605 std::lock_guard<std::mutex> lock(m_mutex_);
606
608 {
609 updateRecordPath(odom);
610 }
612 {
613 updateClearPath(odom);
614 }
615
616 // RCLCPP_WARN(getLogger(),"odomTracker odometry callback");
617 if (publishMessages)
618 {
619 rtPublishPaths(odom.header.stamp);
620 }
621
622 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex release");
623}
virtual bool updateRecordPath(const geometry_msgs::msg::PoseStamped &odom)
virtual bool updateClearPath(const geometry_msgs::msg::PoseStamped &odom)

References cl_nav2z::odom_tracker::CLEAR_PATH, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), m_mutex_, publishMessages, cl_nav2z::odom_tracker::RECORD_PATH, rtPublishPaths(), updateClearPath(), updateRecordPath(), and workingMode_.

Referenced by odomMessageCallback(), and update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushPath() [1/2]

void cl_nav2z::odom_tracker::CpOdomTracker::pushPath ( )

◆ pushPath() [2/2]

void cl_nav2z::odom_tracker::CpOdomTracker::pushPath ( std::string pathname)

Definition at line 211 of file cp_odom_tracker.cpp.

212{
213 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex acquire, to push path");
214 std::lock_guard<std::mutex> lock(m_mutex_);
215
216 this->logStateStringLocked(false);
217 if (this->odomSub_ != nullptr && this->odomSub_->get_publisher_count() == 0)
218 {
219 RCLCPP_ERROR_STREAM(
220 getLogger(),
221 "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to the "
222 "odometry topic");
223 }
224
226 pathStack_.push_back(baseTrajectory_);
227
228 geometry_msgs::msg::PoseStamped goalPose;
229 if (this->currentMotionGoal_) goalPose = *this->currentMotionGoal_;
230
231 RCLCPP_INFO_STREAM(
232 getLogger(), "[CpOdomTracker] currentPathName: " << pathname
233 << " size: " << baseTrajectory_.poses.size()
234 << " current motion goal: " << goalPose);
235
236 currentPathName_ = pathname;
237
238 // clean the current trajectory to start a new one
239 baseTrajectory_.poses.clear();
240
241 this->logStateStringLocked(false);
243
244 this->currentMotionGoal_.reset();
245}

References baseTrajectory_, currentMotionGoal_, currentPathName_, smacc2::ISmaccComponent::getLogger(), logStateStringLocked(), m_mutex_, odomSub_, pathInfos_, pathStack_, and updateAggregatedStackPath().

Here is the call graph for this function:

◆ rtPublishPaths()

void cl_nav2z::odom_tracker::CpOdomTracker::rtPublishPaths ( rclcpp::Time timestamp)
protectedvirtual

rtPublishPaths()

Definition at line 417 of file cp_odom_tracker.cpp.

418{
419 baseTrajectory_.header.stamp = timestamp;
421
422 aggregatedStackPathMsg_.header.stamp = timestamp;
424}

References aggregatedStackPathMsg_, baseTrajectory_, robotBasePathPub_, and robotBasePathStackedPub_.

Referenced by clearPath(), and processNewPose().

Here is the caller graph for this function:

◆ setCurrentMotionGoal()

void cl_nav2z::odom_tracker::CpOdomTracker::setCurrentMotionGoal ( const geometry_msgs::msg::PoseStamped & pose)

Definition at line 394 of file cp_odom_tracker.cpp.

395{
396 std::lock_guard<std::mutex> lock(m_mutex_);
397 this->currentMotionGoal_ = pose;
398}

References currentMotionGoal_, and m_mutex_.

Referenced by cl_nav2z::CbAbsoluteRotate::onEntry(), and cl_nav2z::CbNavigateForward::onEntry().

Here is the caller graph for this function:

◆ setCurrentPathName()

void cl_nav2z::odom_tracker::CpOdomTracker::setCurrentPathName ( const std::string & currentPathName)

Definition at line 353 of file cp_odom_tracker.cpp.

354{
355 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] set current path name: " << currentPathName);
356 currentPathName_ = currentPathName;
357}

References currentPathName_, and smacc2::ISmaccComponent::getLogger().

Here is the call graph for this function:

◆ setOdomFrame()

void cl_nav2z::odom_tracker::CpOdomTracker::setOdomFrame ( std::string odomFrame)
inline

Definition at line 120 of file cp_odom_tracker.hpp.

121 {
122 odomFrame_ = odomFrame;
123 getNode()->set_parameter(rclcpp::Parameter("odom_frame", odomFrame));
124 }

References smacc2::ISmaccComponent::getNode(), and odomFrame_.

Here is the call graph for this function:

◆ setPublishMessages()

void cl_nav2z::odom_tracker::CpOdomTracker::setPublishMessages ( bool value)

setPublishMessages()

Definition at line 200 of file cp_odom_tracker.cpp.

201{
202 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex acquire");
203 std::lock_guard<std::mutex> lock(m_mutex_);
204 publishMessages = value;
205 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex release");
207}

References m_mutex_, publishMessages, and updateAggregatedStackPath().

Referenced by CpOdomTrackerActionServer::execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setStartPoint() [1/2]

void cl_nav2z::odom_tracker::CpOdomTracker::setStartPoint ( const geometry_msgs::msg::Pose & pose)

Definition at line 374 of file cp_odom_tracker.cpp.

375{
376 std::lock_guard<std::mutex> lock(m_mutex_);
377 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] set current path starting point: " << pose);
378 geometry_msgs::msg::PoseStamped posestamped;
379 posestamped.header.frame_id = this->odomFrame_;
380 posestamped.header.stamp = getNode()->now();
381 posestamped.pose = pose;
382
383 if (baseTrajectory_.poses.size() > 0)
384 {
385 baseTrajectory_.poses[0] = posestamped;
386 }
387 else
388 {
389 baseTrajectory_.poses.push_back(posestamped);
390 }
392}

References baseTrajectory_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), m_mutex_, odomFrame_, and updateAggregatedStackPath().

Here is the call graph for this function:

◆ setStartPoint() [2/2]

void cl_nav2z::odom_tracker::CpOdomTracker::setStartPoint ( const geometry_msgs::msg::PoseStamped & pose)

Definition at line 359 of file cp_odom_tracker.cpp.

360{
361 std::lock_guard<std::mutex> lock(m_mutex_);
362 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] set current path starting point: " << pose);
363 if (baseTrajectory_.poses.size() > 0)
364 {
365 baseTrajectory_.poses[0] = pose;
366 }
367 else
368 {
369 baseTrajectory_.poses.push_back(pose);
370 }
372}

References baseTrajectory_, smacc2::ISmaccComponent::getLogger(), m_mutex_, and updateAggregatedStackPath().

Referenced by cl_nav2z::CbAbsoluteRotate::onEntry(), cl_nav2z::CbNavigateBackwards::onEntry(), cl_nav2z::CbNavigateForward::onEntry(), cl_nav2z::CbNavigateGlobalPosition::onEntry(), cl_nav2z::CbRotate::onEntry(), and cl_nav2z::CpWaypointNavigator::sendNextGoal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setWorkingMode()

void cl_nav2z::odom_tracker::CpOdomTracker::setWorkingMode ( WorkingMode workingMode)

setWorkingMode()

Definition at line 155 of file cp_odom_tracker.cpp.

156{
157 std::lock_guard<std::mutex> lock(m_mutex_);
158
159 switch (workingMode)
160 {
162 RCLCPP_INFO_STREAM(
163 getLogger(),
164 "[CpOdomTracker] setting working mode to RECORD - record_point_distance_threshold: "
166 << ", record_angular_distance_threshold: " << recordAngularDistanceThreshold_);
167 break;
169 RCLCPP_INFO_STREAM(
170 getLogger(),
171 "[CpOdomTracker] setting working mode to CLEAR - clear_point_distance_threshold: "
173 << ", clear_angular_distance_threshold: " << clearAngularDistanceThreshold_);
174 break;
176 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] setting working mode to IDLE");
177 break;
178 default:
179
180 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] setting working mode to <UNKNOWN>");
181 }
182
183 if (this->odomSub_ != nullptr && this->odomSub_->get_publisher_count() == 0)
184 {
185 RCLCPP_ERROR_STREAM(
186 getLogger(),
187 "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to the "
188 "odometry topic");
189 }
190
191 workingMode_ = workingMode;
192 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex release");
193}

References cl_nav2z::odom_tracker::CLEAR_PATH, clearAngularDistanceThreshold_, clearPointDistanceThreshold_, smacc2::ISmaccComponent::getLogger(), cl_nav2z::odom_tracker::IDLE, m_mutex_, odomSub_, cl_nav2z::odom_tracker::RECORD_PATH, recordAngularDistanceThreshold_, recordPointDistanceThreshold_, and workingMode_.

Referenced by CpOdomTrackerActionServer::execute(), cl_nav2z::CbAbsoluteRotate::onEntry(), cl_nav2z::CbNavigateBackwards::onEntry(), cl_nav2z::CbNavigateForward::onEntry(), cl_nav2z::CbNavigateGlobalPosition::onEntry(), cl_nav2z::CbRotate::onEntry(), cl_nav2z::CbUndoPathBackwards::onEntry(), cl_nav2z::CbNavigateBackwards::onExit(), cl_nav2z::CbNavigateForward::onExit(), cl_nav2z::CbUndoPathBackwards::onExit(), and cl_nav2z::CpWaypointNavigator::sendNextGoal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void cl_nav2z::odom_tracker::CpOdomTracker::update ( )
virtual

update()

Definition at line 572 of file cp_odom_tracker.cpp.

573{
574 RCLCPP_INFO(getLogger(), "odom_tracker update");
575 auto pose = robotPose_->toPoseStampedMsg();
576 RCLCPP_INFO(getLogger(), "odom tracker updated pose, frame: %s", pose.header.frame_id.c_str());
577 processNewPose(pose);
578 RCLCPP_INFO(getLogger(), "odom_tracker update end");
579}
geometry_msgs::msg::PoseStamped toPoseStampedMsg()
Definition cp_pose.hpp:66

References smacc2::ISmaccComponent::getLogger(), processNewPose(), robotPose_, and cl_nav2z::CpPose::toPoseStampedMsg().

Referenced by onInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateAggregatedStackPath()

void cl_nav2z::odom_tracker::CpOdomTracker::updateAggregatedStackPath ( )
protected

Definition at line 426 of file cp_odom_tracker.cpp.

427{
428 aggregatedStackPathMsg_.poses.clear();
429 for (auto & p : pathStack_)
430 {
431 aggregatedStackPathMsg_.poses.insert(
432 aggregatedStackPathMsg_.poses.end(), p.poses.begin(), p.poses.end());
433 }
434
435 aggregatedStackPathMsg_.header.frame_id = this->odomFrame_;
436}

References aggregatedStackPathMsg_, odomFrame_, and pathStack_.

Referenced by clearPath(), popPath(), pushPath(), setPublishMessages(), setStartPoint(), and setStartPoint().

Here is the caller graph for this function:

◆ updateClearPath()

bool cl_nav2z::odom_tracker::CpOdomTracker::updateClearPath ( const geometry_msgs::msg::PoseStamped & base_pose)
protectedvirtual

updateBackward()

Track robot base pose

Not removing point because it is enough far from the last cord point

Definition at line 443 of file cp_odom_tracker.cpp.

444{
445 // we initially accept any message if the queue is empty
447 baseTrajectory_.header = base_pose.header;
448
449 bool acceptBackward = false;
450 bool clearingError = false;
451 bool finished = false;
452
453 while (!finished)
454 {
455 if (
456 baseTrajectory_.poses.size() <=
457 1) // we at least keep always the first point of the forward path when clearing
458 // (this is important for backwards planner replanning and not losing the
459 // last goal)
460 {
461 acceptBackward = false;
462 finished = true;
463 }
464 else
465 {
466 auto & carrotPose = baseTrajectory_.poses.back().pose;
467 auto & carrotPoint = carrotPose.position;
468
469 double carrotAngle = tf2::getYaw(carrotPose.orientation);
470
471 auto & currePose = base_pose.pose;
472 auto & currePoint = currePose.position;
473 double currentAngle = tf2::getYaw(currePose.orientation);
474
475 double lastpointdist = p2pDistance(carrotPoint, currePoint);
476 double goalAngleOffset = fabs(angles::shortest_angular_distance(carrotAngle, currentAngle));
477
478 acceptBackward = !baseTrajectory_.poses.empty() &&
479 lastpointdist < clearPointDistanceThreshold_ &&
480 goalAngleOffset < clearAngularDistanceThreshold_;
481
482 clearingError = lastpointdist > 2 * clearPointDistanceThreshold_;
483 RCLCPP_DEBUG_STREAM(
484 getLogger(), "[CpOdomTracker] clearing (accepted: " << acceptBackward
485 << ") linerr: " << lastpointdist
486 << ", anglerr: " << goalAngleOffset);
487 }
488
489 if (
490 acceptBackward &&
491 baseTrajectory_.poses.size() > 1) /* we always leave at least one item, specially interesting
492 for the backward local planner reach
493 the backwards goal with enough precision*/
494 {
495 baseTrajectory_.poses.pop_back();
496 }
497 else if (clearingError)
498 {
499 finished = true;
500 RCLCPP_WARN(getLogger(), "[CpOdomTracker] Incorrect odom clearing motion.");
501 }
502 else
503 {
504 finished = true;
506 }
507 }
508
509 return acceptBackward;
510}
double p2pDistance(const geometry_msgs::msg::Point &p1, const geometry_msgs::msg::Point &p2)

References baseTrajectory_, clearAngularDistanceThreshold_, clearPointDistanceThreshold_, smacc2::ISmaccComponent::getLogger(), and cl_nav2z::odom_tracker::p2pDistance().

Referenced by processNewPose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateParameters()

void cl_nav2z::odom_tracker::CpOdomTracker::updateParameters ( )

◆ updateRecordPath()

bool cl_nav2z::odom_tracker::CpOdomTracker::updateRecordPath ( const geometry_msgs::msg::PoseStamped & base_pose)
protectedvirtual

updateRecordPath()

Track robot base pose

Definition at line 517 of file cp_odom_tracker.cpp.

518{
520 baseTrajectory_.header = base_pose.header;
521
522 bool enqueueOdomMessage = false;
523
524 double dist = -1;
525 if (baseTrajectory_.poses.empty())
526 {
527 enqueueOdomMessage = true;
528 }
529 else
530 {
531 const auto & prevPose = baseTrajectory_.poses.back().pose;
532 const geometry_msgs::msg::Point & prevPoint = prevPose.position;
533 double prevAngle = tf2::getYaw(prevPose.orientation);
534
535 const geometry_msgs::msg::Point & currePoint = base_pose.pose.position;
536 double currentAngle = tf2::getYaw(base_pose.pose.orientation);
537
538 dist = p2pDistance(prevPoint, currePoint);
539 double goalAngleOffset = fabs(angles::shortest_angular_distance(prevAngle, currentAngle));
540
541 // RCLCPP_WARN(getLogger(),"dist %lf vs min %lf", dist, recordPointDistanceThreshold_);
542
543 RCLCPP_WARN_THROTTLE(getLogger(), *getNode()->get_clock(), 2000, "odom received");
544
546 {
547 enqueueOdomMessage = true;
548 }
549 else
550 {
551 // RCLCPP_WARN(getLogger(),"skip odom, dist: %lf", dist);
552 enqueueOdomMessage = false;
553 }
554 }
555
556 if (enqueueOdomMessage)
557 {
558 RCLCPP_WARN_THROTTLE(
559 getLogger(), *getNode()->get_clock(), 2000, "enqueue odom tracker pose. dist %lf vs min %lf",
561 baseTrajectory_.poses.push_back(base_pose);
562 }
563
564 return enqueueOdomMessage;
565}

References baseTrajectory_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), cl_nav2z::odom_tracker::p2pDistance(), recordAngularDistanceThreshold_, and recordPointDistanceThreshold_.

Referenced by processNewPose().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ aggregatedStackPathMsg_

nav_msgs::msg::Path cl_nav2z::odom_tracker::CpOdomTracker::aggregatedStackPathMsg_
protected

Definition at line 190 of file cp_odom_tracker.hpp.

Referenced by rtPublishPaths(), and updateAggregatedStackPath().

◆ baseTrajectory_

nav_msgs::msg::Path cl_nav2z::odom_tracker::CpOdomTracker::baseTrajectory_
protected

Processed path for the mouth of the reel.

Definition at line 176 of file cp_odom_tracker.hpp.

Referenced by clearPath(), getPath(), logStateStringLocked(), popPath(), pushPath(), rtPublishPaths(), setStartPoint(), setStartPoint(), updateClearPath(), and updateRecordPath().

◆ clearAngularDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::clearAngularDistanceThreshold_ = 0.1
protected

rads

Definition at line 165 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), parametersCallback(), setWorkingMode(), and updateClearPath().

◆ clearPointDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::clearPointDistanceThreshold_ = 0.05
protected

rads

Definition at line 162 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), parametersCallback(), setWorkingMode(), and updateClearPath().

◆ currentMotionGoal_

std::optional<geometry_msgs::msg::PoseStamped> cl_nav2z::odom_tracker::CpOdomTracker::currentMotionGoal_
protected

◆ currentPathName_

std::string cl_nav2z::odom_tracker::CpOdomTracker::currentPathName_
protected

Definition at line 195 of file cp_odom_tracker.hpp.

Referenced by logStateStringLocked(), pushPath(), and setCurrentPathName().

◆ m_mutex_

◆ odomFrame_

std::string cl_nav2z::odom_tracker::CpOdomTracker::odomFrame_
protected

◆ odomSub_

rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr cl_nav2z::odom_tracker::CpOdomTracker::odomSub_
protected

◆ odomTopicName_

std::string cl_nav2z::odom_tracker::CpOdomTracker::odomTopicName_
protected

Definition at line 169 of file cp_odom_tracker.hpp.

Referenced by CpOdomTracker(), and onInitialize().

◆ param_callback_handle_

rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr cl_nav2z::odom_tracker::CpOdomTracker::param_callback_handle_
protected

Definition at line 200 of file cp_odom_tracker.hpp.

Referenced by onInitialize().

◆ pathInfos_

std::vector<PathInfo> cl_nav2z::odom_tracker::CpOdomTracker::pathInfos_
protected

Definition at line 188 of file cp_odom_tracker.hpp.

Referenced by logStateStringLocked(), popPath(), and pushPath().

◆ pathStack_

std::vector<nav_msgs::msg::Path> cl_nav2z::odom_tracker::CpOdomTracker::pathStack_
protected

◆ publishMessages

bool cl_nav2z::odom_tracker::CpOdomTracker::publishMessages
protected

Definition at line 173 of file cp_odom_tracker.hpp.

Referenced by CpOdomTracker(), processNewPose(), and setPublishMessages().

◆ recordAngularDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::recordAngularDistanceThreshold_ = 0.1
protected

Meters.

Definition at line 159 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), parametersCallback(), setWorkingMode(), and updateRecordPath().

◆ recordPointDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::recordPointDistanceThreshold_ = 0.005
protected

How much distance there is between two points of the path.

Definition at line 156 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), parametersCallback(), setWorkingMode(), and updateRecordPath().

◆ robotBasePathPub_

rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr cl_nav2z::odom_tracker::CpOdomTracker::robotBasePathPub_
protected

Definition at line 143 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), and rtPublishPaths().

◆ robotBasePathStackedPub_

rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr cl_nav2z::odom_tracker::CpOdomTracker::robotBasePathStackedPub_
protected

Definition at line 144 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), and rtPublishPaths().

◆ robotPose_

cl_nav2z::CpPose* cl_nav2z::odom_tracker::CpOdomTracker::robotPose_ = nullptr
protected

Definition at line 151 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), and update().

◆ robotPoseTimer_

rclcpp::TimerBase::SharedPtr cl_nav2z::odom_tracker::CpOdomTracker::robotPoseTimer_
protected

Definition at line 152 of file cp_odom_tracker.hpp.

Referenced by onInitialize().

◆ strategy_

OdomTrackerStrategy cl_nav2z::odom_tracker::CpOdomTracker::strategy_
protected

Definition at line 192 of file cp_odom_tracker.hpp.

Referenced by onInitialize().

◆ workingMode_

WorkingMode cl_nav2z::odom_tracker::CpOdomTracker::workingMode_
protected

Definition at line 178 of file cp_odom_tracker.hpp.

Referenced by CpOdomTracker(), processNewPose(), and setWorkingMode().


The documentation for this class was generated from the following files: