PolarLeanController.cs 859 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using Sensors;
  3. namespace Controller.Lean
  4. {
  5. [Serializable]
  6. public struct PolarRotationMapping
  7. {
  8. public float maxRight;
  9. public float center;
  10. }
  11. public class PolarLeanController : ILeanController
  12. {
  13. private float leanFactor;
  14. public PolarRotationMapping polarRotationMapping;
  15. private BikeSensorData sensorData;
  16. public float LeanAngle { get; private set; }
  17. private void Start()
  18. {
  19. sensorData = BikeSensorData.Instance;
  20. leanFactor = 90f / (polarRotationMapping.maxRight - polarRotationMapping.center);
  21. }
  22. private void Update()
  23. {
  24. var polarData = sensorData.PolarData;
  25. if (polarData != null) LeanAngle = (polarData.Value.Acc.y - polarRotationMapping.center) * leanFactor;
  26. }
  27. }
  28. }