ControllerBase.h
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
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  }
35 
38  virtual bool setTwistCommand(const double vx, const double wz)
39  {
40  return false; /* default: no */
41  }
42 };
43 
45 template <class VEH_DYNAMICS>
47 {
48  public:
49  ControllerBaseTempl(VEH_DYNAMICS& veh) : m_veh(veh) {}
50  virtual ~ControllerBaseTempl() {}
52  virtual void teleop_interface(
53  const TeleopInput& in, TeleopOutput& out) override
54  {
55  /*default: handle logging events*/
56  static bool isRecording = false;
57  switch (in.keycode)
58  {
59  case 'l':
60  case 'L':
61  {
62  isRecording = !isRecording;
63  setLogRecording(isRecording);
64  }
65  break;
66  case 'c':
67  case 'C':
68  {
69  clearLogs();
70  }
71  break;
72 
73  case 'n':
74  case 'N':
75  {
76  newLogSession();
77  }
78  break;
79 
80  default:
81  break;
82  }
83 
84  out.append_gui_lines +=
85  std::string(
86  "Toggle logging [L]. Clear logs[C]. New log session [N]. "
87  "Now ") +
88  std::string(isRecording ? "logging" : "not logging") +
89  std::string("\n");
90  }
91 
94  virtual void control_step(
95  const typename VEH_DYNAMICS::TControllerInput& ci,
96  typename VEH_DYNAMICS::TControllerOutput& co) = 0;
97 
99  virtual void load_config(const rapidxml::xml_node<char>& node)
100  { /*default: do nothing*/
101  }
102 
103  virtual void setLogRecording(bool recording)
104  {
105  m_veh.setRecording(recording);
106  }
107  virtual void clearLogs() { m_veh.clearLogs(); }
108  virtual void newLogSession() { m_veh.newLogSession(); }
109 
110  protected:
111  VEH_DYNAMICS& m_veh;
112 };
113 } // namespace mvsim
virtual void load_config(const rapidxml::xml_node< char > &node)
virtual void teleop_interface(const TeleopInput &in, TeleopOutput &out)
GLuint in
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 Fri May 7 2021 03:05:51