controller.hpp
Go to the documentation of this file.
1 
10 #ifndef QTCTRL_CONTROLLER
11 #define QTCTRL_CONTROLLER
12 
13 #include <QObject>
14 #include <model/motion.hpp>
15 #include <model/state.hpp>
16 
28 class Controller : public QObject {
29  Q_OBJECT // This macro is needed to handle signals
30 
33 
34 protected: // for the inheriting controllers...
37 
39  const double time_step;
40 
42  double initial_date;
43 
48 
56  Controller(const MotionModel& model, const double& ts)
57  : first_odometry(true), motion_model(model),
58  time_step( fabs(ts) >= 1E-9 ? fabs(ts) : 1E-9 ) {}
59 
66  void updateVelocities(double& trans_vel, double& rot_vel) {
67  trans_vel = moving_velocity;
68  rot_vel = turning_velocity;
69  // signal the GUI to update command's display
70  // low frequency and small data: no copy nor mutex needed!
71  commandsUpdated(trans_vel, rot_vel);
72  }
73 
76  bool firstOdometry() { return first_odometry; }
77 
80  void changeFirstOdometry() { first_odometry = !first_odometry; }
81 
82 public:
84  virtual ~Controller() {}
85 
88  const double& timeStep() const { return time_step; }
89 
95  virtual void newState(const State& state);
96 
99  void stopMotion() { moving_velocity = turning_velocity = 0; }
100 
111  virtual void chooseVelocities(double& trans_vel, double& rot_vel,
112  std::ostream& log_str) = 0;
113 
114 
115 Q_SIGNALS: // this requires the Q_OBJECT macro
116 
119  void stateUpdated(const State& state);
120 
125  void commandsUpdated(const double& trans_vel,
126  const double& rot_vel);
127 
128 }; // end of class Controller
129 
130 
132 class NoCtrl : public Controller {
133 public:
136  NoCtrl(const MotionModel& model) : Controller(model, 1) {}
137 
139  virtual ~NoCtrl() {}
140 
141  // Cf Controller::choose_velocities(geometry_msgs::Twist&)
142  void chooseVelocities(double& trans_vel, double& rot_vel,
143  std::ostream&)
144  { stopMotion(); updateVelocities(trans_vel, rot_vel); }
145 
146 }; // end of class NoCtrl
147 
148 #endif // QTCTRL_CONTROLLER
void changeFirstOdometry()
Change the odometry data status (first or not).
Definition: controller.hpp:80
void stopMotion()
Stops the robot (i.e. sets both velocities to zero).
Definition: controller.hpp:99
Controller is the abstract class inherited by all the implemented controllers.
Definition: controller.hpp:28
void commandsUpdated(const double &trans_vel, const double &rot_vel)
Update the display of the controller&#39;s commands.
State class, i.e. configuration and velocities.
virtual ~NoCtrl()
The destructor needs to be explicitely redefined.
Definition: controller.hpp:139
void stateUpdated(const State &state)
Update the display of the state.
const double time_step
The time step of the controller.
Definition: controller.hpp:39
Controller(const MotionModel &model, const double &ts)
This constructor (for the inheriting controllers) sets the motion model to the given one...
Definition: controller.hpp:56
Default controller, which does not move.
Definition: controller.hpp:132
double moving_velocity
Translation velocity desired for the robot.
Definition: controller.hpp:45
NoCtrl(const MotionModel &model)
The constructor only sets the motion model.
Definition: controller.hpp:136
void updateVelocities(double &trans_vel, double &rot_vel)
Update the velocities from the fields and send the update signal.
Definition: controller.hpp:66
double initial_date
The first date of the odometry.
Definition: controller.hpp:42
const MotionModel & motion_model
The model of the motion.
Definition: controller.hpp:36
virtual void newState(const State &state)
Handles new state of the robot.
Definition: controller.cpp:16
const double & timeStep() const
Stops the robot (i.e. sets both velocities to zero).
Definition: controller.hpp:88
This class defines a state, i.e. a configuration and its (translation and rotation) velocities...
Definition: state.hpp:22
void chooseVelocities(double &trans_vel, double &rot_vel, std::ostream &)
Computes new velocities for ROS node.
Definition: controller.hpp:142
double turning_velocity
Rotation velocity desired for the robot.
Definition: controller.hpp:47
This class defines a motion model, with the motion limits.
Definition: motion.hpp:28
virtual void chooseVelocities(double &trans_vel, double &rot_vel, std::ostream &log_str)=0
Computes new velocities for ROS node.
Motion model for qt_ctrl.
virtual ~Controller()
The destructor needs to be defined as virtual.
Definition: controller.hpp:84
bool first_odometry
Are the odometry data the first?
Definition: controller.hpp:32
bool firstOdometry()
Are the odometry data the first?
Definition: controller.hpp:76


qt_ctrl
Author(s): Alexis Scheuer
autogenerated on Wed Dec 16 2020 15:51:32