DefaultFriction.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2020 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), m_mu(0.8), m_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) parse_xmlnode_children_as_param(*node, m_params);
31 }
32 
33 // See docs in base class.
36  mrpt::math::TPoint2D& out_result_force_local) const
37 {
38  // Rotate wheel velocity vector from veh. frame => wheel frame
39  const mrpt::poses::CPose2D wRot(0, 0, input.wheel.yaw);
40  const mrpt::poses::CPose2D wRotInv(0, 0, -input.wheel.yaw);
42  wRotInv.composePoint(input.wheel_speed, vel_w);
43 
44  // Action/Reaction, slippage, etc:
45  // --------------------------------------
46  const double mu = m_mu;
47  const double gravity = m_my_vehicle.getWorldObject()->get_gravity();
48  const double partial_mass = input.weight / gravity + input.wheel.mass;
49  const double max_friction = mu * partial_mass * gravity;
50 
51  // 1) Lateral friction (decoupled sub-problem)
52  // --------------------------------------------
53  double wheel_lat_friction = 0.0; // direction: +y local wrt the wheel
54  {
55  // Impulse required to step the lateral slippage:
56  wheel_lat_friction = -vel_w.y * partial_mass / input.context.dt;
57 
58  wheel_lat_friction =
59  b2Clamp(wheel_lat_friction, -max_friction, max_friction);
60  }
61 
62  // 2) Longitudinal friction (decoupled sub-problem)
63  // -------------------------------------------------
64  double wheel_long_friction = 0.0; // direction: +x local wrt the wheel
65 
66  // (eq. 1)==> desired impulse in wheel spinning speed.
67  // wheel_C_lon_vel = vel_w.x - input.wheel.w * 0.5*input.wheel.diameter
68 
69  // It should be = 0 for no slippage (nonholonomic constraint): find out
70  // required wheel \omega:case '4':
71  const double R = 0.5 * input.wheel.diameter; // Wheel radius
72  const double lon_constraint_desired_wheel_w = vel_w.x / R;
73  const double desired_wheel_w_impulse =
74  (lon_constraint_desired_wheel_w - input.wheel.getW());
75  const double desired_wheel_alpha =
76  desired_wheel_w_impulse / input.context.dt;
77 
78  // (eq. 3)==> Find out F_r
79  // Iyy_w * \Delta\omega_w = dt*\tau- R*dt*Fri -C_damp * \omega_w * dt
80  // "Damping" / internal friction of the wheel's shaft, etc.
81  const double C_damping = m_C_damping;
82  // const mrpt::math::TPoint2D wheel_damping(- C_damping *
83  // input.wheel_speed.x, 0.0);
84 
85  const double I_yy = input.wheel.Iyy;
86  double F_friction_lon = (input.motor_torque - I_yy * desired_wheel_alpha -
87  C_damping * input.wheel.getW()) /
88  R;
89 
90  // Slippage: The friction with the ground is not infinite:
91  F_friction_lon = b2Clamp(F_friction_lon, -max_friction, max_friction);
92 
93  // Recalc wheel ang. velocity impulse with this reduced force:
94  const double actual_wheel_alpha = (input.motor_torque - R * F_friction_lon -
95  C_damping * input.wheel.getW()) /
96  I_yy;
97 
98  // Apply impulse to wheel's spinning:
99  input.wheel.setW(
100  input.wheel.getW() + actual_wheel_alpha * input.context.dt);
101 
102  wheel_long_friction = F_friction_lon;
103 
104  // Resultant force: In local (x,y) coordinates (Newtons) wrt the Wheel
105  // -----------------------------------------------------------------------
106  const mrpt::math::TPoint2D result_force_wrt_wheel(
107  wheel_long_friction, wheel_lat_friction);
108 
109  // Rotate to put: Wheel frame ==> vehicle local framework:
110  wRot.composePoint(result_force_wrt_wheel, out_result_force_local);
111 }
This file contains rapidxml parser and DOM implementation.
void setW(double val)
Spinning velocity (rad/s) wrt shaft.
Definition: Wheel.h:70
const TParameterDefinitions m_params
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="")
Definition: xml_utils.cpp:179
GLenum GLenum GLenum input
void composePoint(double lx, double ly, double &gx, double &gy) const
double m_mu
friction coeficient (non-dimensional)
const TSimulContext & context
Definition: FrictionBase.h:35
double get_gravity() const
Definition: World.h:82
double dt
timestep
Definition: basic_types.h:61
World * getWorldObject()
Definition: VisualObject.h:34
double getW() const
Spinning velocity (rad/s) wrt shaft.
Definition: Wheel.h:69
Ch * name() const
Definition: rapidxml.hpp:673
double diameter
Definition: Wheel.h:39
double yaw
Definition: Wheel.h:36
double Iyy
Definition: Wheel.h:44
double mass
[kg]
Definition: Wheel.h:40
mrpt::math::TPoint2D wheel_speed
Definition: FrictionBase.h:42
T b2Clamp(T a, T low, T high)
Definition: b2Math.h:653
double motor_torque
(Newtons), excluding the weight of the wheel itself.
Definition: FrictionBase.h:39
VehicleBase & m_my_vehicle
Definition: FrictionBase.h:66
const float R
virtual void evaluate_friction(const FrictionBase::TFrictionInput &input, mrpt::math::TPoint2D &out_result_force_local) const override
double m_C_damping
For wheels "internal friction" (N*m*s/rad)


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51