<commit_before>/**
 * User: booster
 * Date: 11/03/15
 * Time: 9:23
 */
package drive {
import drive.components.DrivetrainComponent;
import drive.components.clutch.ClutchComponent;
import drive.components.differential.DifferentialComponent;
import drive.components.differential.IDifferentialExcessTorqueStore;
import drive.components.differential.OpenDifferentialExcessTorqueStore;
import drive.components.engine.EngineComponent;
import drive.components.util.AngularVelocityForwarder;
import drive.components.util.AngularVelocityStore;
import drive.components.util.TimeStepper;

import flash.utils.getTimer;

import plugs.Connection;
import plugs.consumers.DebugConsumer;
import plugs.inputs.NumberInput;
import plugs.outputs.NumberOutput;
import plugs.providers.ValueProvider;

public class Drivetrain {
    public function Drivetrain() {
        //RWDDrivetrainTest();
        ClutchTest();
    }

    private function ClutchTest():void {
        var timeStepper:TimeStepper = new TimeStepper("TimeStepper");
        var engine:EngineComponent = new EngineComponent("Engine");
        var engineVelStore:AngularVelocityStore = new AngularVelocityStore("EngineAngularVelocityStore");
        var clutch:ClutchComponent = new ClutchComponent("Clutch");
        var clutchVelForwarder:AngularVelocityForwarder = new AngularVelocityForwarder("ClutchAngularVelocityForwarder");
        var wheel:DrivetrainComponent = new DrivetrainComponent("LeftWheel");
        var wheelVelStore:AngularVelocityStore = new AngularVelocityStore("LeftWheelAngularVelocityStore");

        engine.connectNextComponent(clutch);
        clutch.connectNextComponent(wheel);

        // engine
        var engineTorque:ValueProvider = new ValueProvider(new NumberOutput("EngineTorque"));
        engineTorque.value = 100;
        var engineInertia:ValueProvider = new ValueProvider(new NumberOutput("EngineInertia"));
        engineInertia.value = 0.2;
        //engineInertia.value = 2;

        Connection.connect(engineTorque.output, engine.torqueInput);
        Connection.connect(engineInertia.output, engine.inertiaInput);

        Connection.connect(engine.newAngularVelocityOutput, engineVelStore.angularVelocityInput);
        Connection.connect(engineVelStore.angularVelocityOutput, engine.angularVelocityInput);
        Connection.connect(engineVelStore.stepDurationOutput, engine.stepDurationInput);

        // clutch
        var clutchRatio:ValueProvider = new ValueProvider(new NumberOutput("ClutchRatio"));
        clutchRatio.value = 0.0;

        Connection.connect(clutchRatio.output, clutch.clutchRatioInput);

        Connection.connect(clutchVelForwarder.angularVelocityOutput, clutch.angularVelocityInput);

        Connection.connect(engine.angularVelocityOutput, clutch.previousAngularVelocityInput);
        Connection.connect(wheel.angularVelocityOutput, clutch.nextAngularVelocityInput);

        // left wheel
        var wheelInertia:ValueProvider = new ValueProvider(new NumberOutput("WheelInertia"));
        wheelInertia.value = 10;
        var wheelTorque:ValueProvider = new ValueProvider(new NumberOutput("WheelTorque"));
        wheelTorque.value = -50;
        var wheelRatio:ValueProvider = new ValueProvider(new NumberOutput("WheelGearRatio"));
        wheelRatio.value = 4;

        Connection.connect(wheelInertia.output, wheel.inertiaInput);
        Connection.connect(wheelTorque.output, wheel.torqueInput);
        Connection.connect(wheelRatio.output, wheel.gearRatioInput);

        Connection.connect(wheel.newAngularVelocityOutput, wheelVelStore.angularVelocityInput);
        Connection.connect(wheelVelStore.angularVelocityOutput, wheel.angularVelocityInput);

        Connection.connect(wheel.angularVelocityOutput, clutchVelForwarder.angularVelocityInput);
        Connection.connect(wheelVelStore.stepDurationOutput, wheel.stepDurationInput);

        // time step - order is important, clutch first, then all the rest
        Connection.connect(timeStepper.timeStepOutput, clutch.timeStepInput);
        Connection.connect(timeStepper.timeStepOutput, engineVelStore.timeStepInput);
        Connection.connect(timeStepper.timeStepOutput, wheelVelStore.timeStepInput);

        // total torque
        var engineTotalTorque:DebugConsumer = new DebugConsumer(new NumberInput("EngineTotalTorque"));
        Connection.connect(engine.totalTorqueOutput, engineTotalTorque.input);

        var clutchTotalTorque:DebugConsumer = new DebugConsumer(new NumberInput("ClutchTotalTorque"));
        Connection.connect(clutch.totalTorqueOutput, clutchTotalTorque.input);

        var wheelTotalTorque:DebugConsumer = new DebugConsumer(new NumberInput("WheelTotalTorque"));
        Connection.connect(wheel.totalTorqueOutput, wheelTotalTorque.input);

        // effective inertia
        var engineEffectiveInertia:DebugConsumer = new DebugConsumer(new NumberInput("EngineEffectiveInertia"));
        Connection.connect(engine.effectiveInertiaOutput, engineEffectiveInertia.input);

        var clutchEffectiveInertia:DebugConsumer = new DebugConsumer(new NumberInput("ClutchEffectiveInertia"));
        Connection.connect(clutch.effectiveInertiaOutput, clutchEffectiveInertia.input);

        var wheelEffectiveInertia:DebugConsumer = new DebugConsumer(new NumberInput("WheelEffectiveInertia"));
        Connection.connect(wheel.effectiveInertiaOutput, wheelEffectiveInertia.input);

        // angular velocity
        var engineAngularVelocity:DebugConsumer = new DebugConsumer(new NumberInput("EngineAngularVelocity"));
        Connection.connect(engine.angularVelocityOutput, engineAngularVelocity.input);

        var clutchAngularVelocity:DebugConsumer = new DebugConsumer(new NumberInput("ClutchAngularVelocity"));
        Connection.connect(clutch.angularVelocityOutput, clutchAngularVelocity.input);

        var wheelAngularVelocity:DebugConsumer = new DebugConsumer(new NumberInput("WheelAngularVelocity"));
        Connection.connect(wheel.angularVelocityOutput, wheelAngularVelocity.input);

        // clutch ratio
        var clutchRatioConsumer:DebugConsumer = new DebugConsumer(new NumberInput("ClutchRatio"));
        Connection.connect(clutchRatio.output, clutchRatioConsumer.input);

        //var time:int = getTimer();
        const stepCount:int = 11;
        for(var i:int = 0; i < stepCount; ++i) {
            clutchRatio.value = Number(i) / (stepCount - 1);

            timeStepper.pushTimeStep(0.1);

            trace("Clutch[" + i + "]:");
            clutchRatioConsumer.pullData();

            trace("Inertia[" + i + "]:");<commit_msg>Clutch test<commit_after>/**
 * User: booster
 * Date: 11/03/15
 * Time: 9:23
 */
package drive {
import drive.components.DrivetrainComponent;
import drive.components.clutch.ClutchComponent;
import drive.components.differential.DifferentialComponent;
import drive.components.differential.IDifferentialExcessTorqueStore;
import drive.components.differential.OpenDifferentialExcessTorqueStore;
import drive.components.engine.EngineComponent;
import drive.components.util.AngularVelocityForwarder;
import drive.components.util.AngularVelocityStore;
import drive.components.util.TimeStepper;

import flash.utils.getTimer;

import plugs.Connection;
import plugs.consumers.DebugConsumer;
import plugs.inputs.NumberInput;
import plugs.outputs.NumberOutput;
import plugs.providers.ValueProvider;

public class Drivetrain {
    public function Drivetrain() {
        //RWDDrivetrainTest();
        ClutchTest();
    }

    private function ClutchTest():void {
        var timeStepper:TimeStepper = new TimeStepper("TimeStepper");
        var engine:EngineComponent = new EngineComponent("Engine");
        var engineVelStore:AngularVelocityStore = new AngularVelocityStore("EngineAngularVelocityStore");
        var clutch:ClutchComponent = new ClutchComponent("Clutch");
        var clutchVelForwarder:AngularVelocityForwarder = new AngularVelocityForwarder("ClutchAngularVelocityForwarder");
        var wheel:DrivetrainComponent = new DrivetrainComponent("LeftWheel");
        var wheelVelStore:AngularVelocityStore = new AngularVelocityStore("LeftWheelAngularVelocityStore");

        engine.connectNextComponent(clutch);
        clutch.connectNextComponent(wheel);

        // engine
        var engineTorque:ValueProvider = new ValueProvider(new NumberOutput("EngineTorque"));
        engineTorque.value = 100;
        var engineInertia:ValueProvider = new ValueProvider(new NumberOutput("EngineInertia"));
        engineInertia.value = 0.2;
        //engineInertia.value = 2;

        Connection.connect(engineTorque.output, engine.torqueInput);
        Connection.connect(engineInertia.output, engine.inertiaInput);

        Connection.connect(engine.newAngularVelocityOutput, engineVelStore.angularVelocityInput);
        Connection.connect(engineVelStore.angularVelocityOutput, engine.angularVelocityInput);
        Connection.connect(engineVelStore.stepDurationOutput, engine.stepDurationInput);

        // clutch
        var clutchRatio:ValueProvider = new ValueProvider(new NumberOutput("ClutchRatio"));
        clutchRatio.value = 0.0;

        Connection.connect(clutchRatio.output, clutch.clutchRatioInput);

        Connection.connect(clutchVelForwarder.angularVelocityOutput, clutch.angularVelocityInput);

        Connection.connect(engine.angularVelocityOutput, clutch.previousAngularVelocityInput);
        Connection.connect(wheel.angularVelocityOutput, clutch.nextAngularVelocityInput);

        // left wheel
        var wheelInertia:ValueProvider = new ValueProvider(new NumberOutput("WheelInertia"));
        wheelInertia.value = 10;
        var wheelTorque:ValueProvider = new ValueProvider(new NumberOutput("WheelTorque"));
        wheelTorque.value = -50;
        var wheelRatio:ValueProvider = new ValueProvider(new NumberOutput("WheelGearRatio"));
        wheelRatio.value = 4;

        Connection.connect(wheelInertia.output, wheel.inertiaInput);
        Connection.connect(wheelTorque.output, wheel.torqueInput);
        Connection.connect(wheelRatio.output, wheel.gearRatioInput);

        Connection.connect(wheel.newAngularVelocityOutput, wheelVelStore.angularVelocityInput);
        Connection.connect(wheelVelStore.angularVelocityOutput, wheel.angularVelocityInput);

        Connection.connect(wheel.angularVelocityOutput, clutchVelForwarder.angularVelocityInput);
        Connection.connect(wheelVelStore.stepDurationOutput, wheel.stepDurationInput);

        // time step - order is important, clutch first, then all the rest
        Connection.connect(timeStepper.timeStepOutput, clutch.timeStepInput);
        Connection.connect(timeStepper.timeStepOutput, engineVelStore.timeStepInput);
        Connection.connect(timeStepper.timeStepOutput, wheelVelStore.timeStepInput);

        // total torque
        var engineTotalTorque:DebugConsumer = new DebugConsumer(new NumberInput("EngineTotalTorque"));
        Connection.connect(engine.totalTorqueOutput, engineTotalTorque.input);

        var clutchTotalTorque:DebugConsumer = new DebugConsumer(new NumberInput("ClutchTotalTorque"));
        Connection.connect(clutch.totalTorqueOutput, clutchTotalTorque.input);

        var wheelTotalTorque:DebugConsumer = new DebugConsumer(new NumberInput("WheelTotalTorque"));
        Connection.connect(wheel.totalTorqueOutput, wheelTotalTorque.input);

        // effective inertia
        var engineEffectiveInertia:DebugConsumer = new DebugConsumer(new NumberInput("EngineEffectiveInertia"));
        Connection.connect(engine.effectiveInertiaOutput, engineEffectiveInertia.input);

        var clutchEffectiveInertia:DebugConsumer = new DebugConsumer(new NumberInput("ClutchEffectiveInertia"));
        Connection.connect(clutch.effectiveInertiaOutput, clutchEffectiveInertia.input);

        var wheelEffectiveInertia:DebugConsumer = new DebugConsumer(new NumberInput("WheelEffectiveInertia"));
        Connection.connect(wheel.effectiveInertiaOutput, wheelEffectiveInertia.input);

        // angular velocity
        var engineAngularVelocity:DebugConsumer = new DebugConsumer(new NumberInput("EngineAngularVelocity"));
        Connection.connect(engine.angularVelocityOutput, engineAngularVelocity.input);

        var clutchAngularVelocity:DebugConsumer = new DebugConsumer(new NumberInput("ClutchAngularVelocity"));
        Connection.connect(clutch.angularVelocityOutput, clutchAngularVelocity.input);

        var wheelAngularVelocity:DebugConsumer = new DebugConsumer(new NumberInput("WheelAngularVelocity"));
        Connection.connect(wheel.angularVelocityOutput, wheelAngularVelocity.input);

        // clutch ratio
        var clutchRatioConsumer:DebugConsumer = new DebugConsumer(new NumberInput("ClutchRatio"));
        Connection.connect(clutchRatio.output, clutchRatioConsumer.input);

        //var time:int = getTimer();
        const stepCount:int = 15;
        for(var i:int = 0, c:Number = 0.0; i < stepCount; ++i, c = Math.abs(c - 1) > 0.1 ? c + 0.1 : 1) {
            clutchRatio.value = c;

            timeStepper.pushTimeStep(0.1);

            trace("Clutch[" + i + "]:");
            clutchRatioConsumer.pullData();

            trace("Inertia[" + i + "]:");
            engineEffectiveInertia.pullData();
            clutchEffectiveInertia.pullData();
            wheelEffectiveInertia.pullData();

            trace("Torque[" + i + "]:");
            engineTotalTorque.pullData();
            clutchTotalTorque.pullData();
            wheelTotalTorque.pullData();

            trace("Velocity[" + i + "]:");
            engineAngularVelocity.pullData();
            clutchAngularVelocity.pullData();
            wheelAngularVelocity.pullData();
        }

        c = 0;

        for(i = 0; i < stepCount + stepCount / 2; ++i) {
            clutchRatio.value = c;

            timeStepper.pushTimeStep(0.1);

            trace("Clutch[" + i + "]:");
            clutchRatioConsumer.pullData();

            trace("Inertia[" + i + "]:");
            engineEffectiveInertia.pullData();
            clutchEffectiveInertia.pullData();
            wheelEffectiveInertia.pullData();

            trace("Torque[" + i + "]:");
            engineTotalTorque.pullData();
            clutchTotalTorque.pullData();
            wheelTotalTorque.pullData();

            trace("Velocity[" + i + "]:");
            engineAngularVelocity.pullData();
            clutchAngularVelocity.pullData();
            wheelAngularVelocity.pullData();
        }

        for(i = 0; i < stepCount + stepCount; ++i, c = Math.abs(c - 1) > 0.1 ? c + 0.1 : 1) {
            clutchRatio.value = c;

            timeStepper.pushTimeStep(0.1);

            trace("Clutch[" + i + "]:");
            clutchRatioConsumer.pullData();

            trace("Inertia[" + i + "]:");
{'fraction_non_alphanumeric': 0.09706439393939394, 'fraction_numerical': 0.005208333333333333, 'mean_word_length': 3.9201331114808653, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1425175', 'n_tokens_mistral': 4011, 'n_tokens_neox': 3873, 'n_words': 626}