public IEnumerator Sample() { Debug.Log("Sample"); // Start the Coroutine to Capture Data Every Second. // Persist that Information to a CSV and Perist the Camera Frame yield return(new WaitForSeconds(0.0666666666666667f)); if (m_saveLocation != "") { CarSample sample = new CarSample(); sample.timeStamp = System.DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff"); sample.steeringAngle = m_SteerAngle / m_MaximumSteerAngle; sample.throttle = AccelInput; sample.brake = BrakeInput; sample.speed = CurrentSpeed; sample.position = transform.position; sample.rotation = transform.rotation; carSamples.Enqueue(sample); sample = null; //may or may not be needed } // Only reschedule if the button hasn't toggled if (IsRecording) { StartCoroutine(Sample()); } }
private IEnumerator Sample() { if (m_SaveLocation != "") { CarSample sample = new CarSample(); sample.TimeStamp = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff"); sample.Mode = m_Control.CurrentMode == CarUserControl.Mode.Autonomous ? 'A' : 'M'; sample.Accel = m_Pid.Accel; sample.Steering = m_Pid.Steering; sample.Speed = m_Car.Speed; sample.Position = transform.position; sample.Rotation = transform.rotation; m_CarSamples.Enqueue(sample); sample = null; } yield return(new WaitForSeconds(m_FrameDelay)); // Only reschedule if the button hasn't been toggled if (IsRecording) { StartCoroutine(Sample()); } }
//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() { Debug.Log("WriteSamplesToDisk"); yield return(new WaitForSeconds(0.000f)); //retrieve as fast as we can but still allow communication of main thread to screen and UISystem if (carSamples.Count > 0) { //pull off a sample from the que CarSample sample = carSamples.Dequeue(); //pysically moving the car to get the right camera position transform.position = sample.position; transform.rotation = sample.rotation; // Capture and Persist Image //string centerPath = WriteImage (CenterCamera, "center", sample.timeStamp); //string leftPath = WriteImage (LeftCamera, "left", sample.timeStamp); //string rightPath = WriteImage (RightCamera, "right", sample.timeStamp); // capture lidar image string lidarPath = WriteLidarData(lidar, "lidar", sample.timeStamp); if (lidarPath != null) { string row = string.Format("{0},{1},{2},{3},{4}\n", lidarPath, sample.steeringAngle, sample.throttle, sample.brake, sample.speed); File.AppendAllText(Path.Combine(m_saveLocation, CSVFileName), row); } } if (carSamples.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; m_Rigidbody.velocity = new Vector3(0f, -10f, 0f); Move(0f, 0f, 0f, 0f); } }
private IEnumerator WriteSamplesToDisk() { //retrieve as fast as we can but still allow communication of main thread to screen and UISystem yield return(null); if (m_CarSamples.Count > 0) { //pull off a sample from the queue CarSample sample = m_CarSamples.Dequeue(); //pysically moving the car to get the right camera position transform.position = sample.Position; transform.rotation = sample.Rotation; // Capture and Persist Image string paths = ""; foreach (MyCamera cam in m_Cameras) { paths += WriteImage(cam, sample.TimeStamp) + ","; } string row = string.Format("{0}{1},{2},{3},{4}\n", paths, sample.Accel, sample.Steering, sample.Speed, sample.Mode); File.AppendAllText(Path.Combine(m_SaveLocation, m_CSVFileName), row); } if (m_CarSamples.Count > 0) { //request if there are more samples to pull StartCoroutine(WriteSamplesToDisk()); } else { //all samples have been pulled IsSaving = false; //need to reset the car back to its position before ending recording transform.position = m_SavedPosition; transform.rotation = m_SavedRotation; m_Rigidbody.velocity = m_SavedVelocity; } }