123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package test
- import (
- "cicv-data-closedloop/pjisuv_msgs"
- "fmt"
- "github.com/bluenviron/goroslib/v2"
- "log"
- "math"
- "testing"
- "time"
- )
- type Object struct {
- ID uint32
- StableAge int
- LastExistTime float64
- }
- var objectsStability = make(map[uint32]Object)
- func speedCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- var targetMinSpeed float32 = 2 / 3.6
- var targetMaxSpeed float32 = 20 / 3.6
- if targetMinSpeed < obj.Speed && obj.Speed < targetMaxSpeed {
- return true
- }
- return false
- }
- func typeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- var targetType uint8 = 3
- if targetType == obj.Type {
- return true
- }
- return false
- }
- func sizeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
-
- var targetMinLength float32 = 3.6
- var targetMinWidth float32 = 1.605
- var targetMinHeight float32 = 1.995
-
-
-
-
- if obj.Length > targetMinLength || obj.Width > targetMinWidth || obj.Height > targetMinHeight {
- return true
- }
- return false
- }
- func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- laneWidth := 3.5
- if obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5 {
- return true
- }
- return false
- }
- func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from panic:", r)
- }
- }()
- CGCS2000_X := 456256.260152
- CGCS2000_Y := 4397809.886833
- existingFrameThreshold := 5
- existingTimeThreshold := 0.5
-
-
-
-
-
-
-
-
-
-
-
-
-
- fmt.Println()
- fmt.Println(time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
- for _, obj := range msg.Objs {
-
-
-
- if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj) || sizeCheck(&obj)) {
-
- if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
- objectsStability[obj.Id] = Object{
- ID: obj.Id,
- StableAge: 1,
- LastExistTime: msg.Header.TimeStamp,
- }
- fmt.Println("create: ", objectsStability[obj.Id])
- } else {
- currObjRecord := Object{
- ID: obj.Id,
- StableAge: 1,
- LastExistTime: msg.Header.TimeStamp,
- }
-
- if currObjRecord.LastExistTime-prevObjRecord.LastExistTime <= existingTimeThreshold {
- currObjRecord.StableAge = prevObjRecord.StableAge + 1
- if existingFrameThreshold == currObjRecord.StableAge {
- fmt.Println("found: ", currObjRecord)
- fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
- obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-CGCS2000_X, obj.Yabs-CGCS2000_Y, obj.Speed, obj.Length, obj.Width, obj.Height))
- delete(objectsStability, obj.Id)
- continue
-
- } else {
- }
- } else {
- fmt.Println("reset: ", currObjRecord)
- }
- objectsStability[obj.Id] = currObjRecord
- fmt.Println("update: ", currObjRecord)
- }
- }
- }
- return ""
- }
- func TestGoRosLib(t *testing.T) {
- defer func() {
- if err := recover(); err != nil {
- log.Println(err, fmt.Sprintf("recover: [%#v]", err), false)
- }
- }()
- rosNode, err := goroslib.NewNode(goroslib.NodeConf{
- Name: "eyTest",
- MasterAddress: "localhost:11311",
- })
- if err != nil {
- log.Panicln(err, fmt.Sprintf("failed to create rosNode: [%#v]", err), false)
- }
- _, err = goroslib.NewSubscriber(goroslib.SubscriberConf{
- Node: rosNode,
- Topic: "/tpperception",
- Callback: func(msg *pjisuv_msgs.PerceptionObjects) {
- Rule(msg)
- },
- })
- if err != nil {
- log.Panicln(err, fmt.Sprintf("failed to create subscriber: [%#v]", err), false)
- }
- select {}
- }
|