123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using TMPro;
- using UnityEngine;
- public class AntSetup : MonoBehaviour
- {
- [Header("Speed")] public int speedSensorId = 0;
- public float wheelCircumference = 2.096f;
- public TextMeshProUGUI speedDisplay;
-
- [Header("Powermeter")]
- public int powerMeterId = 0;
- public TextMeshProUGUI powerDisplay;
- public TextMeshProUGUI cadenceDisplay;
- public TextMeshProUGUI torqueDisplay;
- private SpeedSensorReceiver speedSensorReceiver;
- private PowerMeterReceiver powerMeterReceiver;
- private bool speedDisplayAvailable;
- private bool powerDisplayAvailable;
- private bool cadenceDisplayAvailable;
- private bool torqueDisplayAvailable;
- private BicycleController bicycleController;
- // Start is called before the first frame update
- void Start()
- {
- bicycleController = GetComponent<BicycleController>();
- speedDisplayAvailable = speedDisplay != null;
- powerDisplayAvailable = powerDisplay != null;
- torqueDisplayAvailable = torqueDisplay != null;
- cadenceDisplayAvailable = cadenceDisplay != null;
- speedSensorReceiver = new SpeedSensorReceiver(speedSensorId, wheelCircumference);
- powerMeterReceiver = new PowerMeterReceiver(powerMeterId);
- speedSensorReceiver.StartScan();
- powerMeterReceiver.StartScan();
- }
- // Update is called once per frame
- void Update()
- {
- //transform.Translate(Vector3.forward * (Time.deltaTime * (speedSensorReceiver?.Speed ?? 0)));
- bicycleController.SetSpeed(speedSensorReceiver?.Speed ?? 0);
- //bicycleController.SetTorque(powerMeterReceiver?.CrankTorque ?? 0); //TODO crank to wheel torque;
- if (speedDisplayAvailable)
- {
- speedDisplay.text = $"{(speedSensorReceiver?.SpeedKmh ?? 0f):n2} km/h";
- }
- if (powerDisplayAvailable)
- {
- powerDisplay.text = $"{(powerMeterReceiver?.InstantaneousPower ?? 0f):0} W";
- }
- if (cadenceDisplayAvailable)
- {
- cadenceDisplay.text = $"{(powerMeterReceiver?.InstantaneousCadence ?? 0f):0} rpm";
- }
- if (torqueDisplayAvailable)
- {
- torqueDisplay.text = $"{(powerMeterReceiver?.CrankTorque ?? 0f):F2} Nm";
- }
- }
- }
|