SMACC2
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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")
 
virtual void processOdometryMessage (const nav_msgs::msg::Odometry::SharedPtr odom)
 odom callback: Updates the path - this must be called periodically for each odometry message.
 
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)
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Protected Member Functions

void onInitialize () override
 
void updateConfiguration ()
 
virtual void rtPublishPaths (rclcpp::Time timestamp)
 
virtual bool updateRecordPath (const nav_msgs::msg::Odometry &odom)
 
virtual bool updateClearPath (const nav_msgs::msg::Odometry &odom)
 
void updateAggregatedStackPath ()
 
- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist=false)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist=false)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentTypecreateSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentTypecreateSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachinegetStateMachine ()
 

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_
 
double recordPointDistanceThreshold_
 How much distance there is between two points of the path.
 
double recordAngularDistanceThreshold_
 Meters.
 
double clearPointDistanceThreshold_
 rads
 
double clearAngularDistanceThreshold_
 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< PathInfopathInfos_
 
nav_msgs::msg::Path aggregatedStackPathMsg_
 
bool subscribeToOdometryTopic_
 
std::optional< geometry_msgs::msg::PoseStamped > currentMotionGoal_
 
std::string currentPathName_
 
std::mutex m_mutex_
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

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 53 of file cp_odom_tracker.hpp.

Constructor & Destructor Documentation

◆ CpOdomTracker()

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

Member Function Documentation

◆ clearPath()

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

Definition at line 279 of file cp_odom_tracker.cpp.

280{
281 std::lock_guard<std::mutex> lock(m_mutex_);
282 baseTrajectory_.poses.clear();
283
284 rtPublishPaths(getNode()->now());
285 this->logStateString();
287
288 this->currentMotionGoal_.reset();
289}
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::Node::SharedPtr getNode()

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

Referenced by cl_nav2z::CbNavigateBackwards::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 337 of file cp_odom_tracker.cpp.

338{
339 std::lock_guard<std::mutex> lock(m_mutex_);
340 return this->currentMotionGoal_;
341}

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 343 of file cp_odom_tracker.cpp.

344{
345 std::lock_guard<std::mutex> lock(m_mutex_);
346 return this->baseTrajectory_;
347}

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 237 of file cp_odom_tracker.cpp.

238{
239 std::stringstream ss;
240 ss << "--- odom tracker state ---" << std::endl;
241 ss
242 << " - path stack -" << currentPathName_ << " - size:"
243 << pathStack_.size()
244 //<< " goal: " << (getCurrentMotionGoal()? getCurrentMotionGoal()->pose: geometry_msgs::msg::Pose())
245 << std::endl;
246 ss << " - [STACK-HEAD active path size: " << baseTrajectory_.poses.size() << "]" << std::endl;
247 int i = 0;
248 for (auto & p : pathStack_ | boost::adaptors::reversed)
249 {
250 auto & pathinfo = pathInfos_[pathInfos_.size() - i - 1];
251 std::string goalstr = "[]";
252 if (pathinfo.goalPose)
253 {
254 std::stringstream ss;
255 ss << *(pathinfo.goalPose);
256 goalstr = ss.str();
257 }
258
259 ss << " - p " << i << "[" << p.header.stamp << "], size: " << p.poses.size() << " - "
260 << pathinfo.name << " - goal: " << goalstr << std::endl;
261 i++;
262 }
263 ss << "---";
264
265 if (this->odomSub_->get_publisher_count() == 0)
266 {
267 ss << std::endl
268 << "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to "
269 "the odometry topic"
270 << std::endl;
271 }
272
273 if (debug)
274 RCLCPP_DEBUG(getLogger(), ss.str().c_str());
275 else
276 RCLCPP_INFO(getLogger(), ss.str().c_str());
277}
rclcpp::Subscription< nav_msgs::msg::Odometry >::SharedPtr odomSub_
std::vector< nav_msgs::msg::Path > pathStack_
rclcpp::Logger getLogger() const

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

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

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 57 of file cp_odom_tracker.cpp.

