MVSim
Lightweight simulator for 2.5D vehicles and robots
FrictionBase.h
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2026 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/ClassFactory.h>
13 #include <mvsim/CsvLogger.h>
14 #include <mvsim/Wheel.h>
15 #include <mvsim/basic_types.h> // fwrd decls.
16 
17 #include <optional>
18 
19 namespace mvsim
20 {
29 {
30  public:
31  using Ptr = std::shared_ptr<FrictionBase>;
32 
33  FrictionBase(VehicleBase& my_vehicle);
34  virtual ~FrictionBase();
35 
38  static FrictionBase::Ptr factory(VehicleBase& parent, const rapidxml::xml_node<char>* xml_node);
39 
41  {
42  const TSimulContext& context;
43  Wheel& wheel;
44 
48  double Fz = 0;
49 
52  double motorTorque = 0;
53 
56  mrpt::math::TVector2D wheelCogLocalVel{0, 0};
57 
62  mrpt::math::TVector2D gravSlopeForce{0, 0};
63 
65  std::optional<double> mu_override;
66 
68  std::optional<double> C_rr_override;
69 
70  TFrictionInput(const TSimulContext& _context, Wheel& _wheel)
71  : context(_context), wheel(_wheel)
72  {
73  }
74  };
75 
78  virtual mrpt::math::TVector2D evaluate_friction(
79  const FrictionBase::TFrictionInput& input) const = 0;
80 
81  bool hasLogger() const { return logger_.has_value(); }
82  void setLogger(const std::weak_ptr<CSVLogger>& logger);
83 
84  protected:
85  World* world_;
86  VehicleBase& myVehicle_;
87 
88  std::optional<std::weak_ptr<CSVLogger>> logger_;
89 };
90 
91 // Class factory:
92 typedef ClassFactory<FrictionBase, VehicleBase&, const rapidxml::xml_node<char>*>
93  TClassFactory_friction;
94 extern TClassFactory_friction classFactory_friction;
95 
96 #define DECLARES_REGISTER_FRICTION(CLASS_NAME) \
97  DECLARES_REGISTER_CLASS2( \
98  CLASS_NAME, FrictionBase, VehicleBase&, const rapidxml::xml_node<char>*)
99 
100 #define REGISTER_FRICTION(TEXTUAL_NAME, CLASS_NAME) \
101  REGISTER_CLASS2(TClassFactory_friction, classFactory_friction, TEXTUAL_NAME, CLASS_NAME)
102 } // namespace mvsim
Definition: FrictionBase.h:29
virtual mrpt::math::TVector2D evaluate_friction(const FrictionBase::TFrictionInput &input) const =0
static FrictionBase::Ptr factory(VehicleBase &parent, const rapidxml::xml_node< char > *xml_node)
Definition: VehicleBase.h:44
Definition: Wheel.h:34
Definition: World.h:132
Definition: FrictionBase.h:41
double motorTorque
Definition: FrictionBase.h:52
mrpt::math::TVector2D gravSlopeForce
Definition: FrictionBase.h:62
std::optional< double > C_rr_override
Definition: FrictionBase.h:68
double Fz
Definition: FrictionBase.h:48
mrpt::math::TVector2D wheelCogLocalVel
Definition: FrictionBase.h:56
std::optional< double > mu_override
Definition: FrictionBase.h:65
Definition: basic_types.h:58