ExcessiveSpeedWhenUphill.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. /*
  9. def callback_cicv_location(data):
  10. global angular_velocity_z
  11. global Ego_position_x
  12. global Ego_position_y
  13. global Ego_yaw
  14. Ego_position_x=data.position_x
  15. Ego_position_y=data.position_y
  16. Ego_yaw=data.yaw
  17. #print(Ego_yaw)
  18. angular_velocity_z=data.angular_velocity_z
  19. #print(angular_velocity_z)
  20. if abs(angular_velocity_z)>=27:
  21. event_label='overswing' #横摆角速度过大
  22. print(event_label)
  23. */
  24. func Topic() string {
  25. return "/cicv_location"
  26. }
  27. func Label() string {
  28. return "ExcessiveSpeedWhenUphill"
  29. }
  30. var (
  31. count int = 0
  32. threshold = 0.05
  33. )
  34. func QuaternionToEuler(x, y, z, w float64) float64 {
  35. // 归一化四元数
  36. length := math.Sqrt(x*x + y*y + z*z + w*w)
  37. x /= length
  38. y /= length
  39. z /= length
  40. w /= length
  41. // 计算欧拉角
  42. pitch := math.Asin(2 * (w*y - z*x))
  43. return pitch
  44. }
  45. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  46. defer func() {
  47. if r := recover(); r != nil {
  48. fmt.Println("Recovered from panic:", r)
  49. }
  50. }()
  51. if count%10 == 0 {
  52. OutsideWorkshopFlag, ok1 := shareVars.Load("OutsideWorkshopFlag")
  53. if ok1 && OutsideWorkshopFlag.(bool) {
  54. if math.Abs(data.AngularVelocityZ) >= 17.0 && QuaternionToEuler(data.Qx, data.Qy, data.Qz, data.Qw) >= threshold {
  55. count = 1
  56. return Label()
  57. }
  58. }
  59. }
  60. count++
  61. return ""
  62. }