SMACC
Loading...
Searching...
No Matches
odom_tracker.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6#pragma once
7
8#include <smacc/common.h>
9#include <smacc/component.h>
10
11#include <move_base_msgs/MoveBaseAction.h>
12
13#include <ros/ros.h>
14#include <vector>
15#include <nav_msgs/Odometry.h>
16#include <nav_msgs/Path.h>
17#include <tf/transform_datatypes.h>
18#include <realtime_tools/realtime_publisher.h>
19#include <mutex>
20#include <memory>
21#include <geometry_msgs/Point.h>
22#include <std_msgs/Header.h>
23
24#include <dynamic_reconfigure/server.h>
25#include <move_base_z_client_plugin/OdomTrackerConfig.h>
26
27namespace cl_move_base_z
28{
29namespace odom_tracker
30{
31
32enum class WorkingMode : uint8_t
33{
34 RECORD_PATH = 0,
35 CLEAR_PATH = 1,
36 IDLE = 2
37};
38
40{
41 nav_msgs::Path path;
42 std::string pathTagName;
43};
44
47{
48public:
49 // by default, the component start in record_path mode and publishing the
50 // current path
51 OdomTracker(std::string odomtopicName = "/odom", std::string odomFrame = "odom");
52
53 // threadsafe
55 // The odom parameters is the main input of this tracker
56 virtual void processOdometryMessage(const nav_msgs::Odometry &odom);
57
58 // ------ CONTROL COMMANDS ---------------------
59 // threadsafe
60 void setWorkingMode(WorkingMode workingMode);
61
62 // threadsafe
63 void setPublishMessages(bool value);
64
65 // threadsafe
66 void pushPath(std::string newPathTagName="");
67
68 // threadsafe
69 void popPath(int pathCount = 1, bool keepPreviousPath = false);
70
71 // threadsafe
72 void clearPath();
73
74 // threadsafe
75 void setStartPoint(const geometry_msgs::PoseStamped &pose);
76
77 // threadsafe
78 void setStartPoint(const geometry_msgs::Pose &pose);
79
80 // threadsafe
81 nav_msgs::Path getPath();
82
83 void logStateString();
84
85 inline const std::vector<StackedPathEntry> getStackedPaths() const
86 {
87 return this->pathStack_;
88 }
89
90protected:
91 dynamic_reconfigure::Server<move_base_z_client_plugin::OdomTrackerConfig> paramServer_;
92 dynamic_reconfigure::Server<move_base_z_client_plugin::OdomTrackerConfig>::CallbackType f;
93
94 void reconfigCB(move_base_z_client_plugin::OdomTrackerConfig &config, uint32_t level);
95
96 virtual void rtPublishPaths(ros::Time timestamp);
97
98
99 // this is called when a new odom message is received in record path mode
100 virtual bool updateRecordPath(const nav_msgs::Odometry &odom);
101
102 // this is called when a new odom message is received in clear path mode
103 virtual bool updateClearPath(const nav_msgs::Odometry &odom);
104
106
107 // -------------- OUTPUTS ---------------------
108 std::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::Path>> robotBasePathPub_;
109 std::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::Path>> robotBasePathStackedPub_;
110
111 // --------------- INPUTS ------------------------
112 // optional, this class can be used directly calling the odomProcessing method
113 // without any subscriber
114 ros::Subscriber odomSub_;
115
116 // -------------- PARAMETERS ----------------------
119
122
125
128
129 std::string odomFrame_;
130
131 // --------------- STATE ---------------
132 // default true
134
136 nav_msgs::Path baseTrajectory_;
137
139
140 std::vector<StackedPathEntry> pathStack_;
141
143
144 // subscribes to topic on init if true
146
147 std::string currentPathTagName_="Initial State";
148
149 std::mutex m_mutex_;
150
151};
152
158inline double p2pDistance(const geometry_msgs::Point &p1, const geometry_msgs::Point &p2)
159{
160 double dx = (p1.x - p2.x);
161 double dy = (p1.y - p2.y);
162 double dz = (p2.z - p2.z);
163 double dist = sqrt(dx * dx + dy * dy + dz * dz);
164 return dist;
165}
166} // namespace odom_tracker
167} // namespace cl_move_base_z
This class track the required distance of the cord based on the external localization system.
Definition: odom_tracker.h:47
virtual void processOdometryMessage(const nav_msgs::Odometry &odom)
odom callback: Updates the path - this must be called periodically for each odometry message.
std::vector< StackedPathEntry > pathStack_
Definition: odom_tracker.h:140
void popPath(int pathCount=1, bool keepPreviousPath=false)
dynamic_reconfigure::Server< move_base_z_client_plugin::OdomTrackerConfig >::CallbackType f
Definition: odom_tracker.h:92
double recordPointDistanceThreshold_
How much distance there is between two points of the path.
Definition: odom_tracker.h:118
std::shared_ptr< realtime_tools::RealtimePublisher< nav_msgs::Path > > robotBasePathPub_
Definition: odom_tracker.h:108
nav_msgs::Path baseTrajectory_
Processed path for the mouth of the reel.
Definition: odom_tracker.h:136
virtual bool updateRecordPath(const nav_msgs::Odometry &odom)
std::shared_ptr< realtime_tools::RealtimePublisher< nav_msgs::Path > > robotBasePathStackedPub_
Definition: odom_tracker.h:109
dynamic_reconfigure::Server< move_base_z_client_plugin::OdomTrackerConfig > paramServer_
Definition: odom_tracker.h:91
virtual void rtPublishPaths(ros::Time timestamp)
void setStartPoint(const geometry_msgs::PoseStamped &pose)
void pushPath(std::string newPathTagName="")
virtual bool updateClearPath(const nav_msgs::Odometry &odom)
void reconfigCB(move_base_z_client_plugin::OdomTrackerConfig &config, uint32_t level)
void setWorkingMode(WorkingMode workingMode)
const std::vector< StackedPathEntry > getStackedPaths() const
Definition: odom_tracker.h:85
double p2pDistance(const geometry_msgs::Point &p1, const geometry_msgs::Point &p2)
Definition: odom_tracker.h:158