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


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