123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package main
- import (
- "awesomeProject/entity"
- "awesomeProject/pjisuv_msgs"
- "fmt"
- "github.com/bluenviron/goroslib/v2"
- "os"
- "os/signal"
- "time"
- )
- var (
- param entity.PjisuvParam
- StartTime int64
- IsStopped bool
- )
- func CallbackCicvLocation(data *pjisuv_msgs.PerceptionLocalization) {
- //print(param.AutomodeOfPjVehicleFdbPub)
- if param.AutomodeOfPjVehicleFdbPub == 1 {
- if data.VelocityX < 0.5 {
- // 如果之前没有记录开始时间,记录当前时间
- if StartTime == 0 {
- StartTime = time.Now().Unix()
- }
- // 判断是否持续超过一分钟
- if time.Now().Unix()-StartTime > 10 {
- if !IsStopped {
- event_label := "AuLongStop"
- fmt.Println(event_label)
- IsStopped = true
- }
- }
- } else {
- // 如果速度大于 0.1,重置开始时间和停止标志
- StartTime = 0
- //is_stopped = false
- }
- }
- }
- func CallbackPjVehicleFdbPub(data *pjisuv_msgs.VehicleFdb) {
- param.AutomodeOfPjVehicleFdbPub = data.Automode
- }
- func main() {
- go listener()
- select {}
- //time.Sleep(10000)
- }
- func listener() {
- // create a node and connect to the master
- n, err := goroslib.NewNode(goroslib.NodeConf{
- Name: "goroslib_sub",
- MasterAddress: "127.0.0.1:11311",
- })
- if err != nil {
- panic(err)
- }
- defer n.Close()
- // create a subscriber
- subCicvLocation, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: n,
- Topic: "/cicv_location",
- Callback: CallbackCicvLocation,
- })
- if err != nil {
- panic(err)
- }
- defer subCicvLocation.Close()
- // create a subscriber
- subTpperception, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: n,
- Topic: "pj_vehicle_fdb_pub",
- Callback: CallbackPjVehicleFdbPub,
- })
- if err != nil {
- panic(err)
- }
- defer subTpperception.Close()
- // wait for CTRL-C
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
- <-c
- }
|