Пример #1
0
    public override float Score(AHKController controller)
    {
        float tempScore = Vector3.Distance(controller.transform.position, controller.flightTarget.transform.position);

        tempScore += (controller.flightTarget.transform.forward - controller.transform.forward).magnitude;
        return(tempScore);
    }
Пример #2
0
 public void Reset(AHKController controller)
 {
     controller.transform.position = new Vector3(0, 0, 0);
     controller.transform.rotation = Quaternion.Euler(0, 0, 0);
     controller.GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 0);
     controller.GetComponent<Rigidbody>().angularVelocity = new Vector3(0, 0, 0);
     controller.engineLeft.Reset();
     controller.engineRight.Reset();
     controller.gyro.Reset();
 }
Пример #3
0
 public void Reset(AHKController controller)
 {
     controller.transform.position = new Vector3(0, 0, 0);
     controller.transform.rotation = Quaternion.Euler(0, 0, 0);
     controller.GetComponent <Rigidbody>().velocity        = new Vector3(0, 0, 0);
     controller.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0);
     controller.engineLeft.Reset();
     controller.engineRight.Reset();
     controller.gyro.Reset();
 }
Пример #4
0
    public Brain()
    {
        // INITIALIZATION

        Inputs     = new List <NeuronInput>();
        Outputs    = new List <Neuron>();
        MainColumn = new List <Neuron>();

        // REFERENCE GRABS

        AHK        = AHKController.instance.gameObject;
        Controller = AHKController.instance;

        // INPUTS

        for (int i = 0; i < InputCount; i++)
        {
            Inputs.Add(new NeuronInput());
        }

        // MAIN COLUMN

        for (int i = 0; i < InputCount + 1; i++)
        {
            Neuron tempNeuron = new Neuron();
            for (int j = 0; j < InputCount; j++)
            {
                tempNeuron.InputSynapses.Add(new Synapse(Inputs[j]));
            }
            MainColumn.Add(tempNeuron);
        }

        // OUTPUTS

        for (int i = 0; i < OutputCount; i++)
        {
            Neuron tempNeuron = new Neuron();
            for (int j = 0; j < InputCount + 1; j++)
            {
                tempNeuron.InputSynapses.Add(new Synapse(MainColumn[j]));
            }
            Outputs.Add(tempNeuron);
        }

        // TRAINERS

        TrainingSet = new List <ANNTrainer>();
        TrainingSet.Add(new TrainerBaseline(this));
        TrainingSet.Add(new TrainerCorrelation(this));
        TrainingSet.Add(new TrainerGeneticHover(this));
    }
Пример #5
0
    public Brain()
    {
        // INITIALIZATION

        Inputs = new List<NeuronInput>();
        Outputs = new List<Neuron>();
        MainColumn = new List<Neuron>();

        // REFERENCE GRABS

        AHK = AHKController.instance.gameObject;
        Controller = AHKController.instance;

        // INPUTS

        for (int i = 0; i < InputCount; i++) {
            Inputs.Add(new NeuronInput());
        }

        // MAIN COLUMN

        for (int i = 0; i < InputCount + 1; i++) {
            Neuron tempNeuron = new Neuron();
            for (int j = 0; j < InputCount; j++) {
                tempNeuron.InputSynapses.Add(new Synapse(Inputs[j]));
            }
            MainColumn.Add(tempNeuron);
        }

        // OUTPUTS

        for (int i = 0; i < OutputCount; i++) {
            Neuron tempNeuron = new Neuron();
            for (int j = 0; j < InputCount + 1; j++) {
                tempNeuron.InputSynapses.Add(new Synapse(MainColumn[j]));
            }
            Outputs.Add(tempNeuron);
        }

        // TRAINERS

        TrainingSet = new List<ANNTrainer>();
        TrainingSet.Add(new TrainerBaseline(this));
        TrainingSet.Add(new TrainerCorrelation(this));
        TrainingSet.Add(new TrainerGeneticHover(this));
    }
Пример #6
0
    public void UpdateOutputs()
    {
        // engine 1 thrust x2
        // engine 2 thrust x2

        // engine 1 tilt x2
        // engine 2 tilt x2

        // gyro x2

        AHKController.SetEnginePower(AHKController.EngineType.Left, (Outputs[0].currentValue - Outputs[1].currentValue + 1) / 2f);
        AHKController.SetEnginePower(AHKController.EngineType.Right, (Outputs[2].currentValue - Outputs[3].currentValue + 1) / 2f);

        AHKController.SetEngineTilt(AHKController.EngineType.Left, Outputs[4].currentValue - Outputs[5].currentValue);
        AHKController.SetEngineTilt(AHKController.EngineType.Right, Outputs[6].currentValue - Outputs[7].currentValue);

        AHKController.SetGyroPower(Outputs[8].currentValue - Outputs[9].currentValue);
    }
Пример #7
0
    void Update()
    {
        // Engines

        float roll = Input.GetAxis("Joy X");
        float ver  = Input.GetAxis("Joy Y");

        float climb = Input.GetAxis("Vertical");
        float yaw   = Input.GetAxis("Horizontal");

        roll  = Mathf.Abs(Mathf.Pow(roll, nonlinearityRoll)) * (roll < 0 ? -1 : 1);
        ver   = Mathf.Abs(Mathf.Pow(ver, nonlinearityPitch)) * (ver < 0 ? -1 : 1);
        yaw   = Mathf.Abs(Mathf.Pow(yaw, nonlinearityYaw)) * (yaw < 0 ? -1 : 1);
        climb = Mathf.Abs(Mathf.Pow(climb, nonlinearityClimb)) * (climb < 0 ? -1 : 1);

        roll = (roll + 1) / 2;

        AHKController.SetEngineTilt(AHKController.EngineType.Left, yaw - ver);
        AHKController.SetEngineTilt(AHKController.EngineType.Right, -yaw - ver);

        AHKController.SetEnginePower(AHKController.EngineType.Left, roll + climb);
        AHKController.SetEnginePower(AHKController.EngineType.Right, 1 - roll + climb);

        // Gyro

        float angle = AHKController.instance.transform.localRotation.eulerAngles.x;

        if (angle > 180)
        {
            angle = -(360 - angle);
        }

        Vector3 localangularvelocity = AHKController.instance.transform.InverseTransformDirection(AHKController.instance.GetComponent <Rigidbody>().angularVelocity).normalized
                                       *AHKController.instance.GetComponent <Rigidbody>().angularVelocity.magnitude;

        AHKController.SetGyroPower(-angle / 15 - localangularvelocity.x);
    }
Пример #8
0
 public override float Score(AHKController controller)
 {
     return(0);
 }
Пример #9
0
 // OVERRIDE STUFF
 public abstract float Score(AHKController controller);
Пример #10
0
 public override float Score(AHKController controller)
 {
     return 0;
 }
Пример #11
0
 public override float Score(AHKController controller)
 {
     float tempScore = Vector3.Distance(controller.transform.position, controller.flightTarget.transform.position);
     tempScore += (controller.flightTarget.transform.forward - controller.transform.forward).magnitude;
     return tempScore;
 }
Пример #12
0
 void Start()
 {
     instance = this;
     GetComponent <Rigidbody>().centerOfMass = new Vector3(-0.01f, 2.5f, -2.7f);
     brain = new Brain();
 }
Пример #13
0
 // OVERRIDE STUFF
 public abstract float Score(AHKController controller);
Пример #14
0
 void Start()
 {
     instance = this;
     GetComponent<Rigidbody>().centerOfMass = new Vector3(-0.01f, 2.5f, -2.7f);
     brain = new Brain();
 }