file.hpp
Go to the documentation of this file.
1 
10 #ifndef QTCTRL_FILE_CTRL
11 #define QTCTRL_FILE_CTRL
12 
13 #include <iostream>
14 #include <fstream> // to get ifstream definition
15 #include <ctrl/controller.hpp>
16 
25 class FileCtrl : public Controller {
26 protected:
27  std::ifstream *input;
28 
31  bool inputOK() const
32  { return (input != NULL) && ( input->is_open() ); }
33 
36  bool inputEnded() const
37  { return (input != NULL) && ( input->eof() ); }
38 
40  void inputEnd()
41  { if ( inputOK() ) { input->close(); delete input; } }
42 
43 public:
50  FileCtrl(const MotionModel& model, const double& ts,
51  const char* input_file_name = NULL)
52  : Controller(model, ts), input( input_file_name == NULL ? NULL :
53  new std::ifstream(input_file_name)
54  ) {
55  // std::cout << "Ctrl File: '" << input_file_name << "'\n";
56  }
57 
60  virtual ~FileCtrl() { inputEnd(); }
61 
64  void setInput(const char* input_file_name) {
65  inputEnd(); // if the stream was open, close it...
66  input = new std::ifstream(input_file_name);
67  }
68 
69  // Cf Controller::chooseVelocities(...)
70  void chooseVelocities(double& trans_vel, double& rot_vel,
71  std::ostream& log_str);
72 
73 }; // end of class FileCtrl
74 
75 #endif // QTCTRL_FILE_CTRL
bool inputEnded() const
Is the input stream at its end?
Definition: file.hpp:36
Controller is the abstract class inherited by all the implemented controllers.
Definition: controller.hpp:28
void chooseVelocities(double &trans_vel, double &rot_vel, std::ostream &log_str)
Computes new velocities for ROS node.
Definition: file.cpp:14
void inputEnd()
Close and terminate the input stream.
Definition: file.hpp:40
bool inputOK() const
Is the input stream OK for reading?
Definition: file.hpp:31
virtual ~FileCtrl()
The destructor closes the input stream, if any.
Definition: file.hpp:60
FileCtrl(const MotionModel &model, const double &ts, const char *input_file_name=NULL)
The constructor needs a motion model and an optional input file name.
Definition: file.hpp:50
This class defines a motion model, with the motion limits.
Definition: motion.hpp:28
FileCtrl allows to control the robot from a file.
Definition: file.hpp:25
void setInput(const char *input_file_name)
Change the input stream to a new file.
Definition: file.hpp:64
std::ifstream * input
The input stream, if any.
Definition: file.hpp:27
Controller abstract class.


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