include/vamos/body/Suspension.h

Go to the documentation of this file.
00001 //  Suspension.h - the suspension component for a wheel.
00002 //
00003 //  Copyright (C) 2001--2002 Sam Varner
00004 //
00005 //  This file is part of Vamos Automotive Simulator.
00006 //
00007 //  This program is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU General Public License as published by
00009 //  the Free Software Foundation; either version 2 of the License, or
00010 //  (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef _SUSPENSION_H_
00022 #define _SUSPENSION_H_
00023 
00024 #include <vamos/body/Particle.h>
00025 #include <vamos/geometry/Constants.h>
00026 #include <vamos/geometry/Three_Vector.h>
00027 
00028 #include <GL/gl.h>
00029 
00030 #include <vector>
00031 #include <string>
00032 
00033 namespace Vamos_Body
00034 {
00035   struct Suspension_Model;
00036 
00037   class Hinge : public Particle
00038   {
00039   public:
00040         Hinge (const Vamos_Geometry::Three_Vector& position);
00041 
00042         void input (const Vamos_Geometry::Three_Vector& torque, 
00043                                 const Vamos_Geometry::Three_Vector& radius);
00044   };
00045 
00046   //* The suspension component for a wheel.
00047   class Suspension : public Particle
00048   {
00049         //** Static Member
00050 
00051         // The axis of rotation for steering.
00052         const static Vamos_Geometry::Three_Vector STEER_AXIS;
00053 
00054         Hinge* mp_hinge;
00055         Vamos_Geometry::Three_Vector m_radius;
00056         Vamos_Geometry::Three_Vector m_tangent;
00057         double m_radius_magnitude;
00058         double m_angle;
00059         double m_initial_z;
00060 
00061         // The spring constant.
00062         double m_spring_constant;
00063 
00064         // Damping for compression.
00065         double m_bounce;
00066 
00067         // Damping for decompression.
00068         double m_rebound;
00069 
00070         // How far the suspension can be displaced before bottoming out.
00071         double m_travel;
00072 
00073         // The current displacement of the suspension.  A positive
00074         // displacement means compression.
00075         double m_displacement;
00076         //double m_overdisplacement;
00077 
00078         // The size of the last time step handled by propagate().
00079         double m_time_step;
00080 
00081         // How fast the suspension is being compressed.
00082         double m_compression_velocity;
00083 
00084         // How fast the suspension can be compressed before the damper
00085         // locks up.
00086         double m_max_compression_velocity;
00087 
00088         // true if the displacement has exceeded `m_travel', false
00089         // otherwise.
00090         bool m_bottomed_out;
00091 
00092         // The spring constant for the anti-roll bar that connects this
00093         // suspension component with another.
00094         double m_anti_roll_k;
00095 
00096         // The suspension component that this one is connected to with an
00097         // anti-roll bar.
00098         Suspension* m_anti_roll_suspension;
00099 
00100         Vamos_Geometry::Three_Vector m_wheel_force;
00101 
00102         // The deflection of the tire in radians due to steering.
00103         double m_steer_angle;
00104 
00105         // The static camber angle in radians.  Positive camber is a
00106         // rotation that moves the tops of the tires away from the center
00107         // of the car.  So the direction of the rotation depends on the
00108         // value of m_side.
00109         double m_camber;
00110 
00111         // The caster angle in radians.
00112         double m_caster;
00113 
00114         // The toe angle in radians.  Positive is toe-in.
00115         double m_toe;
00116 
00117         // The side, RIGHT or LEFT, that the suspension is on.  This is
00118         // used to choose the right direction for camber, caster and toe
00119         // adjustments.
00120         Vamos_Geometry::Side m_side;
00121 
00122         // The orientation of the wheel in the absence of steering and
00123         // displacement.
00124         Vamos_Geometry::Three_Matrix m_static_orientation;
00125 
00126         Vamos_Geometry::Three_Vector m_normal;
00127 
00128         //std::vector <Suspension_Model*> m_models;
00129 
00130   public:
00131         Suspension (const Vamos_Geometry::Three_Vector& position,
00132                                 const Vamos_Geometry::Three_Vector& center_of_translation,
00133                                 Vamos_Geometry::Side side_of_car, double spring_constant, 
00134                                 double bounce, double rebound, double travel,
00135                                 double max_compression_velocity);
00136 
00137         ~Suspension ();
00138 
00139         //** Geometry-setting methods.  The arguments are in degrees.
00140 
00141         // Set the steering angle.
00142         void steer (double degree_angle);
00143 
00144         double compression_velocity() {return m_compression_velocity;}
00145         void set_compression_velocity(double newcv) { m_compression_velocity = newcv;}
00146         void set_displacement(double newdisp) {m_displacement = newdisp;}
00147   
00148         // Set the camber angle.
00149         void camber (double degree_angle);
00150 
00151         // Set the caster angle.
00152         void caster (double degree_angle);
00153 
00154         // Set the toe angle.
00155         void toe (double degree_angle);
00156 
00157         Hinge* hinge () const { return mp_hinge; }
00158 
00159         Vamos_Geometry::Three_Vector force () const { return Particle::force (); }
00160         Vamos_Geometry::Three_Vector torque () const 
00161         { return Particle::torque (); }
00162 
00163         void input (const Vamos_Geometry::Three_Vector& wheel_force,
00164                                 const Vamos_Geometry::Three_Vector& normal);
00165 
00166         void torque (double wheel_torque);
00167 
00168         // Calculate the force exerted by the suspension in its current state.
00169         void find_forces ();
00170 
00171         // Advance this suspension component forward in time by TIME.
00172         void propagate (double time);
00173 
00174         // Undo the last propagation.
00175         void rewind ();
00176 
00177         // Specify the suspension component that is attached to this one
00178         // with an anti-roll bar.  The anti-roll bar will have a spring
00179         // constant of SPRING_CONSTANT.
00180         void anti_roll (Suspension* other, double spring_constant);
00181 
00182         // Displace this suspension component by DISTANCE.  A positive
00183         // DISTANCE means compression.
00184         void displace (double distance);
00185 
00186         // Return the current displacement.
00187         double displacement () const { return m_displacement; }
00188 
00189         // Return true if the suspension is displaced as much as it can
00190         // be, false otherwise.
00191         bool bottomed_out () const { return m_bottomed_out; }
00192 
00193         // Return the camber angle in radians for a suspension
00194         // displacement of DISPLACEMENT.
00195         double camber_function (double displacement) const;
00196 
00197         double current_camber (double normal_y) const;
00198 
00199         // Return this suspension component to equilibrium.
00200         void reset ();
00201 
00202         void set_model (std::string file_name, 
00203                                         double scale, 
00204                                         const Vamos_Geometry::Three_Vector& translation, 
00205                                         const Vamos_Geometry::Three_Vector& rotation);
00206 
00207         void draw ();
00208   };
00209 }
00210 
00211 #endif // !_SUSPENSION_H_

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6