Exemplo n.º 1
0
        public override void Build()
        {
            if (save)
            {
                writerEnv = UIO.CreateStreamWriter(GeneratePath(task, true), "GeneSessionResults.csv", false);
                UIO.WriteLine(writerEnv, "Generation;Angle Random Rotation;Wind");
            }
            Debug.Log("Build DroneSession");
            signal  = new ControlSignal();
            tsignal = new ThrustSignal();
            tmpBuildCustomWeights = new List <Matrix <float> >();
            externalEvaluations   = Vector <float> .Build.Dense(populationSize);

            //Debug.Log(fromTask);
            taskObject = (DroneTask)Activator.CreateInstance(Type.GetType("Lexmou.MachineLearning.Drone" + task), rndGenerator, fromTask);
            //Debug.Log(taskObject.fromTask);
            dronePopulation = new GameObject[populationSize];
            droneRigid      = new Rigidbody[populationSize];
            targetPosition  = new Vector3[populationSize];
            mlpPopulation   = new MultiLayerMathsNet[populationSize];

            gene = new Genetic(seed, rndGenerator, populationSize, taskObject.individualSize, initialValueWeights, mutationRate, randomIndividualsRate, bestIndividualsRate, emptyRate, GeneratePath(task, false), save);
            if (loadGeneration != 0)
            {
                float[,] floatArr = new float[taskObject.individualSize - taskObject.rowIndex, populationSize];
                Debug.Log(taskObject.fromTask);
                //Debug.Log(taskObject.individualSize);
                gene.LoadGeneration(GeneratePath(taskObject.fromTask, true), loadGeneration, floatArr, taskObject.rowIndex);
                gene.generation = loadGeneration;
            }
        }
Exemplo n.º 2
0
    /*void Start()
     * {
     *  Debug.Log(inputSize);
     *  inputMLP = Vector<float>.Build.Dense(inputSize);
     * }*/


    public void SendThrustSignal(ThrustSignal signal)
    {
        //Debug.Log("SendThrustSignal");
        resultThrust = signal;
        foreach (Drone.Hardware.Component <ThrustSignal> component in ThrustSignalBus)
        {
            resultThrust = component.ProcessSignal(resultThrust);
        }
    }
Exemplo n.º 3
0
    public void SendThrustSignal(ThrustSignal signal)
    {
        ThrustSignal result = signal;

        foreach (Drone.Hardware.Component <ThrustSignal> component in ThrustSignalBus)
        {
            result = component.ProcessSignal(result);
        }
    }
Exemplo n.º 4
0
    public override ControlSignal ProcessSignal(ControlSignal signal)
    {
        ThrustSignal thrust = new ThrustSignal();

        // Throttle
        if (signal.Throttle >= 0f)
        {
            float throttle = (signal.Throttle * ThrottleSensitivity);
            thrust.FRThrust = throttle;
            thrust.FLThrust = throttle;
            thrust.RRThrust = throttle;
            thrust.RLThrust = throttle;
        }

        // Rudder
        if (signal.Rudder > 0f)
        {
            // turn right
            float rudder = (signal.Rudder * RudderSensitivity) / 2;
            thrust.FRThrust -= rudder;
            thrust.FLThrust += rudder;
            thrust.RRThrust += rudder;
            thrust.RLThrust -= rudder;
        }
        else if (signal.Rudder < 0f)
        {
            // turn left
            float rudder = (-signal.Rudder * RudderSensitivity) / 2;
            thrust.FRThrust += rudder;
            thrust.FLThrust -= rudder;
            thrust.RRThrust -= rudder;
            thrust.RLThrust += rudder;
        }

        // Elevator
        if (signal.Elevator > 0f)
        {
            // go forward
            float elevator = (signal.Elevator * ElevatorSensitivity) / 2;
            thrust.FRThrust -= elevator;
            thrust.FLThrust -= elevator;
            thrust.RRThrust += elevator;
            thrust.RLThrust += elevator;
        }
        else if (signal.Elevator < 0f)
        {
            // go backward
            float elevator = (-signal.Elevator * ElevatorSensitivity) / 2;
            thrust.FRThrust += elevator;
            thrust.FLThrust += elevator;
            thrust.RRThrust -= elevator;
            thrust.RLThrust -= elevator;
        }

        // Aileron
        if (signal.Aileron > 0f)
        {
            // go right
            float aileron = (signal.Aileron * AileronSensitivity) / 2;
            thrust.FRThrust -= aileron;
            thrust.FLThrust += aileron;
            thrust.RRThrust -= aileron;
            thrust.RLThrust += aileron;
        }
        else if (signal.Aileron < 0f)
        {
            // go left
            float aileron = (-signal.Aileron * AileronSensitivity) / 2;
            thrust.FRThrust += aileron;
            thrust.FLThrust -= aileron;
            thrust.RRThrust += aileron;
            thrust.RLThrust -= aileron;
        }

        MainBoard.SendThrustSignal(thrust);

        return(signal);
    }