DefaultFriction.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 
21  VehicleBase& my_vehicle, const rapidxml::xml_node<char>* node)
22  : FrictionBase(my_vehicle), mu_(0.8), C_damping_(1.0)
23 {
24  // Sanity: we can tolerate node==nullptr (=> means use default params).
25  if (node && 0 != strcmp(node->name(), "friction"))
26  throw std::runtime_error(
27  "<friction>...</friction> XML node was expected!!");
28 
29  // Parse XML params:
30  if (node)
33 }
34 
35 // See docs in base class.
36 mrpt::math::TVector2D DefaultFriction::evaluate_friction(
37  const FrictionBase::TFrictionInput& input) const
38 {
39  // Rotate wheel velocity vector from veh. frame => wheel frame
40  const mrpt::poses::CPose2D wRot(0, 0, input.wheel.yaw);
41 
42  // Velocity of the wheel cog in the frame of the wheel itself:
43  const mrpt::math::TVector2D vel_w =
44  wRot.inverseComposePoint(input.wheelCogLocalVel);
45 
46  // Action/Reaction, slippage, etc:
47  // --------------------------------------
48  const double mu = mu_;
49  const double gravity = myVehicle_.parent()->get_gravity();
50  const double partial_mass = input.weight / gravity + input.wheel.mass;
51  const double max_friction = mu * partial_mass * gravity;
52 
53  // 1) Lateral friction (decoupled sub-problem)
54  // --------------------------------------------
55  double wheel_lat_friction = 0.0; // direction: +y local wrt the wheel
56  {
57  // Impulse required to step the lateral slippage:
58  wheel_lat_friction = -vel_w.y * partial_mass / input.context.dt;
59 
60  wheel_lat_friction =
61  b2Clamp(wheel_lat_friction, -max_friction, max_friction);
62  }
63 
64  // 2) Longitudinal friction (decoupled sub-problem)
65  // -------------------------------------------------
66  double wheel_long_friction = 0.0; // direction: +x local wrt the wheel
67 
68  // (eq. 1)==> desired impulse in wheel spinning speed.
69  // wheel_C_lon_vel = vel_w.x - input.wheel.w * 0.5*input.wheel.diameter
70 
71  // It should be = 0 for no slippage (nonholonomic constraint): find out
72  // required wheel \omega:case '4':
73  const double R = 0.5 * input.wheel.diameter; // Wheel radius
74  const double lon_constraint_desired_wheel_w = vel_w.x / R;
75 
76  const double desired_wheel_w_impulse =
77  (lon_constraint_desired_wheel_w - input.wheel.getW());
78 
79  const double desired_wheel_alpha =
80  desired_wheel_w_impulse / input.context.dt;
81 
82  // (eq. 3)==> Find out F_r
83  // Iyy_w * \Delta\omega_w = dt*\tau- R*dt*Fri -C_damp * \omega_w * dt
84  // "Damping" / internal friction of the wheel's shaft, etc.
85  const double C_damping = C_damping_;
86  // const mrpt::math::TPoint2D wheel_damping(- C_damping *
87  // input.wheel_speed.x, 0.0);
88 
89  const double I_yy = input.wheel.Iyy;
90  double F_friction_lon = (input.motorTorque - I_yy * desired_wheel_alpha -
91  C_damping * input.wheel.getW()) /
92  R;
93 
94  // Slippage: The friction with the ground is not infinite:
95  F_friction_lon = b2Clamp(F_friction_lon, -max_friction, max_friction);
96 
97  // Recalc wheel ang. velocity impulse with this reduced force:
98  const double actual_wheel_alpha = (input.motorTorque - R * F_friction_lon -
99  C_damping * input.wheel.getW()) /
100  I_yy;
101 
102  // Apply impulse to wheel's spinning:
103  input.wheel.setW(
104  input.wheel.getW() + actual_wheel_alpha * input.context.dt);
105 
106  wheel_long_friction = F_friction_lon;
107 
108  // Resultant force: In local (x,y) coordinates (Newtons) wrt the Wheel
109  // -----------------------------------------------------------------------
110  const mrpt::math::TPoint2D result_force_wrt_wheel(
111  wheel_long_friction, wheel_lat_friction);
112 
113  // Rotate to put: Wheel frame ==> vehicle local framework:
114  mrpt::math::TVector2D res;
115  wRot.composePoint(result_force_wrt_wheel, res);
116  return res;
117 }
double mu_
friction coeficient (non-dimensional)
This file contains rapidxml parser and DOM implementation.
void setW(double val)
Spinning velocity (rad/s) wrt shaft.
Definition: Wheel.h:93
DefaultFriction(VehicleBase &my_vehicle, const rapidxml::xml_node< char > *node)
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
double C_damping_
For wheels "internal friction" (N*m*s/rad)
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
virtual mrpt::math::TVector2D evaluate_friction(const FrictionBase::TFrictionInput &input) const override
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
double Iyy
Definition: Wheel.h:49
double mass
[kg]
Definition: Wheel.h:45
const TParameterDefinitions params_
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:19