58{
59 // default values
60 recordPointDistanceThreshold_ = 0.005; // 5 mm
61 recordAngularDistanceThreshold_ = 0.1; // radians
62 clearPointDistanceThreshold_ = 0.05; // 5 cm
64
65 auto nh = getNode();
66 RCLCPP_WARN(getLogger(), "[CpOdomTracker] Initializing Odometry Tracker");
67
68 parameterDeclareAndtryGetOrSet(nh, "odom_frame", this->odomFrame_);
70 nh, "record_point_distance_threshold", recordPointDistanceThreshold_);
72 nh, "record_angular_distance_threshold", recordAngularDistanceThreshold_);
74 nh, "clear_point_distance_threshold", clearPointDistanceThreshold_);
76 nh, "clear_angular_distance_threshold", clearAngularDistanceThreshold_);
77
79 {
80 RCLCPP_INFO_STREAM(
81 nh->get_logger(), "[CpOdomTracker] subscribing to odom topic: " << odomTopicName_);
82
83 rclcpp::SensorDataQoS qos;
84 odomSub_ = nh->create_subscription<nav_msgs::msg::Odometry>(
85 odomTopicName_, qos,
86 std::bind(&CpOdomTracker::processOdometryMessage, this, std::placeholders::_1));
87 }
88
90 nh->create_publisher<nav_msgs::msg::Path>("odom_tracker_path", rclcpp::QoS(1));
92 nh->create_publisher<nav_msgs::msg::Path>("odom_tracker_stacked_path", rclcpp::QoS(1));
93}
virtual void processOdometryMessage(const nav_msgs::msg::Odometry::SharedPtr odom)
odom callback: Updates the path - this must be called periodically for each odometry message.
double recordPointDistanceThreshold_
How much distance there is between two points of the path.
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr robotBasePathStackedPub_
rclcpp::Publisher< nav_msgs::msg::Path >::SharedPtr robotBasePathPub_
void parameterDeclareAndtryGetOrSet(rclcpp::Node::SharedPtr &node, std::string param_name, T &value)

References clearAngularDistanceThreshold_, clearPointDistanceThreshold_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getNode(), odomFrame_, odomSub_, odomTopicName_, cl_nav2z::odom_tracker::parameterDeclareAndtryGetOrSet(), processOdometryMessage(), recordAngularDistanceThreshold_, recordPointDistanceThreshold_, robotBasePathPub_, robotBasePathStackedPub_, and subscribeToOdometryTopic_.

Here is the call graph for this function:

◆ popPath()

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

Definition at line 192 of file cp_odom_tracker.cpp.

193{
194 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex acquire");
195 std::lock_guard<std::mutex> lock(m_mutex_);
196
197 RCLCPP_INFO(getLogger(), "POP PATH ENTRY");
198 this->logStateString();
199
200 if (this->odomSub_->get_publisher_count() == 0)
201 {
202 RCLCPP_ERROR_STREAM(
203 getLogger(),
204 "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to the "
205 "odometry topic");
206 }
207
208 if (!keepPreviousPath)
209 {
210 baseTrajectory_.poses.clear();
211 }
212
213 while (popCount > 0 && !pathStack_.empty())
214 {
215 auto & stackedPath = pathStack_.back().poses;
216 auto & stackedPathInfo = pathInfos_.back();
217
218 baseTrajectory_.poses.insert(
219 baseTrajectory_.poses.begin(), stackedPath.begin(), stackedPath.end());
220 this->currentMotionGoal_ = stackedPathInfo.goalPose;
221 pathStack_.pop_back();
222 pathInfos_.pop_back();
223 popCount--;
224
225 RCLCPP_INFO(getLogger(), "POP PATH Iteration ");
226 this->logStateString();
227 }
228
229 RCLCPP_INFO(getLogger(), "POP PATH EXITING");
230 this->logStateString();
231 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex release");
233
234 this->currentMotionGoal_.reset();
235}

References baseTrajectory_, currentMotionGoal_, smacc2::ISmaccComponent::getLogger(), logStateString(), 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:

◆ processOdometryMessage()

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

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

processOdometryMessage()

Definition at line 547 of file cp_odom_tracker.cpp.

