39 std::lock_guard<std::mutex> lock(m_cs);
41 m_last_loc_time.reset();
42 m_last_odo_time.reset();
45 m_loc_odo_ref =
TPose2D(0, 0, 0);
48 m_robot_vel_local =
TTwist2D(.0, .0, .0);
55 std::lock_guard<std::mutex> lock(m_cs);
58 m_last_loc_time = cur_tim;
64 const double dT =
timeDifference(m_last_odo_time.value(), cur_tim);
65 extrapolateRobotPose(m_last_odo, m_robot_vel_local, dT, m_loc_odo_ref);
76 std::lock_guard<std::mutex> lock(m_cs);
80 const double dT =
timeDifference(m_last_odo_time.value(), cur_tim);
82 std::cerr <<
"[CRobot2DPoseEstimator::processUpdateNewOdometry] " 83 "WARNING: Diff. in timestamps between odometry should " 91 m_robot_vel_local = velLocal;
99 m_robot_vel_local =
TTwist2D(.0, .0, .0);
103 m_last_odo_time = cur_tim;
104 m_last_odo = newGlobalOdometry;
113 if (!m_last_odo_time || !m_last_loc_time)
return false;
115 const double dTimeLoc =
timeDifference(m_last_loc_time.value(), tim_query);
116 if (dTimeLoc >
params.max_localiz_age)
return false;
125 const double dTimeOdo =
timeDifference(m_last_odo_time.value(), tim_query);
126 if (dTimeOdo >
params.max_odometry_age)
return false;
128 extrapolateRobotPose(p, m_robot_vel_local, dTimeOdo, pose);
131 velLocal = m_robot_vel_local;
132 velGlobal = velLocal;
144 if (!m_last_odo_time && !m_last_loc_time)
151 if (m_last_odo_time && m_last_loc_time)
152 ret_odo = (m_last_odo_time.value() > m_last_loc_time.value());
153 else if (m_last_odo_time)
172 const double delta_time,
TPose2D& new_p)
174 if (velLocal.
vx == 0 && velLocal.
vy == 0 && velLocal.
omega == 0)
178 else if (std::abs(velLocal.
vy) > 1e-2)
181 TPoint2D(delta_time * velLocal.
vx, delta_time * velLocal.
vy);
192 const double R = velLocal.
vx / velLocal.
omega;
193 const double theta = velLocal.
omega * delta_time;
194 const double cc = cos(p.
phi);
195 const double ss = sin(p.
phi);
197 const double arc_x =
R * sin(theta);
198 const double arc_y =
R * (1 - cos(theta));
200 new_p.
x = p.
x + cc * arc_x - ss * arc_y;
201 new_p.
y = p.
y + ss * arc_x + cc * arc_y;
202 new_p.
phi = p.
phi + theta;
209 bool v = getLatestRobotPose(p);
TPoint2D_< double > TPoint2D
Lightweight 2D point.
CRobot2DPoseEstimator()
Default constructor.
std::chrono::time_point< Clock > time_point
void rotate(const double ang)
Transform the (vx,vy) components for a counterclockwise rotation of ang radians.
bool getLatestRobotPose(mrpt::math::TPose2D &pose) const
Get the latest known robot pose, either from odometry or localization.
mrpt::vision::TStereoCalibParams params
void composePoint(double lx, double ly, double &gx, double &gy) const
An alternative, slightly more efficient way of doing with G and L being 2D points and P this 2D pose...
void reset()
Resets all internal state.
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
This base provides a set of functions for maths stuff.
double phi() const
Get the phi angle of the 2D pose (in radians)
void processUpdateNewOdometry(const mrpt::math::TPose2D &newGlobalOdometry, mrpt::Clock::time_point cur_tim, bool hasVelocities=false, const mrpt::math::TTwist2D &newRobotVelLocal=mrpt::math::TTwist2D())
Updates the filter with new odometry readings.
double vx
Velocity components: X,Y (m/s)
double x() const
Common members of all points & poses classes.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool getCurrentEstimate(mrpt::math::TPose2D &pose, mrpt::math::TTwist2D &velLocal, mrpt::math::TTwist2D &velGlobal, mrpt::Clock::time_point tim_query=mrpt::Clock::now()) const
Get the estimate for a given timestamp (defaults to now()), obtained as:
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
virtual ~CRobot2DPoseEstimator()
Destructor.
double timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
static void extrapolateRobotPose(const mrpt::math::TPose2D &p, const mrpt::math::TTwist2D &robot_vel_local, const double delta_time, mrpt::math::TPose2D &new_p)
Auxiliary static method to extrapolate the pose of a robot located at "p" with velocities (v...
void processUpdateNewPoseLocalization(const mrpt::math::TPose2D &newPose, mrpt::Clock::time_point tim)
Updates the filter with new global-coordinates localization data from a localization or SLAM source...
double phi
Orientation (rads)
double omega
Angular velocity (rad/s)