Can anyone drive a car and a tank?

Configuration

For a more logical experience, I’ve split the configuration into 3 parts. Firstly one that affects the world the vehicles inhabit (whether it’s real physics, size of the car, whether to display gates etc). The ones with a red asterisk can’t be changed without re-starting, in some cases load/paint the track.

“Display eliminated cars” is useful if you click “Q” and run in “quick learn” mode as you see ghosts of cars for each generation, and they move along the track until telemetry is visible.

“Show Telemetry” shows the blue arrows all around the track based on where the car followed pointing where it headed (after 2 successful laps), red lines (perpendicular) are where it has struggled for traction.

The cars need to know where the edges of the track are. It uses a LIDAR. This configuration came about as a result of questions relating to how many sensors it requires. How far ahead does it need to look? Which angles does the LIDAR need to scan?

The AI model is always a perception network. But there are things to experiment with especially the hidden neurons, how much modulation/amplification of the input we apply, and whether the vehicles benefit from brakes (E-brake is the hand brake). If you give it a large throttle value it may struggle to steer. If you reduce steering, again it may struggle. If you increase it too much the laws of physics may not cope (slide sideways).

Also controllable are the mutation and population size. Having small populations, generations will be quicker but it may take longer overall to get optimum vehicles. Playing with strength or chance can also hugely affect how much the bias & weights are changed.

Having a larger population makes it slower, but does having a larger population enable it to discover a working car sooner? Does a large mutation chance or strength have a similar effect? Does not mutating early result in quicker / better cars? Does having the ability to brake improve the car’s performance?

I haven’t provided a UI for configuring the physics. That’s on my to-do list. Edit this file “CarConfig.cs”, and change the parameters. Please note, the values work pretty well for the karts. Some may not be realistic values. I wanted to create karts that have oodles of power, and grip well but can slide the back end (more for satisfaction and challenge).

using CarsAndTanks.Utilities;

namespace CarsAndTanks.World.Car;

/// <summary>
/// 
/// </summary>
internal class CarConfig
{
    //  Defaults approximate a real-wheel drive go-kart.

    /// <summary>
    /// Gravity.
    /// </summary>
    internal double c_gravity = 9.81F;  // m/s^2

    /// <summary>
    /// Inertia.
    /// </summary>
    internal double c_inertiaScale = 1.0F;  // Multiply by mass for inertia

    /// <summary>
    /// The mass of the car. (Weight is multiplied by gravity)
    /// </summary>
    internal const double c_massOfKartKg = 81.6F; // kg

    /// <summary>
    /// The mass of the pretend person driving the car. (Weight is multiplied by gravity)
    /// </summary>
    internal const double c_massOfDriverKg = 76F; // kg

    /// <summary>
    /// Gross Vehicle Weight GVW is approx 185kg. (Weight is multiplied by gravity)
    /// </summary>
    internal double massOfKartPlusDriverKg = c_massOfKartKg + c_massOfDriverKg; // kg

    // Wheelbase 1250mm

    /// <summary>
    /// Go Kart 78" long = 1.867 metres
    /// </summary>
    internal const double goKartLengthMetres = 1.63F;

    /// <summary>
    /// 31" wide = 0.78695 metres
    /// </summary>
    internal const double goKartWidthMetres = 0.78695F;

    /*
		 *			  | 76kg
		 *			 \|/      
		 *				 [###]
		 *     / ##  -----{|[]}     
		 *     |=====O(   )|  }  << engine
		 *     \ ##  -----{|--}
		 *               [###]
		 *     
		 *     ¦  ¦     ¦--¦  ¦
		 *             cg axle
		 */
    internal double halfWidth = goKartWidthMetres / 2; // Centre to side of chassis (metres)

    /// <summary>
    /// Centre of gravity to front of chassis (metres)
    /// </summary>
    internal double centreOfGravityToFront = 60F / 100F * goKartLengthMetres; /* was 52 */

    /// <summary>
    /// Centre of gravity to rear of chassis
    /// </summary>
    internal double centreOfGravityToRear = 40F / 100F * goKartLengthMetres; /* was 48 */

