LocationJump.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. OutsideWorkshopFlag, ok3 := shareVars.Load("OutsideWorkshopFlag")
  23. OutsideWorkshopFlag = OutsideWorkshopFlag.(bool)
  24. positionXOfCicvLocation, ok1 := shareVars.Load("PositionXOfCicvLocation")
  25. positionYOfCicvLocation, ok2 := shareVars.Load("PositionYOfCicvLocation")
  26. if ok1 && ok2 && ok3 {
  27. v1 := positionXOfCicvLocation.(float64)
  28. v2 := positionYOfCicvLocation.(float64)
  29. if v1 != 0 && v2 != 0 {
  30. d := math.Sqrt((v1-data.PositionX)*(v1-data.PositionX) + (v2-data.PositionY)*(v2-data.PositionY))
  31. if d >= 2 && OutsideWorkshopFlag == true {
  32. return Label()
  33. }
  34. }
  35. }
  36. return ""
  37. }