Пример #1
0
    /// <summary>
    /// Function called before of the first update
    /// </summary>
    void Start()
    {
        droneMovementController dmc = gameObject.GetComponent <droneMovementController>();

        // associate the rotors
        helixO1 = dmc.helixO1;
        helixO2 = dmc.helixO2;
        helixV1 = dmc.helixV1;
        helixV2 = dmc.helixV2;

        // finds the rotors position
        Vector3 v1 = helixV1.transform.position;
        Vector3 v2 = helixV2.transform.position;
        Vector3 o1 = helixO1.transform.position;
        Vector3 o2 = helixO2.transform.position;

        Vector3 mid_v1o1 = (v1 + o1) / 2f;
        Vector3 mid_v2o2 = (o2 + v2) / 2f;

        distanceBetweenHelixes = Vector3.Distance(mid_v1o1, mid_v2o2);

        // instantiates the noiseAdders, to add the noise to the measurement
        nRoll       = new noiseAdder();
        nRollSpeed  = new noiseAdder();
        nRollAcc    = new noiseAdder();
        nPitch      = new noiseAdder();
        nPitchSpeed = new noiseAdder();
        nPitchAcc   = new noiseAdder();
    }
 /// <summary>
 /// Function called in the Start function that initializes the variables used for the experiment
 /// </summary>
 /// <param name="lifeTime">Time the drone will live before of dying of natural death </param>
 /// <param name="hidebody">Indicate if the mesh of the drone has to be hidden or not </param>
 /// <param name="routePos">Route position in the circuit.
 /// It is used to estabilish if the drone has to be killed because too far from the circuit </param>
 protected void startOperations(float lifeTime, bool hidebody, Vector3 routePos)
 {
     setID();
     hideBody(hidebody);
     setLifeTime(lifeTime);
     dmc               = gameObject.GetComponent <droneMovementController>();
     routePosition     = routePos;
     lastroutePosition = routePos;
 }
Пример #3
0
    /// <summary>
    /// Sets the keys to the drone
    /// </summary>
    /// <param name="myVals">Array of float containing the parameters</param>
    protected void writeKeysOnDMC(float[] myVals)
    {
        droneMovementController dmc = GetComponent <droneMovementController>();

        PID yPID     = new PID(myVals[0], myVals[1], myVals[2], myVals[3]);
        PID zPID     = new PID(myVals[4], myVals[5], myVals[6], myVals[7]);
        PID xPID     = new PID(myVals[4], myVals[5], myVals[6], myVals[7]);
        PID yawPID   = new PID(myVals[8], myVals[9], myVals[10], myVals[11]);
        PID rollPID  = new PID(myVals[12], myVals[13], myVals[14], myVals[15]);
        PID pitchPID = new PID(myVals[12], myVals[13], myVals[14], myVals[15]);

        dmc.setKs(yPID, zPID, xPID, pitchPID, rollPID, yawPID);
        dmc.setConsts(myVals[16], myVals[17], myVals[18], myVals[19], myVals[20], myVals[22], myVals[23]);
    }
Пример #4
0
    /// <summary>
    /// Function Called when the object is activated for the first time
    /// </summary>
    void Awake()
    {
        // initializes the noiseAdders
        nYaw   = new noiseAdder();
        nSpeed = new noiseAdder();

        // look for the rotors in the droneMovementController
        droneMovementController dmc = gameObject.GetComponent <droneMovementController>();

        helixO1 = dmc.helixO1;
        helixO2 = dmc.helixO2;
        helixV1 = dmc.helixV1;
        helixV2 = dmc.helixV2;
        lastYaw = yaw = getYawINT();
    }
    /// <summary>
    /// Sets the keys used for the experiment and the waypoint
    /// </summary>
    /// <param name="myVals">Array of float containing the parameters</param>
    /// <param name="waypointCircuit">WaypointCircuit that will be used for the experiment</param>
    protected void writeKeysOnDMC(float[] myVals, GameObject waypointCircuit)
    {
        // if the variables are empty, is assigns them
        dmc = (dmc != null ? dmc : GetComponent <droneMovementController>());
        wpt = (wpt != null ? wpt : GetComponent <WaypointProgressTracker>());

        // initializing new PIDs
        yPID     = new PID(myVals[0], myVals[1], myVals[2], myVals[3]);
        zPID     = new PID(myVals[4], myVals[5], myVals[6], myVals[7]);
        xPID     = new PID(myVals[4], myVals[5], myVals[6], myVals[7]);
        yawPID   = new PID(myVals[8], myVals[9], myVals[10], myVals[11]);
        rollPID  = new PID(myVals[12], myVals[13], myVals[14], myVals[15]);
        pitchPID = new PID(myVals[12], myVals[13], myVals[14], myVals[15]);

        // calls the functions in the droneMovementController to set the keys and the constants
        dmc.setKs(yPID, zPID, xPID, pitchPID, rollPID, yawPID);
        dmc.setConsts(myVals[16], myVals[17], myVals[18], myVals[19], myVals[20], myVals[22], myVals[23]);

        // spawns the WaypointCircuit and assign it to the drone
        Vector3 wpcPosition = this.transform.position + new Vector3(2, 6, 2);

        spawnedWaypoint = (GameObject)Instantiate(waypointCircuit, wpcPosition, Quaternion.identity);
        wpt.setWaypoint(spawnedWaypoint.GetComponent <WaypointCircuit>());
    }