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-2018, 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::nav
16 {
17 /** CRobot2NavInterface implemented for a simulator object based on
18  * mrpt::kinematics::CVehicleSimul_Holo.
19  * Only `senseObstacles()` remains virtual for the user to implement it.
20  *
21  * \sa CReactiveNavigationSystem, CAbstractNavigator,
22  * mrpt::kinematics::CVehicleSimulVirtualBase
23  * \ingroup nav_reactive
24  */
26 {
27  private:
29  /** for getNavigationTime */
31 
32  public:
35  : m_simul(simul), m_simul_time_start(.0)
36  {
37  }
38 
40  mrpt::math::TPose2D& curPose, mrpt::math::TTwist2D& curVel,
41  mrpt::system::TTimeStamp& timestamp, mrpt::math::TPose2D& curOdometry,
42  std::string& frame_id) override
43  {
44  curPose = m_simul.getCurrentGTPose();
45  curVel = m_simul.getCurrentGTVel();
46  timestamp = mrpt::system::now();
47  curOdometry = m_simul.getCurrentOdometricPose();
48  return true; // ok
49  }
50 
51  virtual bool changeSpeeds(
52  const mrpt::kinematics::CVehicleVelCmd& vel_cmd) override
53  {
54  m_simul.sendVelCmd(vel_cmd);
55  return true; // ok
56  }
57 
58  bool stop(bool isEmergencyStop) override
59  {
61  0.0 /*vel*/, 0 /*dir*/, isEmergencyStop ? 0.1 : 1.0 /* ramp_time */,
62  0.0 /*rot speed */);
63  return true;
64  }
65 
67  {
69  new mrpt::kinematics::CVehicleVelCmd_Holo(0.0, 0.0, 0.1, 0.0));
70  }
71 
73  {
75  new mrpt::kinematics::CVehicleVelCmd_Holo(0.0, 0.0, 1.0, 0.0));
76  }
77 
79  const double relative_heading_radians) override
80  {
83  0.0, // vel
84  relative_heading_radians, // local_dir
85  0.5, // ramp_time
86  mrpt::signWithZero(relative_heading_radians) *
87  mrpt::DEG2RAD(40.0) // rotvel
88  ));
89  }
90 
91  /** See CRobot2NavInterface::getNavigationTime(). In this class, simulation
92  * time is returned instead of wall-clock time. */
93  double getNavigationTime() override
94  {
96  }
97  /** See CRobot2NavInterface::resetNavigationTimer() */
98  void resetNavigationTimer() override
99  {
101  }
102 };
103 
104 /** CRobot2NavInterface implemented for a simulator object based on
105  * mrpt::kinematics::CVehicleSimul_DiffDriven
106  * Only `senseObstacles()` remains virtual for the user to implement it.
107  *
108  * \sa CReactiveNavigationSystem, CAbstractNavigator,
109  * mrpt::kinematics::CVehicleSimulVirtualBase
110  * \ingroup nav_reactive
111  */
113 {
114  private:
116  /** for getNavigationTime */
118 
119  public:
122  : m_simul(simul), m_simul_time_start(.0)
123  {
124  }
125 
127  mrpt::math::TPose2D& curPose, mrpt::math::TTwist2D& curVel,
128  mrpt::system::TTimeStamp& timestamp, mrpt::math::TPose2D& curOdometry,
129  std::string& frame_id) override
130  {
131  curPose = m_simul.getCurrentGTPose();
132  curVel = m_simul.getCurrentGTVel();
133  timestamp = mrpt::system::now();
134  curOdometry = m_simul.getCurrentOdometricPose();
135  return true; // ok
136  }
137 
138  bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd& vel_cmd) override
139  {
140  m_simul.sendVelCmd(vel_cmd);
141  return true; // ok
142  }
143 
144  bool stop(bool isEmergencyStop) override
145  {
147  cmd.setToStop();
148  m_simul.sendVelCmd(cmd);
149  return true;
150  }
151 
153  {
156  cmd->setToStop();
157  return cmd;
158  }
160  {
161  return getStopCmd();
162  }
163 
164  /** See CRobot2NavInterface::getNavigationTime(). In this class, simulation
165  * time is returned instead of wall-clock time. */
166  double getNavigationTime() override
167  {
169  }
170  /** See CRobot2NavInterface::resetNavigationTimer() */
171  void resetNavigationTimer() override
172  {
174  }
175 };
176 }
177 
mrpt::kinematics::CVehicleVelCmd::Ptr getStopCmd() override
Gets the emergency stop command for the current robot.
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd) override
Sends a velocity command to the robot.
void resetNavigationTimer() override
See CRobot2NavInterface::resetNavigationTimer()
double DEG2RAD(const double x)
Degrees to radians.
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:87
int signWithZero(T x)
Returns the sign of X as "0", "1" or "-1".
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)
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
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.
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020