TTC.go 777 B

123456789101112131415161718192021222324252627282930313233
  1. package main
  2. import (
  3. "cicv-data-closedloop/kinglong_msgs"
  4. "math"
  5. )
  6. func Topic() string {
  7. return "/tpperception"
  8. }
  9. func Label() string {
  10. return "TTC"
  11. }
  12. func Rule(data *kinglong_msgs.PerceptionObjects, velocityX float64, velocityY float64, yaw float64) string {
  13. for _, obj := range data.Objs {
  14. if math.Abs(float64(obj.Y)) <= 2 && obj.X >= 8 && math.Abs(velocityX) > 0.5 {
  15. theta := DegreesToRadians(yaw)
  16. vxrel := (float64(obj.Vxabs)-velocityX)*math.Cos(theta) + (float64(obj.Vyabs)-velocityY)*math.Sin(theta)
  17. ttc := -((float64(obj.X) - 5.2) / (vxrel + 0.001))
  18. if ttc >= 0 && ttc <= 5 {
  19. return "TTC"
  20. }
  21. }
  22. }
  23. return ""
  24. }
  25. // DegreesToRadians 计算角度转弧度
  26. func DegreesToRadians(degrees float64) float64 {
  27. return degrees * math.Pi / 180.0
  28. }