548{
549 RCLCPP_INFO_THROTTLE(
550 getLogger(), *getNode()->get_clock(), 5000,
551 "[odom_tracker] processing odom msg update heartbeat");
552 std::lock_guard<std::mutex> lock(m_mutex_);
553
555
557 {
558 updateRecordPath(*odom);
559 }
561 {
562 updateClearPath(*odom);
563 }
564
565 // RCLCPP_WARN(getLogger(),"odomTracker odometry callback");
566 if (publishMessages)
567 {
568 rtPublishPaths(odom->header.stamp);
569 }
570
571 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex release");
572}
virtual bool updateRecordPath(const nav_msgs::msg::Odometry &odom)
virtual bool updateClearPath(const nav_msgs::msg::Odometry &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(), updateConfiguration(), updateRecordPath(), and workingMode_.

Referenced by onInitialize().

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 ( )

Definition at line 154 of file cp_odom_tracker.cpp.

154{ this->pushPath(std::string()); }

References pushPath().

Referenced by CpOdomTrackerActionServer::execute(), cl_nav2z::CbNavigateForward::onEntry(), and pushPath().

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

◆ pushPath() [2/2]

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

Definition at line 156 of file cp_odom_tracker.cpp.

157{
158 RCLCPP_INFO(getLogger(), "odom_tracker m_mutex acquire");
159 std::lock_guard<std::mutex> lock(m_mutex_);
160
161 this->logStateString(false);
162 if (this->odomSub_->get_publisher_count() == 0)
163 {
164 RCLCPP_ERROR_STREAM(
165 getLogger(),
166 "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to the "
167 "odometry topic");
168 }
169
171 pathStack_.push_back(baseTrajectory_);
172
173 geometry_msgs::msg::PoseStamped goalPose;
174 if (this->currentMotionGoal_) goalPose = *this->currentMotionGoal_;
175
176 RCLCPP_INFO_STREAM(
177 getLogger(), "[CpOdomTracker] currentPathName: " << pathname
178 << " size: " << baseTrajectory_.poses.size()
179 << " current motion goal: " << goalPose);
180
181 currentPathName_ = pathname;
182
183 // clean the current trajectory to start a new one
184 baseTrajectory_.poses.clear();
185
186 this->logStateString(false);
188
189 this->currentMotionGoal_.reset();
190}

References baseTrajectory_, currentMotionGoal_, currentPathName_, smacc2::ISmaccComponent::getLogger(), logStateString(), 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 354 of file cp_odom_tracker.cpp.

355{
356 baseTrajectory_.header.stamp = timestamp;
358
359 aggregatedStackPathMsg_.header.stamp = timestamp;
361}

References aggregatedStackPathMsg_, baseTrajectory_, robotBasePathPub_, and robotBasePathStackedPub_.

Referenced by clearPath(), and processOdometryMessage().

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 331 of file cp_odom_tracker.cpp.

332{
333 std::lock_guard<std::mutex> lock(m_mutex_);
334 this->currentMotionGoal_ = pose;
335}

References currentMotionGoal_, and m_mutex_.

Referenced by 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 291 of file cp_odom_tracker.cpp.

292{
293 currentPathName_ = currentPathName;
294}

References currentPathName_.

◆ setPublishMessages()

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

setPublishMessages()

Definition at line 145 of file cp_odom_tracker.cpp.

146{
147 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex acquire");
148 std::lock_guard<std::mutex> lock(m_mutex_);
149 publishMessages = value;
150 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex release");
152}

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 311 of file cp_odom_tracker.cpp.

312{
313 std::lock_guard<std::mutex> lock(m_mutex_);
314 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] set current path starting point: " << pose);
315 geometry_msgs::msg::PoseStamped posestamped;
316 posestamped.header.frame_id = this->odomFrame_;
317 posestamped.header.stamp = getNode()->now();
318 posestamped.pose = pose;
319
320 if (baseTrajectory_.poses.size() > 0)
321 {
322 baseTrajectory_.poses[0] = posestamped;
323 }
324 else
325 {
326 baseTrajectory_.poses.push_back(posestamped);
327 }
329}

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 296 of file cp_odom_tracker.cpp.

297{
298 std::lock_guard<std::mutex> lock(m_mutex_);
299 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] set current path starting point: " << pose);
300 if (baseTrajectory_.poses.size() > 0)
301 {
302 baseTrajectory_.poses[0] = pose;
303 }
304 else
305 {
306 baseTrajectory_.poses.push_back(pose);
307 }
309}

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

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

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 100 of file cp_odom_tracker.cpp.

