perceptionspeeddiffer.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "cicv-data-closedloop/pjisuv_param"
  5. "math"
  6. "reflect"
  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. // Label todo 禁止存在下划线_
  24. func Label() string {
  25. return "perceptionspeeddiffer"
  26. }
  27. func Rule(data *pjisuv_msgs.PerceptionObjects, param pjisuv_param.PjisuvParam) string {
  28. for _, obj := range data.Objs {
  29. if len(param.ObjSpeedDicOfTpperception) != 0 {
  30. if ContainsElement(param.ObjSpeedDicOfTpperception, obj.Id) {
  31. objSpeed := math.Pow(math.Pow(float64(obj.Vxabs), 2)+math.Pow(float64(obj.Vyabs), 2), 0.5)
  32. diffRate := math.Abs(objSpeed-param.ObjSpeedDicOfTpperception[obj.Id]) / (param.ObjSpeedDicOfTpperception[obj.Id] + 0.0001)
  33. if diffRate > 0.1 && objSpeed > 0.5 && param.ObjSpeedDicOfTpperception[obj.Id] > 0.5 {
  34. return "perceptionspeeddiffer"
  35. }
  36. }
  37. }
  38. }
  39. return ""
  40. }
  41. func ContainsElement(slice interface{}, element interface{}) bool {
  42. sliceValue := reflect.ValueOf(slice)
  43. if sliceValue.Kind() != reflect.Slice {
  44. return false
  45. }
  46. for i := 0; i < sliceValue.Len(); i++ {
  47. currentElement := sliceValue.Index(i).Interface()
  48. if reflect.DeepEqual(currentElement, element) {
  49. return true
  50. }
  51. }
  52. return false
  53. }