ControllerBase.h
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mvsim/basic_types.h>
13 
14 namespace mvsim
15 {
20 {
21  public:
22  struct TeleopInput
23  {
24  int keycode;
25  TeleopInput() : keycode(0) {}
26  };
27  struct TeleopOutput
28  {
29  std::string append_gui_lines;
30  };
31 
32  virtual void teleop_interface(const TeleopInput& in, TeleopOutput& out)
33  { /*default: do nothing*/}
34 
37  virtual bool setTwistCommand(const double vx, const double wz)
38  {
39  return false; /* default: no */
40  }
41 };
42 
44 template <class VEH_DYNAMICS>
46 {
47  public:
48  ControllerBaseTempl(VEH_DYNAMICS& veh) : m_veh(veh) {}
49  virtual ~ControllerBaseTempl() {}
51  virtual void teleop_interface(
52  const TeleopInput& in, TeleopOutput& out) override
53  {
54  /*default: handle logging events*/
55  static bool isRecording = false;
56  switch (in.keycode)
57  {
58  case 'l':
59  case 'L':
60  {
61  isRecording = !isRecording;
62  setLogRecording(isRecording);
63  }
64  break;
65  case 'c':
66  case 'C':
67  {
68  clearLogs();
69  }
70  break;
71 
72  case 'n':
73  case 'N':
74  {
75  newLogSession();
76  }
77  break;
78 
79  default:
80  break;
81  }
82 
83  out.append_gui_lines +=
84  std::string(
85  "Toggle logging [L]. Clear logs[C]. New log session [N]. "
86  "Now ") +
87  std::string(isRecording ? "logging" : "not logging") +
88  std::string("\n");
89  }
90 
93  virtual void control_step(
94  const typename VEH_DYNAMICS::TControllerInput& ci,
95  typename VEH_DYNAMICS::TControllerOutput& co) = 0;
96 
98  virtual void load_config(const rapidxml::xml_node<char>& node)
99  { /*default: do nothing*/}
100 
101  virtual void setLogRecording(bool recording)
102  {
103  m_veh.setRecording(recording);
104  }
105  virtual void clearLogs() { m_veh.clearLogs(); }
106  virtual void newLogSession() { m_veh.newLogSession(); }
107  protected:
108  VEH_DYNAMICS& m_veh;
109 };
110 }
virtual void load_config(const rapidxml::xml_node< char > &node)
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out)
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out) override
virtual void setLogRecording(bool recording)
virtual bool setTwistCommand(const double vx, const double wz)
ControllerBaseTempl(VEH_DYNAMICS &veh)


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40