DefaultFriction.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
10 #include <mvsim/World.h>
11 #include <mvsim/VehicleBase.h>
13 
14 #include <rapidxml.hpp>
15 #include "xml_utils.h"
16 
17 using namespace mvsim;
18 
20  VehicleBase& my_vehicle, const rapidxml::xml_node<char>* node)
21  : FrictionBase(my_vehicle), m_mu(0.8), m_C_damping(1.0)
22 {
23  // Sanity: we can tolerate node==NULL (=> means use default params).
24  if (node && 0 != strcmp(node->name(), "friction"))
25  throw std::runtime_error(
26  "<friction>...</friction> XML node was expected!!");
27 
28  if (node)
29  {
30  // Parse params:
31  std::map<std::string, TParamEntry> params;
32  params["mu"] = TParamEntry("%lf", &m_mu);
33  params["C_damping"] = TParamEntry("%lf", &m_C_damping);
34 
35  // Parse XML params:
36  parse_xmlnode_children_as_param(*node, params);
37  }
38 }
39 
40 // See docs in base class.
42  const FrictionBase::TFrictionInput& input,
43  mrpt::math::TPoint2D& out_result_force_local) const
44 {
45  // Rotate wheel velocity vector from veh. frame => wheel frame
46  const mrpt::poses::CPose2D wRot(0, 0, input.wheel.yaw);
47  const mrpt::poses::CPose2D wRotInv(0, 0, -input.wheel.yaw);
48  mrpt::math::TPoint2D vel_w;
49  wRotInv.composePoint(input.wheel_speed, vel_w);
50 
51  // Action/Reaction, slippage, etc:
52  // --------------------------------------
53  const double mu = m_mu;
54  const double gravity = m_my_vehicle.getWorldObject()->get_gravity();
55  const double partial_mass = input.weight / gravity + input.wheel.mass;
56  const double max_friction = mu * partial_mass * gravity;
57 
58  // 1) Lateral friction (decoupled sub-problem)
59  // --------------------------------------------
60  double wheel_lat_friction = 0.0; // direction: +y local wrt the wheel
61  {
62  // Impulse required to step the lateral slippage:
63  wheel_lat_friction = -vel_w.y * partial_mass / input.context.dt;
64 
65  wheel_lat_friction =
66  b2Clamp(wheel_lat_friction, -max_friction, max_friction);
67  }
68 
69  // 2) Longitudinal friction (decoupled sub-problem)
70  // -------------------------------------------------
71  double wheel_long_friction = 0.0; // direction: +x local wrt the wheel
72 
73  // (eq. 1)==> desired impulse in wheel spinning speed.
74  // wheel_C_lon_vel = vel_w.x - input.wheel.w * 0.5*input.wheel.diameter
75 
76  // It should be = 0 for no slippage (nonholonomic constraint): find out
77  // required wheel \omega:case '4':
78  const double R = 0.5 * input.wheel.diameter; // Wheel radius
79  const double lon_constraint_desired_wheel_w = vel_w.x / R;
80  const double desired_wheel_w_impulse =
81  (lon_constraint_desired_wheel_w - input.wheel.getW());
82  const double desired_wheel_alpha =
83  desired_wheel_w_impulse / input.context.dt;
84 
85  // (eq. 3)==> Find out F_r
86  // Iyy_w * \Delta\omega_w = dt*\tau- R*dt*Fri -C_damp * \omega_w * dt
87  // "Damping" / internal friction of the wheel's shaft, etc.
88  const double C_damping = m_C_damping;
89  // const mrpt::math::TPoint2D wheel_damping(- C_damping *
90  // input.wheel_speed.x, 0.0);
91 
92  const double I_yy = input.wheel.Iyy;
93  double F_friction_lon = (input.motor_torque - I_yy * desired_wheel_alpha -
94  C_damping * input.wheel.getW()) /
95  R;
96 
97  // Slippage: The friction with the ground is not infinite:
98  F_friction_lon = b2Clamp(F_friction_lon, -max_friction, max_friction);
99 
100  // Recalc wheel ang. velocity impulse with this reduced force:
101  const double actual_wheel_alpha = (input.motor_torque - R * F_friction_lon -
102  C_damping * input.wheel.getW()) /
103  I_yy;
104 
105  // Apply impulse to wheel's spinning:
106  input.wheel.setW(
107  input.wheel.getW() + actual_wheel_alpha * input.context.dt);
108 
109  wheel_long_friction = F_friction_lon;
110 
111  // Resultant force: In local (x,y) coordinates (Newtons) wrt the Wheel
112  // -----------------------------------------------------------------------
113  const mrpt::math::TPoint2D result_force_wrt_wheel(
114  wheel_long_friction, wheel_lat_friction);
115 
116  // Rotate to put: Wheel frame ==> vehicle local framework:
117  wRot.composePoint(result_force_wrt_wheel, out_result_force_local);
118 }
This file contains rapidxml parser and DOM implementation.
void setW(double val)
Spinning velocity (rad/s) wrt shaft.
Definition: Wheel.h:63
DefaultFriction(VehicleBase &my_vehicle, const rapidxml::xml_node< char > *node)
double m_mu
friction coeficient (non-dimensional)
const TSimulContext & context
Definition: FrictionBase.h:33
double get_gravity() const
Definition: World.h:113
double dt
timestep
Definition: basic_types.h:57
World * getWorldObject()
Definition: VisualObject.h:29
void parse_xmlnode_children_as_param(const rapidxml::xml_node< char > &xml_node, const std::map< std::string, TParamEntry > &params, const char *function_name_context="")
Definition: xml_utils.cpp:196
double getW() const
Spinning velocity (rad/s) wrt shaft.
Definition: Wheel.h:62
Ch * name() const
Definition: rapidxml.hpp:673
double diameter
[m,rad] (in local coords)
Definition: Wheel.h:43
double yaw
Definition: Wheel.h:41
double Iyy
Definition: Wheel.h:46
double mass
[kg]
Definition: Wheel.h:45
mrpt::math::TPoint2D wheel_speed
Definition: FrictionBase.h:40
T b2Clamp(T a, T low, T high)
Definition: b2Math.h:654
double motor_torque
(Newtons), excluding the weight of the wheel itself.
Definition: FrictionBase.h:37
VehicleBase & m_my_vehicle
Definition: FrictionBase.h:64
virtual void evaluate_friction(const FrictionBase::TFrictionInput &input, mrpt::math::TPoint2D &out_result_force_local) const
double m_C_damping
For wheels "internal friction" (N*m*s/rad)


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40