AuLongStop.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. if ok {
  27. if automodeOfPjVehicleFdbPub.(int16) == 1 {
  28. if data.VelocityX < 0.5 {
  29. // 如果之前没有记录开始时间,记录当前时间
  30. if StartTime == 0 {
  31. StartTime = time.Now().Unix()
  32. }
  33. // 判断是否持续超过 50s
  34. if time.Now().Unix()-StartTime > 50 {
  35. if !IsStopped {
  36. IsStopped = true
  37. return Label()
  38. }
  39. }
  40. } else {
  41. // 如果速度大于 0.1,重置开始时间和停止标志
  42. StartTime = 0
  43. IsStopped = false
  44. }
  45. } else {
  46. StartTime = 0
  47. IsStopped = false
  48. }
  49. }
  50. return ""
  51. }