FrontWheelTrackerLogger.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Logging.Base;
  5. using Tracking;
  6. using UnityEngine;
  7. namespace Logging.Data
  8. {
  9. public readonly struct FrontWheelTrackerData : ISerializable
  10. {
  11. private readonly long timestamp;
  12. private readonly float debugLegTrackerPositionX;
  13. private readonly float debugLegTrackerPositionY;
  14. private readonly float debugLegTrackerPositionZ;
  15. private readonly float debugPosOnBikePlaneX;
  16. private readonly float debugPosOnBikePlaneY;
  17. private readonly float debugPosOnBikePlaneZ;
  18. private readonly float debugFrontWheelTrackerRelativePositionX;
  19. private readonly float debugFrontWheelTrackerRelativePositionY;
  20. private readonly float debugFrontWheelTrackerRelativePositionZ;
  21. public FrontWheelTrackerData(long timestamp, float debugLegTrackerPositionX, float debugLegTrackerPositionY,
  22. float debugLegTrackerPositionZ, float debugPosOnBikePlaneX, float debugPosOnBikePlaneY,
  23. float debugPosOnBikePlaneZ, float debugFrontWheelTrackerRelativePositionX,
  24. float debugFrontWheelTrackerRelativePositionY, float debugFrontWheelTrackerRelativePositionZ)
  25. {
  26. this.timestamp = timestamp;
  27. this.debugLegTrackerPositionX = debugLegTrackerPositionX;
  28. this.debugLegTrackerPositionY = debugLegTrackerPositionY;
  29. this.debugLegTrackerPositionZ = debugLegTrackerPositionZ;
  30. this.debugPosOnBikePlaneX = debugPosOnBikePlaneX;
  31. this.debugPosOnBikePlaneY = debugPosOnBikePlaneY;
  32. this.debugPosOnBikePlaneZ = debugPosOnBikePlaneZ;
  33. this.debugFrontWheelTrackerRelativePositionX = debugFrontWheelTrackerRelativePositionX;
  34. this.debugFrontWheelTrackerRelativePositionY = debugFrontWheelTrackerRelativePositionY;
  35. this.debugFrontWheelTrackerRelativePositionZ = debugFrontWheelTrackerRelativePositionZ;
  36. }
  37. public KeyValuePair<long, string[]> Serialize()
  38. {
  39. return new KeyValuePair<long, string[]>(timestamp, new[]
  40. {
  41. debugLegTrackerPositionX.ToString("F4", CultureInfo.InvariantCulture),
  42. debugLegTrackerPositionY.ToString("F4", CultureInfo.InvariantCulture),
  43. debugLegTrackerPositionZ.ToString("F4", CultureInfo.InvariantCulture),
  44. debugPosOnBikePlaneX.ToString("F4", CultureInfo.InvariantCulture),
  45. debugPosOnBikePlaneY.ToString("F4", CultureInfo.InvariantCulture),
  46. debugPosOnBikePlaneZ.ToString("F4", CultureInfo.InvariantCulture),
  47. debugFrontWheelTrackerRelativePositionX.ToString("F4", CultureInfo.InvariantCulture),
  48. debugFrontWheelTrackerRelativePositionY.ToString("F4", CultureInfo.InvariantCulture),
  49. debugFrontWheelTrackerRelativePositionZ.ToString("F4", CultureInfo.InvariantCulture)
  50. });
  51. }
  52. }
  53. public class FrontWheelTrackerLogger : SensorDataLogger<FrontWheelTrackerData>
  54. {
  55. public FrontWheelTracker frontWheelTracker;
  56. public override string Key => "front_wheel_tracker";
  57. private void Update()
  58. {
  59. var legTrackerPos = frontWheelTracker.legTracker.RelativePosition;
  60. var posOnBikePlane = frontWheelTracker.DebugPosOnBikePlane;
  61. var fwtRelativePos = frontWheelTracker.RelativePosition;
  62. Log(new FrontWheelTrackerData(Helpers.RoundToLong(Time.time * 1000f),
  63. legTrackerPos.x,
  64. legTrackerPos.y,
  65. legTrackerPos.z,
  66. posOnBikePlane.x,
  67. posOnBikePlane.y,
  68. posOnBikePlane.z,
  69. fwtRelativePos.x,
  70. fwtRelativePos.y,
  71. fwtRelativePos.z));
  72. }
  73. public override IEnumerable<FrontWheelTrackerData> ReadLog(IEnumerable<IEnumerable<string>> lines)
  74. {
  75. throw new NotImplementedException(); //TODO
  76. }
  77. }
  78. }