include/vamos/body/Wheel.h

Go to the documentation of this file.
00001 //  Wheel.h - a wheel.
00002 //
00003 //  Copyright (C) 2001--2004 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 _WHEEL_H_
00022 #define _WHEEL_H_
00023 
00024 #include <vamos/body/Suspension.h>
00025 #include <vamos/body/Tire.h>
00026 #include <vamos/body/Brake.h>
00027 #include <vamos/body/Contact_Point.h>
00028 #include <vamos/geometry/Constants.h>
00029 #include <vamos/geometry/Material.h>
00030 #include <vamos/geometry/Three_Vector.h>
00031 #include <vamos/geometry/Inertia_Tensor.h>
00032 
00033 #include <GL/gl.h>
00034 
00035 #include "model.h"
00036 
00037 #include <string>
00038 
00039 namespace Vamos_Body
00040 {
00041   //* A wheel.  
00042   // Handles wheel geometry.  See Tire, Brake and Suspension for
00043   // related functionality.
00044   class Wheel : public Contact_Point
00045   {
00046   private:
00047 
00048         // The initial position of the wheel.
00049         Vamos_Geometry::Three_Vector m_original_position;
00050 
00051         double m_tire_offset;
00052         // The distance from the steering pivot to the effective center
00053         // of the contact patch.
00054 
00055         double m_roll_height;
00056         // How far off the road lateral forces are applied to the chassis.
00057 
00058         // The suspension that the wheel is attached to.
00059         Suspension* mp_suspension;
00060 
00061         // The tire that is attached to the wheel.
00062         Tire m_tire;
00063 
00064         // The brake for the wheel.
00065         Brake m_brake;
00066 
00067         // The velocity of the ground relative to the wheel.
00068         Vamos_Geometry::Three_Vector m_ground_velocity;
00069 
00070         // The current normal vector for the road.
00071         Vamos_Geometry::Three_Vector m_normal;
00072 
00073         // The angular velocity of the wheel.
00074         Vamos_Geometry::Three_Vector m_ang_velocity;
00075         
00076         // The surface we're currently on
00077         Vamos_Geometry::Material_Handle m_material;
00078 
00079         // The torque applied to the tire.
00080         double m_tire_torque;
00081 
00082         double m_drive_torque;
00083 
00084         double m_braking_torque;
00085 
00086         // True if the wheel responds to steering. 
00087         bool m_steered;
00088 
00089         // True if the wheel is driven.
00090         bool m_driven;
00091 
00092         // The side of the car that the wheel is on.
00093         Vamos_Geometry::Side m_side;
00094 
00095         // The ID of the display lists for the wheel.
00096         /*GLuint m_slow_wheel_list;
00097         GLuint m_fast_wheel_list;
00098         GLuint m_stator_list;*/
00099 
00100         // The speed where we start using m_fast_wheel_list.
00101         double m_transition_speed;
00102 
00103         // The current rotation angle about the axle.
00104         double m_rotation;
00105         
00106         JOEMODEL model;
00107 
00108         // Return the display list for the specified model file.
00109         /*GLuint make_model (std::string file, double scale,
00110                                            const Vamos_Geometry::Three_Vector& translation,
00111                                            const Vamos_Geometry::Three_Vector& rotation);*/
00112 
00113         // Do the transformation of the wheel model.
00114         void transform ();
00115 
00116   public:
00117         //** Constructor
00118         Wheel (double mass, 
00119                    Vamos_Geometry::Three_Vector position, 
00120                    double tire_offset,
00121                    double roll_height,
00122                    double restitution,
00123                    Suspension* suspension, 
00124                    const Tire& tire, 
00125                    const Brake& brake,
00126                    bool steered,
00127                    bool driven,
00128                    Vamos_Geometry::Side side);
00129 
00130         // Find and store the forces and torques for the current
00131         // configuration.
00132         void find_forces ();
00133 
00134         Suspension* suspension();
00135         Vamos_Geometry::Three_Vector ang_velocity();
00136         void set_ang_velocity(Vamos_Geometry::Three_Vector newvel) {m_ang_velocity = newvel;}
00137   
00138         // Advance the wheel forward in time by TIME.
00139         void propagate (double time);
00140 
00141         // Undo the last propagation.
00142         void rewind ();
00143 
00144         // Handle collisions.  The return value is how much the wheel was
00145         // displaced by the collision.
00146         double contact (const Vamos_Geometry::Three_Vector& position,
00147                                         const Vamos_Geometry::Inertia_Tensor& inertia,
00148                                         const Vamos_Geometry::Three_Vector& vecocity, 
00149                                         double distance,
00150                                         const Vamos_Geometry::Three_Vector& normal,
00151                                         const Vamos_Geometry::Three_Vector& ang_velocity,
00152                                         Vamos_Geometry::Material_Handle material);
00153 
00154         // Apply the torque TORQUE_IN to the wheel.  This torque results
00155         // from acceleration or braking.
00156         void drive_torque (double torque_in);
00157 
00158         void brake (double factor);
00159         
00160         double get_handbrake_multiplier() {return m_brake.handbrake();}
00161 
00162         // Set the steering angle.
00163         void steer (double degree_angle) { mp_suspension->steer (degree_angle); }
00164 
00165 
00166         // Return the speed of the contact patch of the tire with respect
00167         // to the ground.
00168         double slide () const { return m_tire.slide (); }
00169 
00170         // Return the wheel's rotational speed in radians per second.
00171         double rotational_speed () const { return m_tire.rotational_speed (); }
00172         
00173         void set_rotational_speed(double newrs) {m_tire.set_rotational_speed(newrs);}
00174 
00175         // Return the linear speed of the tire tread.  This is the speed
00176         // that a speedometer on this wheel would read.
00177         double speed () const { return m_tire.speed (); }
00178         
00179         double GetFeedback() {return m_tire.GetFeedback();}
00180 
00181         // Return the position relative to the body where the wheel exerts
00182         // its force.
00183         Vamos_Geometry::Three_Vector force_position () const;
00184 
00185         // Return the position of the wheel relative to the body for the
00186         // purpose of detecting collisions.
00187         Vamos_Geometry::Three_Vector contact_position () const;
00188         
00189         Vamos_Geometry::Three_Vector position () const;
00190 
00191         // Return the slip ratio for the wheel;
00192         double slip () const;
00193 
00194         // Return the wheel to its initial conditions.
00195         void reset ();
00196 
00197         bool single_contact () const { return false; }
00198 
00199         bool steered () const { return m_steered; }
00200         bool driven () const { return m_driven; }
00201 
00202         Vamos_Geometry::Side side () const { return m_side; }
00203 
00204         void set_models (std::string slow_file, 
00205                                          std::string fast_file, 
00206                                          double transition_speed,
00207                                          std::string stator_file,
00208                                          double stator_offset,
00209                                          double scale, 
00210                                          const Vamos_Geometry::Three_Vector& translation,
00211                                          const Vamos_Geometry::Three_Vector& rotation);
00212         void draw ();
00213         
00214         void SetColParams(double f1, double f2, double rr, double rd) {m_tire.SetSurfaceParams(f1, f2, rr, rd);}
00215   };
00216 }
00217 
00218 #endif // !_WHEEL_H_

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