101{
102 std::lock_guard<std::mutex> lock(m_mutex_);
103
104 switch (workingMode)
105 {
107 RCLCPP_INFO_STREAM(
108 getLogger(),
109 "[CpOdomTracker] setting working mode to RECORD - record_point_distance_threshold: "
111 << ", record_angular_distance_threshold: " << recordAngularDistanceThreshold_);
112 break;
114 RCLCPP_INFO_STREAM(
115 getLogger(),
116 "[CpOdomTracker] setting working mode to CLEAR - clear_point_distance_threshold: "
118 << ", clear_angular_distance_threshold: " << clearAngularDistanceThreshold_);
119 break;
121 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] setting working mode to IDLE");
122 break;
123 default:
124
125 RCLCPP_INFO_STREAM(getLogger(), "[CpOdomTracker] setting working mode to <UNKNOWN>");
126 }
127
128 if (this->odomSub_->get_publisher_count() == 0)
129 {
130 RCLCPP_ERROR_STREAM(
131 getLogger(),
132 "[CpOdomTracker] Odom tracker cannot record the path because there is no publisher to the "
133 "odometry topic");
134 }
135
136 workingMode_ = workingMode;
137 // RCLCPP_INFO(getLogger(),"odom_tracker m_mutex release");
138}

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::CbNavigateBackwards::onEntry(), cl_nav2z::CbNavigateForward::onEntry(), cl_nav2z::CbUndoPathBackwards::onEntry(), cl_nav2z::CbNavigateBackwards::onExit(), and cl_nav2z::CbNavigateForward::onExit().

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 363 of file cp_odom_tracker.cpp.

364{
365 aggregatedStackPathMsg_.poses.clear();
366 for (auto & p : pathStack_)
367 {
368 aggregatedStackPathMsg_.poses.insert(
369 aggregatedStackPathMsg_.poses.end(), p.poses.begin(), p.poses.end());
370 }
371
372 aggregatedStackPathMsg_.header.frame_id = this->odomFrame_;
373}

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 nav_msgs::msg::Odometry &  odom)
protectedvirtual

updateBackward()

Track robot base pose

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

Definition at line 380 of file cp_odom_tracker.cpp.

381{
382 // we initially accept any message if the queue is empty
384 geometry_msgs::msg::PoseStamped base_pose;
385
386 base_pose.pose = odom.pose.pose;
387 base_pose.header = odom.header;
388 baseTrajectory_.header = odom.header;
389
390 bool acceptBackward = false;
391 bool clearingError = false;
392 bool finished = false;
393
394 while (!finished)
395 {
396 if (
397 baseTrajectory_.poses.size() <=
398 1) // we at least keep always the first point of the forward path when clearing
399 // (this is important for backwards planner replanning and not losing the
400 // last goal)
401 {
402 acceptBackward = false;
403 finished = true;
404 }
405 else
406 {
407 auto & carrotPose = baseTrajectory_.poses.back().pose;
408 auto & carrotPoint = carrotPose.position;
409
410 double carrotAngle = tf2::getYaw(carrotPose.orientation);
411
412 auto & currePose = base_pose.pose;
413 auto & currePoint = currePose.position;
414 double currentAngle = tf2::getYaw(currePose.orientation);
415
416 double lastpointdist = p2pDistance(carrotPoint, currePoint);
417 double goalAngleOffset = fabs(angles::shortest_angular_distance(carrotAngle, currentAngle));
418
419 acceptBackward = !baseTrajectory_.poses.empty() &&
420 lastpointdist < clearPointDistanceThreshold_ &&
421 goalAngleOffset < clearAngularDistanceThreshold_;
422
423 clearingError = lastpointdist > 2 * clearPointDistanceThreshold_;
424 RCLCPP_DEBUG_STREAM(
425 getLogger(), "[CpOdomTracker] clearing (accepted: " << acceptBackward
426 << ") linerr: " << lastpointdist
427 << ", anglerr: " << goalAngleOffset);
428 }
429
430 // RCLCPP_INFO(getLogger(),"Backwards, last distance: %lf < %lf accept: %d", dist,
431 // minPointDistanceBackwardThresh_, acceptBackward);
432 if (
433 acceptBackward &&
434 baseTrajectory_.poses.size() > 1) /* we always leave at least one item, specially interesting
435 for the backward local planner reach
436 the backwards goal with enough precision*/
437 {
438 baseTrajectory_.poses.pop_back();
439 }
440 else if (clearingError)
441 {
442 finished = true;
443 RCLCPP_WARN(getLogger(), "[CpOdomTracker] Incorrect odom clearing motion.");
444 }
445 else
446 {
447 finished = true;
449 }
450 }
451
452 return acceptBackward;
453}
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 processOdometryMessage().

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

◆ updateConfiguration()

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

reconfigCB()

Definition at line 518 of file cp_odom_tracker.cpp.

519{
520 if (!getNode()->get_parameter("odom_frame", this->odomFrame_))
521 {
522 }
523
524 if (!getNode()->get_parameter("record_point_distance_threshold", recordPointDistanceThreshold_))
525 {
526 }
527
528 if (!getNode()->get_parameter(
529 "record_angular_distance_threshold", recordAngularDistanceThreshold_))
530 {
531 }
532
533 if (!getNode()->get_parameter("clear_point_distance_threshold", clearPointDistanceThreshold_))
534 {
535 }
536
537 if (!getNode()->get_parameter("clear_angular_distance_threshold", clearAngularDistanceThreshold_))
538 {
539 }
540}

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

