Beispiel #1
0
    //Changed the WriteSamplesToDisk to a IEnumerator method that plays back recording along with percent status from UISystem script
    //instead of showing frozen screen until all data is recorded
    public IEnumerator WriteSamplesToDisk()
    {
        string newLine = "\n";

        if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
        {
            newLine = "\r\n";
        }

        if (string.IsNullOrEmpty(csvSeparatorChar))
        {
            Debug.LogWarning("Warning: empty/null separator. using `,`");
            csvSeparatorChar = ",";
        }
        yield return(null);

        if (samples.Count > 0)
        {
            string row = "Path" + csvSeparatorChar + "SteerAngle" + csvSeparatorChar + "Throttle" + csvSeparatorChar + "Brake" + csvSeparatorChar + "Speed" + csvSeparatorChar + "X_Position" +
                         csvSeparatorChar + "Y_Position" + csvSeparatorChar + "Pitch" + csvSeparatorChar + "Yaw" + csvSeparatorChar + "Roll" + newLine;
            File.AppendAllText(Path.Combine(m_saveLocation, CSVFileName), row);

            ObjectiveSpawner.SetInitialPositions();
            int         count          = samples.Count;
            RobotSample sample         = null;
            int         badPickupCount = 0;
            bool        isPickingUp    = false;
            for (int i = 0; i < count; i++)
            {
                // hack: for some reason there are lots of extra samples during the pickup, so artificially advance and drop them
                if (!IsPickingUpSample && isPickingUp)
                {
                    do
                    {
                        sample = samples.Dequeue();
                        i++;
                        badPickupCount++;
                    } while (!sample.stopPickup && samples.Count > 0 && i < count);
                    isPickingUp       = false;
                    IsPickingUpSample = false;
                }
                sample             = samples.Dequeue();
                transform.position = sample.position;
                transform.rotation = sample.rotation;
                if (sample.triggerPickup)
                {
                    isPickingUp = true;
//					Debug.Log ( "recorded pickup" );
                    curObjective = sample.curSample.GetComponent <PickupSample> ();
                    curObjective.transform.parent = null;
                    curObjective.Collider.enabled = true;
                    PickupObjective(null);
                }
                if (sample.stopPickup)
                {
                    Debug.Log("STOP!!");
                    isPickingUp       = false;
                    IsPickingUpSample = false;
                }
                string camPath = WriteImage(recordingCam, "robocam", sample.timestamp);

                row = camPath + csvSeparatorChar + sample.steerAngle + csvSeparatorChar + sample.throttle + csvSeparatorChar + sample.brake + csvSeparatorChar + sample.speed + csvSeparatorChar +
                      sample.position.x + csvSeparatorChar + sample.position.z + csvSeparatorChar + sample.pitch + csvSeparatorChar + sample.yaw + csvSeparatorChar + sample.roll + newLine;
                File.AppendAllText(Path.Combine(m_saveLocation, CSVFileName), row);

                yield return(null);
            }
            Debug.Log("bad pickup count: " + badPickupCount);
            isSaving = false;
            //need to reset the car back to its position before ending recording, otherwise sometimes the car ended up in strange areas
            transform.position = saved_position;
            transform.rotation = saved_rotation;
            Vector3 euler = cameraVAxis.localEulerAngles;
            euler.x = saved_vAngle;
            cameraVAxis.localEulerAngles = euler;
            Move(0);
            Rotate(0);
            RotateCamera(0, 0);
        }
    }
    //Changed the WriteSamplesToDisk to a IEnumerator method that plays back recording along with percent status from UISystem script
    //instead of showing frozen screen until all data is recorded
    public IEnumerator WriteSamplesToDisk()
    {
        string newLine = "\n";

        if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
        {
            newLine = "\r\n";
        }

        yield return(null);

        if (samples.Count > 0)
        {
            string row = "Path,SteerAngle,Throttle,Brake,Speed,X_Position,Y_Position,Pitch,Yaw,Roll" + newLine;
            File.AppendAllText(Path.Combine(m_saveLocation, CSVFileName), row);

            ObjectiveSpawner.SetInitialPositions();
            int         count          = samples.Count;
            RobotSample sample         = null;
            int         badPickupCount = 0;
            bool        isPickingUp    = false;
            for (int i = 0; i < count; i++)
            {
                // hack: for some reason there are lots of extra samples during the pickup, so artificially advance and drop them
                if (!IsPickingUpSample && isPickingUp)
                {
                    do
                    {
                        sample = samples.Dequeue();
                        i++;
                        badPickupCount++;
                    } while (!sample.stopPickup && samples.Count > 0 && i < count);
                    isPickingUp = false;
                }
                sample             = samples.Dequeue();
                transform.position = sample.position;
                transform.rotation = sample.rotation;
                if (sample.triggerPickup)
                {
                    isPickingUp = true;
//					Debug.Log ( "recorded pickup" );
                    curObjective = sample.curSample.GetComponent <PickupSample> ();
                    curObjective.transform.parent = null;
                    curObjective.Collider.enabled = true;
                    PickupObjective(null);
                }
                if (sample.stopPickup)
                {
                    Debug.Log("STOP!!");
                    isPickingUp = false;
                }
                string camPath = WriteImage(recordingCam, "robocam", sample.timestamp);

                row = camPath + "," + sample.steerAngle + "," + sample.throttle + "," + sample.brake + "," + sample.speed + "," +
                      sample.position.x + "," + sample.position.z + "," + sample.pitch + "," + sample.yaw + "," + sample.roll + newLine;
                File.AppendAllText(Path.Combine(m_saveLocation, CSVFileName), row);

                yield return(null);
            }
            Debug.Log("bad pickup count: " + badPickupCount);
            isSaving = false;
            //need to reset the car back to its position before ending recording, otherwise sometimes the car ended up in strange areas
            transform.position = saved_position;
            transform.rotation = saved_rotation;
            Vector3 euler = cameraVAxis.localEulerAngles;
            euler.x = saved_vAngle;
            cameraVAxis.localEulerAngles = euler;
            Move(0);
            Rotate(0);
            RotateCamera(0, 0);
        }

/*		yield return new WaitForSeconds(0.000f); //retrieve as fast as we can but still allow communication of main thread to screen and UISystem
 *              if (samples.Count > 0) {
 *                      //pull off a sample from the que
 *                      RobotSample sample = samples.Dequeue();
 *
 *                      //pysically moving the car to get the right camera position
 *                      transform.position = sample.position;
 *                      transform.rotation = sample.rotation;
 * //			Vector3 euler = cameraVAxis.localEulerAngles;
 * //			euler.x = sample.verticalAngle;
 * //			cameraVAxis.localEulerAngles = euler;
 *
 *                      // Capture and Persist Image
 *                      string camPath = WriteImage ( recordingCam, "robocam", sample.timestamp );
 *
 *                      string row = camPath + "," + sample.steerAngle + "," + sample.throttle + "," + sample.brake + "," + sample.speed + "," +
 *                              sample.position.x + "," + sample.position.y + "," + sample.position.z + "," + sample.yaw + "\r\n";
 * //			string row = string.Format ("{0},{1},{2},{3},{4},{5},{6}\n", centerPath, leftPath, rightPath, sample.steeringAngle, sample.throttle, sample.brake, sample.speed);
 *                      File.AppendAllText (Path.Combine (m_saveLocation, CSVFileName), row);
 *              }
 *              if (samples.Count > 0) {
 *                      //request if there are more samples to pull
 *                      StartCoroutine(WriteSamplesToDisk());
 *              }
 *              else
 *              {
 *                      //all samples have been pulled
 *                      StopCoroutine(WriteSamplesToDisk());
 *                      isSaving = false;
 *
 *                      //need to reset the car back to its position before ending recording, otherwise sometimes the car ended up in strange areas
 *                      transform.position = saved_position;
 *                      transform.rotation = saved_rotation;
 *                      Vector3 euler = cameraVAxis.localEulerAngles;
 *                      euler.x = saved_vAngle;
 *                      cameraVAxis.localEulerAngles = euler;
 *                      Move ( 0 );
 *                      Rotate ( 0 );
 *                      RotateCamera ( 0, 0 );
 *              }*/
    }