Skip to content

Commit

Permalink
Rearrange tire kinematics calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rserban committed Dec 2, 2022
1 parent f7b3910 commit c9167c8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 36 deletions.
25 changes: 7 additions & 18 deletions src/chrono_vehicle/wheeled_vehicle/ChTire.cpp
Expand Up @@ -59,35 +59,24 @@ void ChTire::Initialize(std::shared_ptr<ChWheel> wheel) {
// Calculate kinematics quantities (slip angle, longitudinal slip, camber angle,
// and toe-in angle) using the given state of the associated wheel.
// -----------------------------------------------------------------------------
void ChTire::CalculateKinematics(double time, const WheelState& state, const ChTerrain& terrain) {
void ChTire::CalculateKinematics(const WheelState& wheel_state,
const ChCoordsys<>& tire_frame) {
// Wheel normal (expressed in global frame)
ChVector<> wheel_normal = state.rot.GetYaxis();

// Terrain normal at wheel location (expressed in global frame)
ChVector<> Z_dir = terrain.GetNormal(state.pos);

// Longitudinal (heading) and lateral directions, in the terrain plane
ChVector<> X_dir = Vcross(wheel_normal, Z_dir);
X_dir.Normalize();
ChVector<> Y_dir = Vcross(Z_dir, X_dir);

// Tire reference coordinate system
ChMatrix33<> rot;
rot.Set_A_axis(X_dir, Y_dir, Z_dir);
ChCoordsys<> tire_csys(state.pos, rot.Get_A_quaternion());
ChVector<> wheel_normal = wheel_state.rot.GetYaxis();

// Express wheel linear velocity in tire frame
ChVector<> V = tire_csys.TransformDirectionParentToLocal(state.lin_vel);
ChVector<> V = tire_frame.TransformDirectionParentToLocal(wheel_state.lin_vel);

// Express wheel normal in tire frame
ChVector<> n = tire_csys.TransformDirectionParentToLocal(wheel_normal);
ChVector<> n = tire_frame.TransformDirectionParentToLocal(wheel_normal);

// Slip angle (positive sign = left turn, negative sign = right turn)
double abs_Vx = std::abs(V.x());
double zero_Vx = 1e-4;
m_slip_angle = (abs_Vx > zero_Vx) ? std::atan(V.y() / abs_Vx) : 0;

// Longitudinal slip (positive sign = driving, negative sign = breaking)
m_longitudinal_slip = (abs_Vx > zero_Vx) ? -(V.x() - state.omega * GetRadius()) / abs_Vx : 0;
m_longitudinal_slip = (abs_Vx > zero_Vx) ? -(V.x() - wheel_state.omega * GetRadius()) / abs_Vx : 0;

// Camber angle (positive sign = upper side tipping to the left, negative sign = upper side tipping to the right)
m_camber_angle = std::atan2(n.z(), n.y());
Expand Down
13 changes: 4 additions & 9 deletions src/chrono_vehicle/wheeled_vehicle/ChTire.h
Expand Up @@ -105,15 +105,11 @@ class CH_VEHICLE_API ChTire : public ChPart {
// allow extensions to Chrono::Vehicle in user code.

/// Initialize this tire subsystem by associating it to an existing wheel subsystem.
/// The tire mass and inertia are used to increment those of the associated suspension spindle body.
virtual void Initialize(std::shared_ptr<ChWheel> wheel);

/// Update the state of this tire system at the current time.
virtual void Synchronize(double time, ///< [in] current time
const ChTerrain& terrain ///< [in] reference to the terrain system
) {
CalculateKinematics(time, m_wheel->GetState(), terrain);
}
/// A derived class should also set the current slip, longitudinal slip, and camber angle.
virtual void Synchronize(double time, const ChTerrain& terrain) {}

/// Advance the state of this tire by the specified time step.
virtual void Advance(double step) {}
Expand All @@ -123,9 +119,8 @@ class CH_VEHICLE_API ChTire : public ChPart {
ChTire(const std::string& name);

/// Calculate kinematics quantities based on the given state of the associated wheel body.
void CalculateKinematics(double time, ///< [in] current time
const WheelState& wheel_state, ///< [in] current state of associated wheel body
const ChTerrain& terrain ///< [in] reference to the terrain system
void CalculateKinematics(const WheelState& wheel_state, ///< [in] current state of associated wheel body
const ChCoordsys<>& tire_frame ///< [in] tire contact frame
);

/// Get offset from spindle center.
Expand Down
7 changes: 4 additions & 3 deletions src/chrono_vehicle/wheeled_vehicle/tire/ChFialaTire.cpp
Expand Up @@ -67,10 +67,8 @@ void ChFialaTire::Initialize(std::shared_ptr<ChWheel> wheel) {

void ChFialaTire::Synchronize(double time,
const ChTerrain& terrain) {
WheelState wheel_state = m_wheel->GetState();
CalculateKinematics(time, wheel_state, terrain);

m_time = time;
WheelState wheel_state = m_wheel->GetState();

// Extract the wheel normal (expressed in global frame)
ChMatrix33<> A(wheel_state.rot);
Expand All @@ -96,6 +94,9 @@ void ChFialaTire::Synchronize(double time,
ChClampValue(mu, 0.1f, 1.0f);
m_mu = mu;

// Calculate tire kinematics
CalculateKinematics(wheel_state, m_data.frame);

if (m_data.in_contact) {
// Wheel velocity in the ISO-C Frame
ChVector<> vel = wheel_state.lin_vel;
Expand Down
4 changes: 3 additions & 1 deletion src/chrono_vehicle/wheeled_vehicle/tire/ChPac02Tire.cpp
Expand Up @@ -267,7 +267,6 @@ void ChPac02Tire::Initialize(std::shared_ptr<ChWheel> wheel) {

void ChPac02Tire::Synchronize(double time, const ChTerrain& terrain) {
WheelState wheel_state = m_wheel->GetState();
CalculateKinematics(time, wheel_state, terrain);

// Extract the wheel normal (expressed in global frame)
ChMatrix33<> A(wheel_state.rot);
Expand All @@ -293,6 +292,9 @@ void ChPac02Tire::Synchronize(double time, const ChTerrain& terrain) {
ChClampValue(mu, 0.1f, 1.0f);
m_mu = mu;

// Calculate tire kinematics
CalculateKinematics(wheel_state, m_data.frame);

if (m_data.in_contact) {
// Wheel velocity in the ISO-C Frame
ChVector<> vel = wheel_state.lin_vel;
Expand Down
4 changes: 3 additions & 1 deletion src/chrono_vehicle/wheeled_vehicle/tire/ChPac89Tire.cpp
Expand Up @@ -64,7 +64,6 @@ void ChPac89Tire::Initialize(std::shared_ptr<ChWheel> wheel) {
void ChPac89Tire::Synchronize(double time,
const ChTerrain& terrain) {
WheelState wheel_state = m_wheel->GetState();
CalculateKinematics(time, wheel_state, terrain);

// Extract the wheel normal (expressed in global frame)
ChMatrix33<> A(wheel_state.rot);
Expand All @@ -90,6 +89,9 @@ void ChPac89Tire::Synchronize(double time,
ChClampValue(mu, 0.1f, 1.0f);
m_mu = mu;

// Calculate tire kinematics
CalculateKinematics(wheel_state, m_data.frame);

if (m_data.in_contact) {
// Wheel velocity in the ISO-C Frame
ChVector<> vel = wheel_state.lin_vel;
Expand Down
1 change: 0 additions & 1 deletion src/chrono_vehicle/wheeled_vehicle/tire/ChPacejkaTire.cpp
Expand Up @@ -258,7 +258,6 @@ void ChPacejkaTire::Synchronize(double time,
}

m_tireState = m_wheel->GetState();
CalculateKinematics(time, m_tireState, terrain);

// Update the tire coordinate system.
m_simTime = time;
Expand Down
7 changes: 4 additions & 3 deletions src/chrono_vehicle/wheeled_vehicle/tire/ChTMeasyTire.cpp
Expand Up @@ -117,10 +117,8 @@ void ChTMeasyTire::Initialize(std::shared_ptr<ChWheel> wheel) {
// -----------------------------------------------------------------------------

void ChTMeasyTire::Synchronize(double time, const ChTerrain& terrain) {
WheelState wheel_state = m_wheel->GetState();
CalculateKinematics(time, wheel_state, terrain);

m_time = time;
WheelState wheel_state = m_wheel->GetState();

// Extract the wheel normal (expressed in global frame)
ChMatrix33<> A(wheel_state.rot);
Expand All @@ -147,6 +145,9 @@ void ChTMeasyTire::Synchronize(double time, const ChTerrain& terrain) {
ChClampValue(mu, 0.1f, 1.0f);
m_mu = mu;

// Calculate tire kinematics
CalculateKinematics(wheel_state, m_data.frame);

UpdateVerticalStiffness();

if (m_data.in_contact) {
Expand Down

0 comments on commit c9167c8

Please sign in to comment.