VehicleDifferential.h
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2023 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 <mrpt/math/TPoint2D.h>
13 #include <mvsim/PID_Controller.h>
14 #include <mvsim/VehicleBase.h>
15 
16 namespace mvsim
17 {
25 {
27  public:
28  enum
29  {
30  // common to all:
31  WHEEL_L = 0,
32  WHEEL_R = 1,
33  // 3 wheels:
35  // 4 wheels:
36  WHEEL_LR = 0,
37  WHEEL_RR = 1,
38  WHEEL_LF = 2,
40  };
41 
43  {
44  ConfigPerWheel() = default;
46  const std::string& _name, const mrpt::math::TPoint2D& _pos)
47  : name(_name), pos(_pos)
48  {
49  }
50 
51  std::string name;
52  mrpt::math::TPoint2D pos;
53  };
54 
57  parent, {
58  {"l_wheel", {0.0, 0.5}},
59  {"r_wheel", {0.0, -0.5}},
60  })
61  {
62  }
63 
65  World* parent, const std::vector<ConfigPerWheel>& cfgPerWheel);
66 
71  {
73  };
74 
76  {
77  TControllerOutput() = default;
78 
79  double wheel_torque_l = 0;
80  double wheel_torque_r = 0;
81  };
82 
85 
87  {
88  public:
90 
91  static const char* class_name() { return "raw"; }
92 
95  double setpoint_wheel_torque_l = 0, setpoint_wheel_torque_r = 0;
96 
97  double setpoint_teleop_steps = 5e-2;
98 
99  virtual void control_step(
102  virtual void teleop_interface(
103  const TeleopInput& in, TeleopOutput& out) override;
104  };
105 
109  {
110  public:
112  static const char* class_name() { return "twist_pid"; }
113 
114  virtual void control_step(
117 
118  virtual void load_config(const rapidxml::xml_node<char>& node) override;
119  virtual void teleop_interface(
120  const TeleopInput& in, TeleopOutput& out) override;
121 
123  double KP = 10, KI = 0, KD = 0;
124 
126  double max_torque = 100;
127 
128  // See base docs.
129  bool setTwistCommand(const mrpt::math::TTwist2D& t) override
130  {
131  setpointMtx_.lock();
132  setpoint_ = t;
133  setpointMtx_.unlock();
134  return true;
135  }
136 
138  mrpt::math::TTwist2D setpoint() const
139  {
140  setpointMtx_.lock();
141  auto t = setpoint_;
142  setpointMtx_.unlock();
143  return t;
144  }
145 
146  private:
147  double distWheels_ = 0;
148  std::array<PID_Controller, 2> PIDs_;
149  mrpt::math::TTwist2D setpoint_{0, 0, 0};
150  mutable std::mutex setpointMtx_;
151  };
152 
157  {
158  public:
160  static const char* class_name() { return "twist_ideal"; }
161 
162  void control_step(
165  void on_post_step(const TSimulContext& context) override;
166 
167  virtual void teleop_interface(
168  const TeleopInput& in, TeleopOutput& out) override;
169 
170  // See base docs.
171  bool setTwistCommand(const mrpt::math::TTwist2D& t) override
172  {
173  setpointMtx_.lock();
174  setpoint_ = t;
175  setpointMtx_.unlock();
176  return true;
177  }
178 
180  mrpt::math::TTwist2D setpoint() const
181  {
182  setpointMtx_.lock();
183  auto t = setpoint_;
184  setpointMtx_.unlock();
185  return t;
186  }
187 
188  private:
189  double distWheels_ = 0;
190  mrpt::math::TTwist2D setpoint_{0, 0, 0};
191  mutable std::mutex setpointMtx_;
192  };
193 
194  const ControllerBase::Ptr& getController() const { return controller_; }
197  {
198  return controller_.get();
199  }
200  // end controllers
202 
203  virtual mrpt::math::TTwist2D getVelocityLocalOdoEstimate() const override;
204 
205  protected:
206  // See base class docs
207  virtual void dynamics_load_params_from_xml(
208  const rapidxml::xml_node<char>* xml_node) override;
209  // See base class docs
210  virtual std::vector<double> invoke_motor_controllers(
211  const TSimulContext& context) override;
213  const TSimulContext& context) override;
214 
216  const std::vector<ConfigPerWheel> configPerWheel_;
217 
218  private:
220 };
221 
223 {
225 
226  public:
229  parent, {
230  {"l_wheel", {0.0, 0.5}},
231  {"r_wheel", {0.0, -0.5}},
232  {"caster_wheel", {0.5, 0.0}},
233  })
234  {
235  }
236 };
237 
239 {
241 
242  public:
245  parent, {
246  {"lr_wheel", {0.0, 0.5}},
247  {"rr_wheel", {0.0, -0.5}},
248  {"lf_wheel", {0.5, 0.5}},
249  {"rf_wheel", {0.5, -0.5}},
250  })
251  {
252  }
253 };
254 
255 } // namespace mvsim
ConfigPerWheel(const std::string &_name, const mrpt::math::TPoint2D &_pos)
bool setTwistCommand(const mrpt::math::TTwist2D &t) override
ControllerBase::Ptr & getController()
ControllerBase::Ptr controller_
The installed controller.
virtual void dynamics_load_params_from_xml(const rapidxml::xml_node< char > *xml_node) override
virtual std::vector< double > invoke_motor_controllers(const TSimulContext &context) override
geometry_msgs::TransformStamped t
virtual void invoke_motor_controllers_post_step(const TSimulContext &context) override
bool setTwistCommand(const mrpt::math::TTwist2D &t) override
virtual ControllerBaseInterface * getControllerInterface() override
std::shared_ptr< ControllerBaseTempl< VEH_DYNAMICS > > Ptr
#define DECLARES_REGISTER_VEHICLE_DYNAMICS(CLASS_NAME)
Definition: VehicleBase.h:262
virtual mrpt::math::TTwist2D getVelocityLocalOdoEstimate() const override
const std::vector< ConfigPerWheel > configPerWheel_
Defined at ctor time:
const ControllerBase::Ptr & getController() const


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21