WardIagnemmaFriction.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2024 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 
11 #include <mvsim/VehicleBase.h>
12 #include <mvsim/World.h>
13 
14 #include <rapidxml.hpp>
15 
16 #include "xml_utils.h"
17 
18 using namespace mvsim;
19 
20 static double sign(double x) { return (double)((x > 0) - (x < 0)); }
22  VehicleBase& my_vehicle, const rapidxml::xml_node<char>* node)
23  : FrictionBase(my_vehicle), mu_(0.8), C_damping_(1.0)
24 {
25  // Sanity: we can tolerate node==nullptr (=> means use default params).
26  if (node && 0 != strcmp(node->name(), "friction"))
27  throw std::runtime_error("<friction>...</friction> XML node was expected!!");
28 
29  if (node)
30  {
31  // Parse params:
32  TParameterDefinitions params;
33  params["mu"] = TParamEntry("%lf", &mu_);
34  params["C_damping"] = TParamEntry("%lf", &C_damping_);
35  params["A_roll"] = TParamEntry("%lf", &A_roll_);
36  params["R1"] = TParamEntry("%lf", &R1_);
37  params["R2"] = TParamEntry("%lf", &R2_);
38  // Parse XML params:
40  *node, params, world_->user_defined_variables(), "WardIagnemmaFriction",
41  my_vehicle.parent() /*for logger*/);
42  }
43 }
44 
45 // See docs in base class.
47  const FrictionBase::TFrictionInput& input) const
48 {
49  // Rotate wheel velocity vector from veh. frame => wheel frame
50  const mrpt::poses::CPose2D wRot(0, 0, input.wheel.yaw);
51  const mrpt::poses::CPose2D wRotInv(0, 0, -input.wheel.yaw);
52  mrpt::math::TPoint2D vel_w;
53  wRotInv.composePoint(input.wheelCogLocalVel, vel_w);
54 
55  // Action/Reaction, slippage, etc:
56  // --------------------------------------
57  const double mu = mu_;
58  const double gravity = myVehicle_.parent()->get_gravity();
59  const double partial_mass = input.weight / gravity + input.wheel.mass;
60  const double max_friction = mu * partial_mass * gravity;
61 
62  // 1) Lateral friction (decoupled sub-problem)
63  // --------------------------------------------
64  double wheel_lat_friction = 0.0; // direction: +y local wrt the wheel
65  {
66  // Impulse required to step the lateral slippage:
67  wheel_lat_friction = -vel_w.y * partial_mass / input.context.dt;
68 
69  wheel_lat_friction = b2Clamp(wheel_lat_friction, -max_friction, max_friction);
70  }
71 
72  // 2) Longitudinal friction (decoupled sub-problem)
73  // -------------------------------------------------
74  double wheel_long_friction = 0.0; // direction: +x local wrt the wheel
75 
76  // (eq. 1)==> desired impulse in wheel spinning speed.
77  // wheel_C_lon_vel = vel_w.x - input.wheel.w * 0.5*input.wheel.diameter
78 
79  // It should be = 0 for no slippage (nonholonomic constraint): find out
80  // required wheel \omega:case '4':
81  const double R = 0.5 * input.wheel.diameter; // Wheel radius
82  const double lon_constraint_desired_wheel_w = vel_w.x / R;
83  const double desired_wheel_w_impulse = (lon_constraint_desired_wheel_w - input.wheel.getW());
84  const double desired_wheel_alpha = desired_wheel_w_impulse / input.context.dt;
85 
86  // (eq. 3)==> Find out F_r
87  // Iyy_w * \Delta\omega_w = dt*\tau- R*dt*Fri -C_damp * \omega_w * dt
88  // "Damping" / internal friction of the wheel's shaft, etc.
89  const double C_damping = C_damping_;
90 
91  // const mrpt::math::TPoint2D wheel_damping(- C_damping *
92  // input.wheel_speed.x, 0.0);
93 
94  // Actually, Ward-Iagnemma rolling resistance is here (longitudal one):
95 
96  const double F_rr = -sign(vel_w.x) * partial_mass * gravity *
97  (R1_ * (1 - exp(-A_roll_ * fabs(vel_w.x))) + R2_ * fabs(vel_w.x));
98 
99  if (!logger_.expired())
100  {
101  logger_.lock()->updateColumn("F_rr", F_rr);
102  }
103 
104  const double I_yy = input.wheel.Iyy;
105  // There are torques this is force v
106  double F_friction_lon =
107  (input.motorTorque - I_yy * desired_wheel_alpha - C_damping * input.wheel.getW()) / R +
108  F_rr;
109 
110  // Slippage: The friction with the ground is not infinite:
111  F_friction_lon = b2Clamp(F_friction_lon, -max_friction, max_friction);
112 
113  // Recalc wheel ang. velocity impulse with this reduced force:
114  const double actual_wheel_alpha =
115  (input.motorTorque - R * F_friction_lon - C_damping * input.wheel.getW()) / I_yy;
116 
117  // Apply impulse to wheel's spinning:
118  input.wheel.setW(input.wheel.getW() + actual_wheel_alpha * input.context.dt);
119 
120  wheel_long_friction = F_friction_lon;
121 
122  // Resultant force: In local (x,y) coordinates (Newtons) wrt the Wheel
123  // -----------------------------------------------------------------------
124  const mrpt::math::TPoint2D result_force_wrt_wheel(wheel_long_friction, wheel_lat_friction);
125 
126  // Rotate to put: Wheel frame ==> vehicle local framework:
127  mrpt::math::TVector2D res;
128  wRot.composePoint(result_force_wrt_wheel, res);
129  return res;
130 }
move-object-example.R
int R
Definition: move-object-example.py:41
mvsim::VisualObject::parent
World * parent()
Definition: VisualObject.h:51
mvsim
Definition: Client.h:21
mvsim::FrictionBase::TFrictionInput::context
const TSimulContext & context
Definition: FrictionBase.h:40
mvsim::FrictionBase
Definition: FrictionBase.h:26
mvsim::Wheel::yaw
double yaw
Definition: Wheel.h:40
mvsim::WardIagnemmaFriction::A_roll_
double A_roll_
Definition: WardIagnemmaFriction.h:41
mvsim::TParamEntry
Definition: TParameterDefinitions.h:38
mvsim::parse_xmlnode_children_as_param
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const TParameterDefinitions &params, const std::map< std::string, std::string > &variableNamesValues={}, const char *functionNameContext="", mrpt::system::COutputLogger *logger=nullptr)
Definition: xml_utils.cpp:215
World.h
mvsim::WardIagnemmaFriction::R1_
double R1_
Definition: WardIagnemmaFriction.h:41
mvsim::World::get_gravity
double get_gravity() const
Definition: World.h:154
mvsim::FrictionBase::TFrictionInput
Definition: FrictionBase.h:38
mvsim::FrictionBase::myVehicle_
VehicleBase & myVehicle_
Definition: FrictionBase.h:71
xml_utils.h
mvsim::TSimulContext::dt
double dt
timestep
Definition: basic_types.h:63
sign
static double sign(double x)
Definition: WardIagnemmaFriction.cpp:20
VehicleBase.h
mvsim::Wheel::diameter
double diameter
Definition: Wheel.h:46
mvsim::Wheel::Iyy
double Iyy
Definition: Wheel.h:51
b2Clamp
T b2Clamp(T a, T low, T high)
Definition: b2_math.h:648
mvsim::FrictionBase::world_
World * world_
Definition: FrictionBase.h:70
WardIagnemmaFriction.h
mvsim::WardIagnemmaFriction::mu_
double mu_
friction coeficient (non-dimensional)
Definition: WardIagnemmaFriction.h:38
mvsim::TParameterDefinitions
std::map< std::string, TParamEntry > TParameterDefinitions
Definition: TParameterDefinitions.h:64
mvsim::WardIagnemmaFriction::evaluate_friction
virtual mrpt::math::TVector2D evaluate_friction(const FrictionBase::TFrictionInput &input) const override
Definition: WardIagnemmaFriction.cpp:46
mvsim::WardIagnemmaFriction::WardIagnemmaFriction
WardIagnemmaFriction(VehicleBase &my_vehicle, const rapidxml::xml_node< char > *node)
Definition: WardIagnemmaFriction.cpp:21
mvsim::FrictionBase::TFrictionInput::wheel
Wheel & wheel
Definition: FrictionBase.h:41
mvsim::WardIagnemmaFriction::C_damping_
double C_damping_
For wheels "internal friction" (N*m*s/rad)
Definition: WardIagnemmaFriction.h:39
mvsim::WardIagnemmaFriction::R2_
double R2_
Definition: WardIagnemmaFriction.h:41
mvsim::VehicleBase
Definition: VehicleBase.h:44
rapidxml::xml_node< char >
mvsim::World::user_defined_variables
const std::map< std::string, std::string > & user_defined_variables() const
Definition: World.h:390
mvsim::Wheel::mass
double mass
[kg]
Definition: Wheel.h:47
mvsim::FrictionBase::TFrictionInput::weight
double weight
Definition: FrictionBase.h:46
mvsim::FrictionBase::TFrictionInput::wheelCogLocalVel
mrpt::math::TVector2D wheelCogLocalVel
Definition: FrictionBase.h:54
rapidxml.hpp
mvsim::FrictionBase::TFrictionInput::motorTorque
double motorTorque
Definition: FrictionBase.h:50
mvsim::FrictionBase::logger_
std::weak_ptr< CSVLogger > logger_
Definition: FrictionBase.h:73


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08