ev_msg.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2019, sogwyms@gmail.com
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-12-01 sogwms The first version
  9. */
  10. #ifndef __EV_MSG_H__
  11. #define __EV_MSG_H__
  12. #include <rtconfig.h>
  13. #define IS_SAME_TOPIC(topica, topicb) (topica == topicb)
  14. #define DEF_EV_TOPICS(mytopics) \
  15. enum ev_topic \
  16. { \
  17. EV_TOPIC_IMU = 0, \
  18. EV_TOPIC_RPY, \
  19. EV_TOPIC_MOTION, \
  20. EV_TOPIC_POWER, \
  21. EV_TOPIC_SET_MOTOR_SPEED, \
  22. EV_TOPIC_LOCK_MOTOR, \
  23. EV_TOPIC_RC, \
  24. EV_TOPIC_SYS_STATUS, \
  25. EV_TOPIC_MOTOR_SPEED, \
  26. EV_TOPIC_REQUEST_MOTOR_SPEED, \
  27. EV_TOPIC_SIGNAL, \
  28. \
  29. mytopics \
  30. EV_TOTAL_TOPICS \
  31. };
  32. #if defined(PKG_EV_ENABLING_CUSTOM)
  33. #include <my_ev_custom.h>
  34. #ifdef MY_EV_TOPICS
  35. DEF_EV_TOPICS(MY_EV_TOPICS)
  36. #else
  37. DEF_EV_TOPICS()
  38. #endif
  39. #else
  40. DEF_EV_TOPICS()
  41. #endif
  42. /**
  43. * unit: mg, mdps, mGauss
  44. */
  45. struct msg_imu
  46. {
  47. long acc_x;
  48. long acc_y;
  49. long acc_z;
  50. long gyro_x;
  51. long gyro_y;
  52. long gyro_z;
  53. long mag_x;
  54. long mag_y;
  55. long mag_z;
  56. };
  57. struct msg_rpy
  58. {
  59. float roll;
  60. float pitch;
  61. float yaw;
  62. };
  63. /**
  64. * 放大100倍后的值. 如 current_power = 720 表示 7.20v
  65. */
  66. struct msg_power
  67. {
  68. int current_power;
  69. int total_power;
  70. int alert_power;
  71. };
  72. #define EV_SCALE 10000
  73. /**
  74. * 右手坐标系,以‘头’方向为X轴正方向, Z轴朝向地面
  75. * 旋转正方向,遵循右手法则
  76. * !归一化处理 (EV_SCALE)
  77. */
  78. struct msg_motion
  79. {
  80. int velocity_x; /* 在参考坐标系下 */
  81. int velocity_y;
  82. int velocity_z;
  83. int rotation_x; /* 在载体坐标系下 */
  84. int rotation_y;
  85. int rotation_z;
  86. };
  87. /**
  88. * 从x轴向始,逆时针依次编号为 m1,m2,...
  89. * !归一化处理 (EV_SCALE)
  90. */
  91. struct msg_motor
  92. {
  93. int m1;
  94. int m2;
  95. int m3;
  96. int m4;
  97. };
  98. struct msg_lock_motor
  99. {
  100. int bool_value; // TRUE <--> lock; FALSE <--> unlock
  101. };
  102. struct msg_sys_status
  103. {
  104. int bl_low_power : 1;
  105. int bl_running : 1;
  106. int bl_fault : 1;
  107. int bl_balance : 1;
  108. };
  109. enum ev_signal{
  110. EV_SIGNAL_LOW_POWER,
  111. EV_SIGNAL_NORMAL_POWER,
  112. EV_SIGNAL_IMBALANCE,
  113. EV_SIGNAL_BALANCE,
  114. };
  115. struct msg_signal
  116. {
  117. int info;
  118. };
  119. #endif /* __EV_MSG_H__ */