using System; using System.Net; using System.Text; using Controller; using Controller.Bicycle; using Sensors; using UnityEngine; namespace Display { public class DebugDisplay : MonoBehaviour { public WcBicycleController wcBicycleController; private BikeSensorData sensorData = BikeSensorData.Instance; private string ip; private string text; private void Start() { ip = GetIp(); } private void Update() { var rbSpeed = wcBicycleController.rigidBody.velocity.magnitude * 3.6; var sensorSpeed = sensorData.SpeedData?.SpeedKmh ?? 0f; var sb = new StringBuilder(); //sb.Append( // $"MotorTorque: {bicycleController.CurrentMotorTorque:n2}\nBrakeTorque: {bicycleController.CurrentBrakeTorque:n2}\nSteer: {bicycleController.CurrentSteerAngle}\nLean: {bicycleController.CurrentLeaningAngle:n4}\n"); sb.Append("-----Sensors------\n"); sb.Append( $"Speed: {(sensorData.SpeedData?.Speed ?? 0f):n4} m/s\nPolar Acc ({(sensorData.PolarData?.Acc.x ?? 0f):n4}; {(sensorData.PolarData?.Acc.y ?? 0f):n4}; {(sensorData.PolarData?.Acc.z ?? 0f):n4}) "); sb.Append("\n\n"); sb.Append($"IP: {ip}\n"); sb.Append("----BicycleController-----\n"); sb.Append($"Actual Speed {rbSpeed:n2} km/h - Dif: {(wcBicycleController.CurrentSpeed * 3.6 - rbSpeed):n2}\n"); sb.Append( $"Current Speed = {wcBicycleController.CurrentSpeed:n2} m/s ({(wcBicycleController.CurrentSpeed * 3.6):n2} km/h)"); text = sb.ToString(); } private void OnGUI() { var padding = 10; var width = 260; var height = 175; var x = Screen.width - width - padding; var y = Screen.height - height - padding; GUI.TextField(new Rect(x, y, width, height), text); } private String GetIp() { string usedIp = null; foreach (var ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { if (usedIp == null || ip.ToString().StartsWith("192.168.1.")) { usedIp = ip.ToString(); } } } return usedIp; } } }