VehicleDifferential.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/VehicleBase.h>
13 #include <mvsim/PID_Controller.h>
14 
15 #include <mrpt/math/lightweight_geom_data.h>
16 
17 namespace mvsim
18 {
23 {
25  public:
26  enum
27  {
28  WHEEL_L = 0,
29  WHEEL_R = 1
30  };
31 
32  DynamicsDifferential(World* parent);
33 
38  {
40  };
42  {
43  double wheel_torque_l, wheel_torque_r;
44  TControllerOutput() : wheel_torque_l(0), wheel_torque_r(0) {}
45  };
46 
49  typedef std::shared_ptr<ControllerBase> ControllerBasePtr;
50 
51  class ControllerRawForces : public ControllerBase
52  {
53  public:
55  : ControllerBase(veh),
56  setpoint_wheel_torque_l(0),
57  setpoint_wheel_torque_r(0)
58  {
59  }
60  static const char* class_name() { return "raw"; }
63  double setpoint_wheel_torque_l, setpoint_wheel_torque_r;
64  virtual void control_step(
67  co); // See base class docs
68  virtual void teleop_interface(
69  const TeleopInput& in, TeleopOutput& out); // See base class docs
70  };
71 
74  class ControllerTwistPID : public ControllerBase
75  {
76  public:
78  static const char* class_name() { return "twist_pid"; }
82  setpoint_ang_speed;
83  virtual void control_step(
86  co); // See base class docs
87  virtual void load_config(
88  const rapidxml::xml_node<char>& node); // See base class docs
89  virtual void teleop_interface(
90  const TeleopInput& in, TeleopOutput& out); // See base class docs
91 
92  double KP, KI, KD;
93  double max_torque;
94  // See base docs.
95  virtual bool setTwistCommand(const double vx, const double wz)
96  {
97  setpoint_lin_speed = vx;
98  setpoint_ang_speed = wz;
99  return true;
100  }
101 
102  private:
103  double m_distWheels;
104  PID_Controller m_PID[2];
105  };
106 
107  const ControllerBasePtr& getController() const { return m_controller; }
108  ControllerBasePtr& getController() { return m_controller; }
110  {
111  return m_controller.get();
112  }
113  // end controllers
115 
116  virtual vec3 getVelocityLocalOdoEstimate() const; // See docs of base class
117 
118  protected:
119  // See base class docs
120  virtual void dynamics_load_params_from_xml(
121  const rapidxml::xml_node<char>* xml_node);
122  // See base class docs
123  virtual void invoke_motor_controllers(
124  const TSimulContext& context, std::vector<double>& out_force_per_wheel);
125 
126  private:
127  ControllerBasePtr m_controller;
128 };
129 }
virtual bool setTwistCommand(const double vx, const double wz)
const ControllerBasePtr & getController() const
virtual void invoke_motor_controllers(const TSimulContext &context, std::vector< double > &out_force_per_wheel)
ControllerBaseTempl< DynamicsDifferential > ControllerBase
virtual vec3 getVelocityLocalOdoEstimate() const
std::shared_ptr< ControllerBase > ControllerBasePtr
virtual void dynamics_load_params_from_xml(const rapidxml::xml_node< char > *xml_node)
#define DECLARES_REGISTER_VEHICLE_DYNAMICS(CLASS_NAME)
Definition: VehicleBase.h:296
virtual ControllerBaseInterface * getControllerInterface()
ControllerBasePtr m_controller
The installed controller.
double max_torque
Maximum abs. value torque (for clamp) [Nm].
ControllerBasePtr & getController()


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