void Update() { if (infoText == null) { return; } sb.Length = 0; sb.Capacity = 16; float speed = controller.Speed; float steer = controller.SteerAngle; float vAngle = controller.VerticalAngle; float throttle = controller.ThrottleInput; float brake = controller.BrakeInput; Vector2 position = new Vector2(controller.Position.x, controller.Position.z); // Vector3 position = controller.Position; float pitch = controller.Pitch; // new: set yaw angle counter-clockwise and relative to positive-x float yaw = IRobotController.ConvertAngleToCCWXBased(controller.Yaw); // float yaw = controller.Yaw; float roll = controller.Roll; sb.Append("Throttle: " + throttle.ToString("F1") + "\n"); sb.Append("Brake: " + brake.ToString("F1") + "\n"); sb.Append("Steer angle: " + steer.ToString("F4") + "\n"); sb.Append("Ground speed: " + speed.ToString("F1") + "m/s\n"); sb.Append("Position: " + position.ToString() + "\n"); sb.Append("Pitch angle: " + pitch.ToString("F2") + "\n"); sb.Append("Yaw angle: " + yaw.ToString("F2") + "\n"); sb.Append("Roll angle: " + roll.ToString("F2") + "\n"); // sb.Append ( "Camera zoom: " + controller.Zoom.ToString ( "F1" ) + "x\n" ); sb.Append("Is near objective: " + (controller.IsNearObjective ? "Yes" : "No") + "\n"); sb.Append("Is picking up:" + (controller.IsPickingUpSample ? "Yes" : "No")); infoText.text = sb.ToString(); if (controller.PickupProgress != -1) { if (!progressParent.activeSelf) { progressParent.SetActive(true); } progressBar.fillAmount = controller.PickupProgress; } else { if (progressParent.activeSelf) { progressParent.SetActive(false); } } }
void EmitTelemetry(SocketIOEvent obj) { // Debug.Log ( "Emitting" ); UnityMainThreadDispatcher.Instance().Enqueue(() => { print("Attempting to Send..."); // Collect Data from the Car Dictionary <string, string> data = new Dictionary <string, string>(); data["steering_angle"] = robotController.SteerAngle.ToString("N4"); // data["vert_angle"] = robotController.VerticalAngle.ToString ("N4"); data["throttle"] = robotController.ThrottleInput.ToString("N4"); data["brake"] = robotController.BrakeInput.ToString("N4"); data["speed"] = robotController.Speed.ToString("N4"); Vector3 pos = robotController.Position; data["position"] = pos.x.ToString("N4") + robotController.csvSeparatorChar + pos.z.ToString("N4"); data["pitch"] = robotController.Pitch.ToString("N4"); // new: convert the angle to CCW, x-based data["yaw"] = IRobotController.ConvertAngleToCCWXBased(robotController.Yaw).ToString("N4"); data["roll"] = robotController.Roll.ToString("N4"); data["fixed_turn"] = robotController.IsTurningInPlace ? "1" : "0"; data["near_sample"] = robotController.IsNearObjective ? "1" : "0"; data["picking_up"] = robotController.IsPickingUpSample ? "1" : "0"; Debug.Log("picking_up is " + robotController.IsPickingUpSample); data["sample_count"] = ObjectiveSpawner.samples.Length.ToString(); StringBuilder sample_x = new StringBuilder(); StringBuilder sample_y = new StringBuilder(); for (int i = 0; i < ObjectiveSpawner.samples.Length; i++) { GameObject go = ObjectiveSpawner.samples[i]; sample_x.Append(go.transform.position.x.ToString("N2") + robotController.csvSeparatorChar); sample_y.Append(go.transform.position.z.ToString("N2") + robotController.csvSeparatorChar); } if (ObjectiveSpawner.samples.Length != 0) { sample_x.Remove(sample_x.Length - 1, 1); sample_y.Remove(sample_y.Length - 1, 1); } data["samples_x"] = sample_x.ToString(); data["samples_y"] = sample_y.ToString(); data["image"] = Convert.ToBase64String(CameraHelper.CaptureFrame(frontFacingCamera)); // Debug.Log ("sangle " + data["steering_angle"] + " vert " + data["vert_angle"] + " throt " + data["throttle"] + " speed " + data["speed"] + " image " + data["image"]); _socket.Emit("telemetry", new JSONObject(data)); }); }