public void SpawnMe(ObjectiveSpawner spawner) { if (isServer) { RpcStartSpawnIndependantTimer(independantSpawners.IndexOf(spawner)); } }
private void ResetSpawner(ObjectiveSpawner spawner) { spawner.StopRespawnEffects(); spawner.StopAllCoroutines(); spawner.Despawn(); if (spawner.StartWithBall && !RoundManager.instance.IsTiebreaker) { spawner.Spawn(); } }
IEnumerator DoPickup() { float total = 1 + 1.5f + 1.5f + 1.5f + 1.5f + 3; float t = 0; // curObjective.Collider.enabled = false; // grabbingObject = false; // first find a new folded position facing the target Vector3 centerPos = armActuator.baseTransform.position; centerPos.y = armActuator.foldedPosition.position.y; float dist = (armActuator.foldedPosition.position - centerPos).magnitude; Vector3 toTarget = curObjective.GetCenterPosition() - centerPos; toTarget.y = 0; // assign that position to the folded position and the arm will turn to it armActuator.SetTarget(0, centerPos + toTarget.normalized * dist); t = 0; while (t < 1) { // if ( IsRecording ) // GetSample ( true ); yield return(null); // PickupProgress += Time.deltaTime / total; t += Time.deltaTime; } // yield return new WaitForSeconds ( 2 ); // now assign the extended position as something near the sample's position Ray ray = new Ray(armActuator.foldedPosition.position, curObjective.GetCenterPosition() - armActuator.foldedPosition.position); // Ray ray = new Ray ( robotGrabPoint.position, curObjective.GetCenterPosition () - robotGrabPoint.position ); RaycastHit hit; curObjective.Collider.Raycast(ray, out hit, 1); curObjective.Collider.enabled = false; // Physics.Raycast ( ray, out hit ); armActuator.SetTarget(1, hit.point); // armActuator.SetTarget ( 1, curObjective.GetCenterPosition () ); // and move towards that over 3 sec armActuator.MoveToTarget(1.5f); t = 0; while (t < 1.5f) { // if ( IsRecording ) // GetSample ( true ); yield return(null); // PickupProgress += Time.deltaTime / total; t += Time.deltaTime; } // yield return new WaitForSeconds ( 3 ); // parent and position the sample to our vacuum attachment Vector3 positionDIff = curObjective.transform.position - hit.point; Debug.DrawLine(hit.point, curObjective.transform.position, Color.red, 3); curObjective.transform.position = robotGrabPoint.position + positionDIff; // curObjective.transform.position = robotGrabPoint.position;// - Vector3.up * curObjective.Collider.bounds.extents.y; curObjective.transform.parent = armActuator.wrist; // now move back to folded position over 3 sec armActuator.MoveToTarget(1.5f, true); t = 0; while (t < 1.5f) { // if ( IsRecording ) // GetSample ( true ); yield return(null); // PickupProgress += Time.deltaTime / total; t += Time.deltaTime; } // yield return new WaitForSeconds ( 3 ); // find a place to put the sample Vector3 newPos = getSaveStatus() ? finalPositions[curObjective.gameObject] : GetPositionOnFlatbed(); if (IsRecording) { finalPositions.Add(curObjective.gameObject, newPos); } toTarget = newPos - centerPos; toTarget.y = 0; // move the folded position to turn the arm around armActuator.SetTarget(0, centerPos + toTarget.normalized * dist); t = 0; while (t < 1.5f) { // if ( IsRecording ) // GetSample ( true ); yield return(null); // PickupProgress += Time.deltaTime / total; t += Time.deltaTime; } // yield return new WaitForSeconds ( 3 ); // extend the arm out to place the object positionDIff = curObjective.transform.position - armActuator.foldedPosition.position; armActuator.SetTarget(1, newPos - positionDIff); // armActuator.SetTarget ( 1, newPos ); armActuator.MoveToTarget(1.5f); t = 0; while (t < 1.5f) { // if ( IsRecording ) // GetSample ( true ); yield return(null); // PickupProgress += Time.deltaTime / total; t += Time.deltaTime; } // yield return new WaitForSeconds ( 3 ); // parent and position it to us (not to the flatbed because thatscrews up scales) curObjective.transform.position = newPos; curObjective.transform.parent = robotBody; // lastly reset the arm, and go back to drivable state armActuator.ResetPosition(); t = 0; while (t < 3) { // if ( IsRecording ) // GetSample ( true ); yield return(null); // PickupProgress += Time.deltaTime / total; t += Time.deltaTime; } // yield return new WaitForSeconds ( 6 ); // IsPickingUpSample = false; rb.isKinematic = false; // IsNearObjective = false; // PickupProgress = -1; if (IsRecording) { // GetSample ( true ); StopPickup(); } if (!getSaveStatus()) { ObjectiveSpawner.RemoveSample(curObjective.gameObject); } IsNearObjective = false; curObjective = null; yield return(null); IsPickingUpSample = false; }
public void Despawn(ObjectiveSpawner spawner) { spawnedSpawners.Remove(spawner); unspawnedSpawners.Add(spawner); }
//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); } }
void Awake() { instance = this; }
//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 ); * }*/ }