LocationJump.go 890 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "math"
  6. "sync"
  7. )
  8. func Topic() string {
  9. return "/cicv_location"
  10. }
  11. // 禁止存在下划线_
  12. func Label() string {
  13. return "LocationJump"
  14. }
  15. // 主进程的逻辑是先判断触发再缓存全局变量
  16. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  17. defer func() {
  18. if r := recover(); r != nil {
  19. fmt.Println("Recovered from panic:", r)
  20. }
  21. }()
  22. positionXOfCicvLocation, ok1 := shareVars.Load("PositionXOfCicvLocation")
  23. positionYOfCicvLocation, ok2 := shareVars.Load("PositionYOfCicvLocation")
  24. if ok1 && ok2 {
  25. v1 := positionXOfCicvLocation.(float64)
  26. v2 := positionYOfCicvLocation.(float64)
  27. if v1 != 0 && v2 != 0 {
  28. d := math.Sqrt((v1-data.PositionX)*(v1-data.PositionX) + (v2-data.PositionY)*(v2-data.PositionY))
  29. if d >= 2 {
  30. return Label()
  31. }
  32. }
  33. }
  34. return ""
  35. }