ControllerBase.h
Go to the documentation of this file.
00001 /*+-------------------------------------------------------------------------+
00002   |                       MultiVehicle simulator (libmvsim)                 |
00003   |                                                                         |
00004   | Copyright (C) 2014  Jose Luis Blanco Claraco (University of Almeria)    |
00005   | Copyright (C) 2017  Borys Tymchenko (Odessa Polytechnic University)     |
00006   | Distributed under GNU General Public License version 3                  |
00007   |   See <http://www.gnu.org/licenses/>                                    |
00008   +-------------------------------------------------------------------------+ */
00009 
00010 #pragma once
00011 
00012 #include <mvsim/basic_types.h>
00013 
00014 namespace mvsim
00015 {
00019 class ControllerBaseInterface
00020 {
00021    public:
00022         struct TeleopInput
00023         {
00024                 int keycode;
00025                 TeleopInput() : keycode(0) {}
00026         };
00027         struct TeleopOutput
00028         {
00029                 std::string append_gui_lines;
00030         };
00031 
00032         virtual void teleop_interface(const TeleopInput& in, TeleopOutput& out)
00033         { /*default: do nothing*/}
00034 
00037         virtual bool setTwistCommand(const double vx, const double wz)
00038         {
00039                 return false; /* default: no */
00040         }
00041 };
00042 
00044 template <class VEH_DYNAMICS>
00045 class ControllerBaseTempl : public ControllerBaseInterface
00046 {
00047    public:
00048         ControllerBaseTempl(VEH_DYNAMICS& veh) : m_veh(veh) {}
00049         virtual ~ControllerBaseTempl() {}
00051         virtual void teleop_interface(
00052                 const TeleopInput& in, TeleopOutput& out) override
00053         {
00054                 /*default: handle logging events*/
00055                 static bool isRecording = false;
00056                 switch (in.keycode)
00057                 {
00058                         case 'l':
00059                         case 'L':
00060                         {
00061                                 isRecording = !isRecording;
00062                                 setLogRecording(isRecording);
00063                         }
00064                         break;
00065                         case 'c':
00066                         case 'C':
00067                         {
00068                                 clearLogs();
00069                         }
00070                         break;
00071 
00072                         case 'n':
00073                         case 'N':
00074                         {
00075                                 newLogSession();
00076                         }
00077                         break;
00078 
00079                         default:
00080                                 break;
00081                 }
00082 
00083                 out.append_gui_lines +=
00084                         std::string(
00085                                 "Toggle logging [L]. Clear logs[C]. New log session [N]. "
00086                                 "Now ") +
00087                         std::string(isRecording ? "logging" : "not logging") +
00088                         std::string("\n");
00089         }
00090 
00093         virtual void control_step(
00094                 const typename VEH_DYNAMICS::TControllerInput& ci,
00095                 typename VEH_DYNAMICS::TControllerOutput& co) = 0;
00096 
00098         virtual void load_config(const rapidxml::xml_node<char>& node)
00099         { /*default: do nothing*/}
00100 
00101         virtual void setLogRecording(bool recording)
00102         {
00103                 m_veh.setRecording(recording);
00104         }
00105         virtual void clearLogs() { m_veh.clearLogs(); }
00106         virtual void newLogSession() { m_veh.newLogSession(); }
00107    protected:
00108         VEH_DYNAMICS& m_veh;
00109 };
00110 }


mvsim
Author(s):
autogenerated on Thu Sep 7 2017 09:27:48