Main MRPT website > C++ reference for MRPT 1.9.9
CRobot2NavInterfaceForSimulator.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
14 
15 namespace mrpt
16 {
17 namespace nav
18 {
19 /** CRobot2NavInterface implemented for a simulator object based on
20  * mrpt::kinematics::CVehicleSimul_Holo.
21  * Only `senseObstacles()` remains virtual for the user to implement it.
22  *
23  * \sa CReactiveNavigationSystem, CAbstractNavigator,
24  * mrpt::kinematics::CVehicleSimulVirtualBase
25  * \ingroup nav_reactive
26  */
28 {
29  private:
31  /** for getNavigationTime */
33 
34  public:
37  : m_simul(simul), m_simul_time_start(.0)
38  {
39  }
40 
42  mrpt::math::TPose2D& curPose, mrpt::math::TTwist2D& curVel,
43  mrpt::system::TTimeStamp& timestamp, mrpt::math::TPose2D& curOdometry,
44  std::string& frame_id) override
45  {
46  curPose = m_simul.getCurrentGTPose();
47  curVel = m_simul.getCurrentGTVel();
48  timestamp = mrpt::system::now();
49  curOdometry = m_simul.getCurrentOdometricPose();
50  return true; // ok
51  }
52 
53  virtual bool changeSpeeds(
54  const mrpt::kinematics::CVehicleVelCmd& vel_cmd) override
55  {
56  m_simul.sendVelCmd(vel_cmd);
57  return true; // ok
58  }
59 
60  bool stop(bool isEmergencyStop) override
61  {
63  0.0 /*vel*/, 0 /*dir*/, isEmergencyStop ? 0.1 : 1.0 /* ramp_time */,
64  0.0 /*rot speed */);
65  return true;
66  }
67 
69  {
71  new mrpt::kinematics::CVehicleVelCmd_Holo(0.0, 0.0, 0.1, 0.0));
72  }
73 
75  {
77  new mrpt::kinematics::CVehicleVelCmd_Holo(0.0, 0.0, 1.0, 0.0));
78  }
79 
81  const double relative_heading_radians) override
82  {
85  0.0, // vel
86  relative_heading_radians, // local_dir
87  0.5, // ramp_time
88  mrpt::utils::signWithZero(relative_heading_radians) *
89  mrpt::utils::DEG2RAD(40.0) // rotvel
90  ));
91  }
92 
93  /** See CRobot2NavInterface::getNavigationTime(). In this class, simulation
94  * time is returned instead of wall-clock time. */
95  double getNavigationTime() override
96  {
98  }
99  /** See CRobot2NavInterface::resetNavigationTimer() */
100  void resetNavigationTimer() override
101  {
103  }
104 };
105 
106 /** CRobot2NavInterface implemented for a simulator object based on
107  * mrpt::kinematics::CVehicleSimul_DiffDriven
108  * Only `senseObstacles()` remains virtual for the user to implement it.
109  *
110  * \sa CReactiveNavigationSystem, CAbstractNavigator,
111  * mrpt::kinematics::CVehicleSimulVirtualBase
112  * \ingroup nav_reactive
113  */
115 {
116  private:
118  /** for getNavigationTime */
120 
121  public:
124  : m_simul(simul), m_simul_time_start(.0)
125  {
126  }
127 
129  mrpt::math::TPose2D& curPose, mrpt::math::TTwist2D& curVel,
130  mrpt::system::TTimeStamp& timestamp, mrpt::math::TPose2D& curOdometry,
131  std::string& frame_id) override
132  {
133  curPose = m_simul.getCurrentGTPose();
134  curVel = m_simul.getCurrentGTVel();
135  timestamp = mrpt::system::now();
136  curOdometry = m_simul.getCurrentOdometricPose();
137  return true; // ok
138  }
139 
140  bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd& vel_cmd) override
141  {
142  m_simul.sendVelCmd(vel_cmd);
143  return true; // ok
144  }
145 
146  bool stop(bool isEmergencyStop) override
147  {
149  cmd.setToStop();
150  m_simul.sendVelCmd(cmd);
151  return true;
152  }
153 
155  {
158  cmd->setToStop();
159  return cmd;
160  }
162  {
163  return getStopCmd();
164  }
165 
166  /** See CRobot2NavInterface::getNavigationTime(). In this class, simulation
167  * time is returned instead of wall-clock time. */
168  double getNavigationTime() override
169  {
171  }
172  /** See CRobot2NavInterface::resetNavigationTimer() */
173  void resetNavigationTimer() override
174  {
176  }
177 };
178 }
179 }
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
int signWithZero(T x)
Returns the sign of X as "0", "1" or "-1".
mrpt::kinematics::CVehicleVelCmd::Ptr getStopCmd() override
Gets the emergency stop command for the current robot.
double DEG2RAD(const double x)
Degrees to radians.
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd) override
Sends a velocity command to the robot.
void resetNavigationTimer() override
See CRobot2NavInterface::resetNavigationTimer()
mrpt::kinematics::CVehicleVelCmd::Ptr getEmergencyStopCmd() override
Gets the emergency stop command for the current robot.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:76
void resetNavigationTimer() override
See CRobot2NavInterface::resetNavigationTimer()
double getNavigationTime() override
See CRobot2NavInterface::getNavigationTime().
bool stop(bool isEmergencyStop) override
Stop the robot right now.
void sendVelRampCmd(double vel, double dir, double ramp_time, double rot_speed)
Sends a velocity cmd to the holonomic robot.
const mrpt::math::TTwist2D & getCurrentGTVel() const
Returns the instantaneous, ground truth velocity vector (vx,vy,omega) in world coordinates.
const mrpt::math::TPose2D & getCurrentGTPose() const
Returns the instantaneous, ground truth pose in world coordinates.
Virtual base for velocity commands of different kinematic models of planar mobile robot...
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
double getNavigationTime() override
See CRobot2NavInterface::getNavigationTime().
void sendVelCmd(const CVehicleVelCmd &cmd_vel) override
Sends a velocity command to the robot.
CRobot2NavInterface implemented for a simulator object based on mrpt::kinematics::CVehicleSimul_DiffD...
CRobot2NavInterfaceForSimulator_DiffDriven(mrpt::kinematics::CVehicleSimul_DiffDriven &simul)
Simulates the kinematics of a differential-driven planar mobile robot/vehicle, including odometry err...
void setToStop() override
Set to a command that means "do not move" / "stop".
double getTime() const
Get the current simulation time.
mrpt::kinematics::CVehicleVelCmd::Ptr getAlignCmd(const double relative_heading_radians) override
Gets a motion command to make the robot to align with a given relative heading, without translating...
GLsizei const GLchar ** string
Definition: glext.h:4101
bool getCurrentPoseAndSpeeds(mrpt::math::TPose2D &curPose, mrpt::math::TTwist2D &curVel, mrpt::system::TTimeStamp &timestamp, mrpt::math::TPose2D &curOdometry, std::string &frame_id) override
Get the current pose and velocity of the robot.
bool stop(bool isEmergencyStop) override
Stop the robot right now.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Kinematic simulator of a holonomic 2D robot capable of moving in any direction, with "blended" veloci...
Lightweight 2D pose.
CRobot2NavInterface implemented for a simulator object based on mrpt::kinematics::CVehicleSimul_Holo...
bool getCurrentPoseAndSpeeds(mrpt::math::TPose2D &curPose, mrpt::math::TTwist2D &curVel, mrpt::system::TTimeStamp &timestamp, mrpt::math::TPose2D &curOdometry, std::string &frame_id) override
Get the current pose and velocity of the robot.
mrpt::kinematics::CVehicleVelCmd::Ptr getStopCmd() override
Gets the emergency stop command for the current robot.
std::shared_ptr< CVehicleVelCmd > Ptr
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...
mrpt::kinematics::CVehicleVelCmd::Ptr getEmergencyStopCmd() override
Gets the emergency stop command for the current robot.
const mrpt::math::TPose2D & getCurrentOdometricPose() const
Returns the current pose according to (noisy) odometry.
bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd) override
Sends a velocity command to the robot.
Kinematic model for Ackermann-like or differential-driven vehicles.
CRobot2NavInterfaceForSimulator_Holo(mrpt::kinematics::CVehicleSimul_Holo &simul)
void sendVelCmd(const CVehicleVelCmd &cmd_vel) override
Sends a velocity command to the robot.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019