12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package main
- import (
- "awesomeProject/pjisuv_msgs"
- "fmt"
- "github.com/bluenviron/goroslib/v2"
- "math"
- "os"
- "os/signal"
- )
- var (
- PrePositionX float64 = 0
- PrePositionY float64 = 0
- //numbers = make([]float64, 0)
- )
- func CallbackCicvLocation(data *pjisuv_msgs.PerceptionLocalization) {
- if PrePositionX != 0 && PrePositionY != 0 {
- d := math.Sqrt((PrePositionX-data.PositionX)*(PrePositionX-data.PositionX) + (PrePositionY-data.PositionY)*(PrePositionY-data.PositionY))
- if d >= 2 {
- eventLabel := "LocationJump"
- fmt.Println(eventLabel)
- }
- //fmt.Println(d)
- //numbers = append(numbers, d)
- //sort.Float64s(numbers)
- //max := numbers[len(numbers)-1]
- //fmt.Println("最大值为:", max)
- }
- PrePositionX = data.PositionX
- PrePositionY = data.PositionY
- }
- 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()
- // wait for CTRL-C
- c := make(chan os.Signal, 1)
- //sort.Float64s(numbers)
- //max := numbers[len(numbers)-1]
- //fmt.Println("最大值为:", max)
- signal.Notify(c, os.Interrupt)
- <-c
- }
|