Пример #1
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]);
    }
    /// <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>());
    }