// The tire for a wheel.
//
// Copyright (C) 2001--2019 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _TIRE_H_
#define _TIRE_H_
#include "../geometry/Material.hpp"
#include "../geometry/Three_Vector.hpp"
#include "Particle.hpp"
#include <array>
#include <vector>
namespace Vamos_Body
{
using V_Long = std::array<double, 11>;
using V_Trans = std::array<double, 15>;
using V_Align = std::array<double, 18>;
/// The frictional properties of the tire.
class Tire_Friction
{
public:
Tire_Friction(const V_Long& long_parameters,
const V_Trans& trans_parameters,
const V_Align& align_parameters);
/// @param hub_velocity The velocity vector of the wheel's reference frame.
/// @param patch_speed The rearward speed of the contact patch with respect to the
/// wheel's frame.
/// @return The friction vector calculated from the magic formula.
Vamos_Geometry::Three_Vector friction_forces(double normal_force, double friction_factor,
const Vamos_Geometry::Three_Vector& hub_velocity,
double patch_speed, double current_camber);
/// @return The value of the slide parameter.
double slide() const { return m_slide; }
/// @return The slip ratio that gives maximum force.
double peak_slip_ratio() const { return m_peak_slip; }
/// @return The slip angle that gives maximum force.
double peak_slip_angle() const { return m_peak_slip_angle; }
private:
/// The parameters of the longitudinal magic equation.
V_Long m_longitudital_parameters;
/// The parameters of the transverse magic equation.
V_Trans m_transverse_parameters;
/// The parameters of the magic equation for aligning torque.
V_Align m_aligning_parameters;
/// The slip that gives the maximum longitudinal force.
double m_peak_slip = 0.0;
/// The slip angle that gives the maximum transverse force.
double m_peak_slip_angle = 0.0;
/// The slip angle that gives the maximum aligning torque.
double m_peak_aligning_angle = 0.0;
/// A parameter that is used to set the volume of the tire squeal sound.
double m_slide = 0.0;
};
/// The tire for a wheel.
class Tire : public Particle
{
public:
Tire(double radius, double rolling_resistance_1, double rolling_resistance_2,
const Tire_Friction& friction, double hardness, double inertia, const Frame* parent = 0);
// Particle overrides
virtual void find_forces() override;
virtual void propagate(double time) override;
virtual void rewind() override;
/// Called by the wheel to update the tire.
void input(const Vamos_Geometry::Three_Vector& velocity, double normal_angular_velocity,
const Vamos_Geometry::Three_Vector& normal_force, double camber, double torque,
bool is_locked, const Vamos_Geometry::Material& surface_material);
/// @return The radius of the tire
double radius() const { return m_radius; }
/// @return The rotational speed of the tire.
double rotational_speed() const { return m_rotational_speed; }
/// @return The linear speed of the tread.
double speed() const { return m_rotational_speed * m_radius; }
/// @return The longitudinal (sigma) and transverse (alpha) slip ratios.
std::pair<double, double> slip() const;
double temperature() const { return m_temperature - 273.15; }
/// A traction factor that depends on tire temperature and wear.
double wear() const { return m_wear; }
double grip() const;
/// @return The linear sliding speed.
double slide() const { return m_slide; }
/// @return The slip ratio that gives maximum force.
double peak_slip_ratio() const { return m_tire_friction.peak_slip_ratio(); }
/// @return The slip angle that gives maximum force.
double peak_slip_angle() const { return m_tire_friction.peak_slip_angle(); }
/// @return The position of the contact patch in the wheel's
// coordinate system.
Vamos_Geometry::Three_Vector contact_position() const;
/// @return The normal force on this tire.
double normal_force() const { return m_normal_force; }
// Set the tire to its initial conditions.
void reset();
private:
/// Orient the tire's z-axis with the normal force.
void orient_frame(const Vamos_Geometry::Three_Vector& normal);
/// The radius of the tire.
double m_radius;
/// Linear rolling resistance on a hard surface.
double m_rolling_resistance_1;
/// Quadratic rolling resistance on a hard surface.
double m_rolling_resistance_2;
/// Object for calculating friction.
Tire_Friction m_tire_friction;
/// The rotational inertia of the tire.
double m_inertia;
/// The rotational speed of the tire in radians per second.
double m_rotational_speed = 0.0;
/// The rotational speed of in the previous time step.
double m_last_rotational_speed = 0.0;
/// How fast the tire is sliding.
double m_slide = 0.0;
/// How much the tire heats up due to applied forces.
double m_hardness;
/// The temperature of the tire, K.
double m_temperature = 345;
/// How much grip has been lost to tire wear.
double m_wear = 0.0;
// Input paremeters provided by the wheel.
/// The velocity of the wheel relative to the road.
Vamos_Geometry::Three_Vector m_velocity;
/// The angular velocity about the normal to the surface.
double m_normal_angular_velocity = 0.0;
/// The force perpendicular to the surface.
double m_normal_force = 0.0;
/// The current camber, supplied by the wheel.
double m_camber = 0.0;
/// The torque on the wheel due to acceleration or braking.
double m_applied_torque = 0.0;
/// True if the brake for this wheel is locked.
bool m_is_locked = false;
/// The surface that the tire is currently on.
Vamos_Geometry::Material m_surface_material;
};
} // namespace Vamos_Body
#endif // not _TIRE_H_