Referenced by processOdometryMessage().

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

◆ updateRecordPath()

bool cl_nav2z::odom_tracker::CpOdomTracker::updateRecordPath ( const nav_msgs::msg::Odometry &  odom)
protectedvirtual

updateRecordPath()

Track robot base pose

Definition at line 459 of file cp_odom_tracker.cpp.

460{
462 geometry_msgs::msg::PoseStamped base_pose;
463
464 base_pose.pose = odom.pose.pose;
465 base_pose.header = odom.header;
466 baseTrajectory_.header = odom.header;
467
468 bool enqueueOdomMessage = false;
469
470 double dist = -1;
471 if (baseTrajectory_.poses.empty())
472 {
473 enqueueOdomMessage = true;
474 }
475 else
476 {
477 const auto & prevPose = baseTrajectory_.poses.back().pose;
478 const geometry_msgs::msg::Point & prevPoint = prevPose.position;
479 double prevAngle = tf2::getYaw(prevPose.orientation);
480
481 const geometry_msgs::msg::Point & currePoint = base_pose.pose.position;
482 double currentAngle = tf2::getYaw(base_pose.pose.orientation);
483
484 dist = p2pDistance(prevPoint, currePoint);
485 double goalAngleOffset = fabs(angles::shortest_angular_distance(prevAngle, currentAngle));
486
487 // RCLCPP_WARN(getLogger(),"dist %lf vs min %lf", dist, recordPointDistanceThreshold_);
488
489 RCLCPP_WARN_THROTTLE(getLogger(), *getNode()->get_clock(), 2000, "odom received");
490
492 {
493 enqueueOdomMessage = true;
494 }
495 else
496 {
497 // RCLCPP_WARN(getLogger(),"skip odom, dist: %lf", dist);
498 enqueueOdomMessage = false;
499 }
500 }
501
502 if (enqueueOdomMessage)
503 {
504 RCLCPP_WARN_THROTTLE(
505 getLogger(), *getNode()->get_clock(), 2000, "enqueue odom tracker pose. dist %lf vs min %lf",
507 baseTrajectory_.poses.push_back(base_pose);
508 }
509
510 return enqueueOdomMessage;
511}

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

Referenced by processOdometryMessage().

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 163 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 149 of file cp_odom_tracker.hpp.

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

◆ clearAngularDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::clearAngularDistanceThreshold_
protected

rads

Definition at line 138 of file cp_odom_tracker.hpp.

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

◆ clearPointDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::clearPointDistanceThreshold_
protected

rads

Definition at line 135 of file cp_odom_tracker.hpp.

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

◆ 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 169 of file cp_odom_tracker.hpp.

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

◆ m_mutex_

std::mutex cl_nav2z::odom_tracker::CpOdomTracker::m_mutex_
protected

◆ 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

Definition at line 125 of file cp_odom_tracker.hpp.

Referenced by logStateString(), onInitialize(), popPath(), pushPath(), and setWorkingMode().

◆ odomTopicName_

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

Definition at line 142 of file cp_odom_tracker.hpp.

Referenced by CpOdomTracker(), and onInitialize().

◆ pathInfos_

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

Definition at line 161 of file cp_odom_tracker.hpp.

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

◆ pathStack_

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

Definition at line 153 of file cp_odom_tracker.hpp.

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

◆ publishMessages

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

Definition at line 146 of file cp_odom_tracker.hpp.

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

◆ recordAngularDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::recordAngularDistanceThreshold_
protected

Meters.

Definition at line 132 of file cp_odom_tracker.hpp.

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

◆ recordPointDistanceThreshold_

double cl_nav2z::odom_tracker::CpOdomTracker::recordPointDistanceThreshold_
protected

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

Definition at line 129 of file cp_odom_tracker.hpp.

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

◆ robotBasePathPub_

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

Definition at line 119 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 120 of file cp_odom_tracker.hpp.

Referenced by onInitialize(), and rtPublishPaths().

◆ subscribeToOdometryTopic_

bool cl_nav2z::odom_tracker::CpOdomTracker::subscribeToOdometryTopic_
protected

Definition at line 166 of file cp_odom_tracker.hpp.

Referenced by CpOdomTracker(), and onInitialize().

◆ workingMode_

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

Definition at line 151 of file cp_odom_tracker.hpp.

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


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