TTC.go 892 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "cicv-data-closedloop/common/entity"
  4. "cicv-data-closedloop/pjisuv_msgs"
  5. "math"
  6. )
  7. func Topic() string {
  8. return "/tpperception"
  9. }
  10. // Label todo 禁止存在下划线_
  11. func Label() string {
  12. return "TTC"
  13. }
  14. func Rule(data *pjisuv_msgs.PerceptionObjects, param entity.ExtendParam) string {
  15. for _, obj := range data.Objs {
  16. if math.Abs(float64(obj.Y)) <= 2 && obj.X >= 8 {
  17. theta := DegreesToRadians(param.YawOfCicvLocation)
  18. vxrel := (float64(obj.Vxabs)-param.VelocityXOfCicvLocation)*math.Cos(theta) + (float64(obj.Vyabs)-param.VelocityYOfCicvLocation)*math.Sin(theta)
  19. ttc := -((float64(obj.X) - 5.2) / (vxrel + 0.001))
  20. //fmt.Println("TTC值为:", ttc)
  21. if ttc >= 0 && ttc <= 5 {
  22. return "TTC"
  23. }
  24. }
  25. }
  26. return ""
  27. }
  28. // DegreesToRadians 计算角度转弧度
  29. func DegreesToRadians(degrees float64) float64 {
  30. return degrees * math.Pi / 180.0
  31. }