PerceptionSpeedDiffer.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. /*
  9. if obj_speed_dic is not {}: #相邻两帧对于同一目标物速度变化率超过设定阈值
  10. if obj.id in obj_speed_dic:
  11. objspeed=pow(pow(obj.vxabs,2)+pow(obj.vyabs,2),0.5)
  12. diff_rate=abs(objspeed-obj_speed_dic[obj.id])/(obj_speed_dic[obj.id]+0.0001)
  13. if diff_rate>0.1 and objspeed>0.5 and obj_speed_dic[obj.id]>0.5:
  14. event_label='perceptionspeeddiffer'
  15. print(event_label)
  16. print(objspeed," ",obj_speed_dic[obj.id]," ",diff_rate)
  17. else:
  18. print(objspeed," ",obj_speed_dic[obj.id]," ",diff_rate)
  19. */
  20. func Topic() string {
  21. return "/tpperception"
  22. }
  23. // 禁止存在下划线_
  24. func Label() string {
  25. return "PerceptionSpeedDiffer"
  26. }
  27. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionObjects) string {
  28. defer func() {
  29. if r := recover(); r != nil {
  30. fmt.Println("Recovered from panic:", r)
  31. }
  32. }()
  33. value, ok := shareVars.Load("ObjSpeedDicOfTpperception")
  34. if ok {
  35. objSpeedDicOfTpperception := value.(map[uint32]float64)
  36. for _, obj := range data.Objs {
  37. if len(objSpeedDicOfTpperception) != 0 {
  38. if _, exist := objSpeedDicOfTpperception[obj.Id]; exist {
  39. objSpeed := math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
  40. diffRate := math.Abs(objSpeed-objSpeedDicOfTpperception[obj.Id]) / (objSpeedDicOfTpperception[obj.Id] + 0.0001)
  41. if diffRate > 0.1 && objSpeed > 0.5 && objSpeedDicOfTpperception[obj.Id] > 0.5 {
  42. return Label()
  43. }
  44. }
  45. }
  46. }
  47. }
  48. return ""
  49. }