VehicleDifferential.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/PID_Controller.h>
13 #include <mvsim/VehicleBase.h>
14 
15 namespace mvsim
16 {
21 {
23  public:
24  enum
25  {
26  WHEEL_L = 0,
27  WHEEL_R = 1
28  };
29 
30  DynamicsDifferential(World* parent);
31 
36  {
38  };
40  {
41  double wheel_torque_l, wheel_torque_r;
42  TControllerOutput() : wheel_torque_l(0), wheel_torque_r(0) {}
43  };
44 
47  typedef std::shared_ptr<ControllerBase> ControllerBasePtr;
48 
49  class ControllerRawForces : public ControllerBase
50  {
51  public:
53  : ControllerBase(veh),
54  setpoint_wheel_torque_l(0),
55  setpoint_wheel_torque_r(0)
56  {
57  }
58  static const char* class_name() { return "raw"; }
61  double setpoint_wheel_torque_l, setpoint_wheel_torque_r;
62  virtual void control_step(
65  virtual void teleop_interface(
66  const TeleopInput& in, TeleopOutput& out) override;
67  };
68 
71  class ControllerTwistPID : public ControllerBase
72  {
73  public:
75  static const char* class_name() { return "twist_pid"; }
79  setpoint_ang_speed;
80  virtual void control_step(
83  virtual void load_config(const rapidxml::xml_node<char>& node) override;
84  virtual void teleop_interface(
85  const TeleopInput& in, TeleopOutput& out) override;
86 
87  double KP, KI, KD;
88  double max_torque;
89  // See base docs.
90  virtual bool setTwistCommand(const double vx, const double wz) override
91  {
92  setpoint_lin_speed = vx;
93  setpoint_ang_speed = wz;
94  return true;
95  }
96 
97  private:
98  double m_distWheels;
99  PID_Controller m_PID[2];
100  };
101 
102  const ControllerBasePtr& getController() const { return m_controller; }
103  ControllerBasePtr& getController() { return m_controller; }
105  {
106  return m_controller.get();
107  }
108  // end controllers
110 
111  virtual mrpt::math::TTwist2D getVelocityLocalOdoEstimate() const override;
112 
113  protected:
114  // See base class docs
115  virtual void dynamics_load_params_from_xml(
116  const rapidxml::xml_node<char>* xml_node) override;
117  // See base class docs
118  virtual void invoke_motor_controllers(
119  const TSimulContext& context,
120  std::vector<double>& out_force_per_wheel) override;
121 
122  private:
123  ControllerBasePtr m_controller;
124 };
125 } // namespace mvsim
virtual void dynamics_load_params_from_xml(const rapidxml::xml_node< char > *xml_node) override
const ControllerBasePtr & getController() const
virtual bool setTwistCommand(const double vx, const double wz) override
GLuint in
virtual void invoke_motor_controllers(const TSimulContext &context, std::vector< double > &out_force_per_wheel) override
ControllerBaseTempl< DynamicsDifferential > ControllerBase
virtual ControllerBaseInterface * getControllerInterface() override
std::shared_ptr< ControllerBase > ControllerBasePtr
#define DECLARES_REGISTER_VEHICLE_DYNAMICS(CLASS_NAME)
Definition: VehicleBase.h:249
ControllerBasePtr m_controller
The installed controller.
virtual mrpt::math::TTwist2D getVelocityLocalOdoEstimate() const override
double max_torque
Maximum abs. value torque (for clamp) [Nm].
ControllerBasePtr & getController()


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51