1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Net;
- using System.Text;
- using Controller;
- using Controller.Bicycle;
- using Sensors;
- using UnityEngine;
- namespace Display
- {
- public class DebugDisplay<T> : MonoBehaviour where T : IBicycleController
- {
- public T bicycleController;
- private BikeSensorData sensorData = BikeSensorData.Instance;
- private string ip;
- private string text;
- private void Start()
- {
- ip = GetIp();
- }
- private void Update()
- {
- var rbSpeed = bicycleController.RigidBodyVelocity.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: {(bicycleController.CurrentSpeed * 3.6 - rbSpeed):n2}\n");
- sb.Append(
- $"Current Speed = {bicycleController.CurrentSpeed:n2} m/s ({(bicycleController.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;
- }
- }
- }
|