    /// <summary>
    /// // Centre gravity to front axle
    /// </summary>
    internal double centreOfGravityToFrontAxle = 34F / 100F * goKartLengthMetres; /* was 31/100 */

    /// <summary>
    /// Estimated centre gravity to rear axle.
    /// </summary>
    internal double centreOfGravityToRearAxle = 24F / 100F * goKartLengthMetres; /* was 42/100*/

    /// <summary>
    /// 250 mm Centre gravity height (g isn't the engine, it isn't the person it's a blended height).
    /// </summary>
    internal double centreOfGravityHeight = 0.25F;

    /// <summary>
    /// Co-efficient of friction for slicks u = 0.9
    /// </summary>
    internal double GripOfFrontTyres = 0.7F;  // How much grip tires have, smaller.

    /// <summary>
    /// Co-efficient of friction for slicks u = 0.9
    /// </summary>
    internal double GripOfRearTyres = 0.8F;  // How much grip tires have

    /// <summary>
    /// % of grip available when wheel is locked.
    /// 1..100 
    /// </summary>
    internal double gripWhenWheelIsLocked = 70F; // % 

    /// <summary>
    /// Engine Power P 3.5hp 2611 watts.
    /// </summary>
    internal double engineForce = 26110F;

    /// <summary>
    /// Clamping force * coefficient of friction between the pads=4991.06*0.45=2245.977N, for a normal car.
    /// </summary>
    internal double brakeForce = 22000F;

    /// <summary\>
    /// Clamping force of the eBrake.
    /// </summary>
    internal double eBrakeForce = 12000F /*brakeForce*/ / 2.5F;

    /// <summary>
    /// How much weight is transferred during acceleration/deceleration.
    /// </summary>
    internal double weightTransfer = 0.2F;  // How much weight is transferred during acceleration/braking

    /// <summary>
    /// Steering wheel lock angle 50.52° is how far one can twist the wheel.
    /// </summary>
    internal double maxSteer = MathUtils.DegreesInRadians(50.52); // Maximum steering angle in radians

    /// <summary>
    /// Stiffness of front corner.
    /// </summary>
    internal double cornerStiffnessFront = 4F;

    /// <summary>
    /// Stiffness of rear corner.
    /// </summary>
    internal double cornerStiffnessRear = 4.2F;

    /// <summary>
    /// Cdrag 
    /// Air resistance is approximated by the following formula (Fluid Mechanics by Landau and Lifshitz, [Beckham] chapter 6, [Zuvich])
    /// 
    /// Fdrag =  0.5 * Cd * A * rho * v2
    ///    where Cd = coefficient of friction,  A is frontal area of car, rho (Greek symbol) is density of air, v = speed of the car
    /// 
    /// Air density (rho) is 1.29 kg/m3 (0.0801 lb-mass/ft3), frontal area is approx. 2.2 m2 (20 sq. feet), Cd depends on the shape of the car and determined via wind tunnel tests.  
    /// 
    /// Approximate value for a Corvette: 0.30.  This gives us a value for Cdrag:  
    ///   Cdrag = 0.5 * 0.30 * 2.2 * 1.29 
    ///         = 0.4257
    /// 
    /// Air resistance (proportional to velocity)
    /// air density 1.226 kg/𝑚3
    /// Co-efficient of drag 0.35
    /// 
    /// Asawiki said: I have my doubts about this last constant. I couldn't confirm its value anywhere. Be prepared to finetune this one to get realistic behaviour.
    /// </summary>
    internal double airResist = 2.85F; // this should be  0.4257 for a Corvette, but works well for a Go Kart

    /// <summary>
    /// Crr
    /// Co-efficient of Rolling Resistance 0.012, used to determine drag. 
    /// At approx. 100 km/h (60 mph, 30 m/s) Cdrag and Crr are equal ([Zuvich]). This means Crr must be approximately 30 times the value of Cdrag.
    /// </summary>
    internal double rollResist = 83.0F; // this should be 12.8 for a Corvette, but works well for a Go Kart
}

On the next page (4) we’ll quickly look at how you define tracks.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *