123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Net;
- using System.Text;
- using UnityEngine;
- public class DebugDisplay : MonoBehaviour
- {
- public BicycleController bicycleController;
- private BikeSensorData sensorData = BikeSensorData.Instance;
- private string ip;
- private string text;
- private void Start()
- {
- ip = GetIp();
- }
- private void Update()
- {
- var rbSpeed = bicycleController.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: {(sensorSpeed - rbSpeed):n2}");
- 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;
- }
- }
|