AttitudeJson.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Collections.Generic;
  2. using Newtonsoft.Json.Linq;
  3. using o0.IMU;
  4. using o0.Geometry;
  5. using o0;
  6. public class AttitudeJson : JCUnityLib.CustomJson
  7. {
  8. public AttitudeJson() : base()
  9. {
  10. InitJsonClass<_9AxisPreProcessor>(() => new _9AxisPreProcessor(),
  11. "AccByteIndex",
  12. "GyrByteIndex",
  13. "MagByteIndex",
  14. "ByteToAcc",
  15. "ByteToGyr",
  16. "ByteToMag",
  17. "GyrCalibrater",
  18. "MagCalibrater",
  19. "ByteReverseMS"
  20. );
  21. InitJsonClass<MagnetometerAutoCalibrater>(() => new MagnetometerAutoCalibrater(),
  22. "CountPerLength",
  23. "EllipsoidFitting",
  24. "FitCountLeft",
  25. "FitThreshold",
  26. "LastTimestamp",
  27. "Lock",
  28. "MaxCount",
  29. "NewBlock",
  30. "NewBlockAccumulation",
  31. "Variance",
  32. "VectorByBlock"
  33. );
  34. InitJsonClass<ByteToShorts>(() => new ByteToShorts(3),
  35. "ByteToShort"
  36. );
  37. InitJsonClass<MeanMaintainer<Vector<double>>>(() => new MeanMaintainer<Vector<double>>(),
  38. "Count",
  39. "Mean"
  40. );
  41. InitJsonClass<ByteToShortByVariance>(() => new ByteToShortByVariance(),
  42. "Count",
  43. "Reverse",
  44. "Short",
  45. "ThresholdRate"
  46. );
  47. InitJsonClass<EllipsoidFitting>(
  48. o => {
  49. var to = (EllipsoidFitting)o;
  50. JToken jt = new JObject();
  51. jt["Center"] = ToJTokenByImporter(to.Center);
  52. jt["CorrectMatrixArray"] = ToJTokenByImporter(to.CorrectMatrixArray);
  53. jt["Raduis"] = ToJTokenByImporter(to.Radius);
  54. return jt;
  55. },
  56. jt => {
  57. var o = new EllipsoidFitting(
  58. (Vector<double>)ParseByExporter(jt["Center"], typeof(Vector<double>)),
  59. null,
  60. (Vector<double>)ParseByExporter(jt["Radius"], typeof(Vector<double>))
  61. );
  62. o.CorrectMatrixArray = (double[][])ParseByExporter(jt["CorrectMatrixArray"], typeof(double[][]));
  63. return o;
  64. }
  65. );
  66. InitJsonClass<Dictionary<Vector<int>, Vector<double>>>(
  67. o => JToken.FromObject(o),
  68. jt => {
  69. var o = new Dictionary<Vector<int>, Vector<double>>();
  70. foreach (JProperty item in jt)
  71. o[ParseByExporter<Vector<int>>(JArray.Parse(item.Name))]
  72. = ParseByExporter<Vector<double>>(item.Value);
  73. return o;
  74. }
  75. );
  76. InitJsonClass<Vector<int>>(
  77. o => JToken.FromObject(o),
  78. jt => new Vector<int>(jt.ToObject<int[]>())
  79. );
  80. InitJsonClass<Vector<double>>(
  81. o => JToken.FromObject(o),
  82. jt => new Vector<double>(jt.ToObject<double[]>())
  83. );
  84. }
  85. }