18 using namespace mvsim;
20 static double sign(
double x) {
return (
double)((x > 0) - (x < 0)); }
26 if (node && 0 != strcmp(node->name(),
"friction"))
27 throw std::runtime_error(
"<friction>...</friction> XML node was expected!!");
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;
57 const double mu =
mu_;
60 const double max_friction = mu * partial_mass * gravity;
64 double wheel_lat_friction = 0.0;
67 wheel_lat_friction = -vel_w.y * partial_mass / input.
context.
dt;
69 wheel_lat_friction =
b2Clamp(wheel_lat_friction, -max_friction, max_friction);
74 double wheel_long_friction = 0.0;
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;
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));
101 logger_.lock()->updateColumn(
"F_rr", F_rr);
104 const double I_yy = input.
wheel.
Iyy;
106 double F_friction_lon =
107 (input.
motorTorque - I_yy * desired_wheel_alpha - C_damping * input.
wheel.getW()) /
R +
111 F_friction_lon =
b2Clamp(F_friction_lon, -max_friction, max_friction);
114 const double actual_wheel_alpha =
115 (input.
motorTorque -
R * F_friction_lon - C_damping * input.
wheel.getW()) / I_yy;
120 wheel_long_friction = F_friction_lon;
124 const mrpt::math::TPoint2D result_force_wrt_wheel(wheel_long_friction, wheel_lat_friction);
127 mrpt::math::TVector2D res;
128 wRot.composePoint(result_force_wrt_wheel, res);