AuLongStop.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "fmt"
  5. "sync"
  6. "time"
  7. )
  8. var (
  9. StartTime int64
  10. IsStopped bool
  11. )
  12. func Topic() string {
  13. return "/cicv_location"
  14. }
  15. // 禁止存在下划线_
  16. func Label() string {
  17. return "AuLongStop"
  18. }
  19. func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
  20. defer func() {
  21. if r := recover(); r != nil {
  22. fmt.Println("Recovered from panic:", r)
  23. }
  24. }()
  25. automodeOfPjVehicleFdbPub, ok := shareVars.Load("AutomodeOfPjVehicleFdbPub")
  26. OutsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
  27. OutsideWorkshopFlag = OutsideWorkshopFlag.(bool)
  28. if ok {
  29. if automodeOfPjVehicleFdbPub.(int16) == 1 {
  30. if data.VelocityX < 0.5 {
  31. // 如果之前没有记录开始时间,记录当前时间
  32. if StartTime == 0 {
  33. StartTime = time.Now().Unix()
  34. }
  35. // 判断是否持续超过 50s
  36. if time.Now().Unix()-StartTime > 50 && OutsideWorkshopFlag == true {
  37. if !IsStopped {
  38. IsStopped = true
  39. return Label()
  40. }
  41. }
  42. } else {
  43. // 如果速度大于 0.1,重置开始时间和停止标志
  44. StartTime = 0
  45. IsStopped = false
  46. }
  47. } else {
  48. StartTime = 0
  49. IsStopped = false
  50. }
  51. }
  52. return ""
  53. }