123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package test
- import (
- "cicv-data-closedloop/pjisuv_msgs"
- "fmt"
- "github.com/bluenviron/goroslib/v2"
- "log"
- "math"
- "testing"
- "time"
- )
- 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
- fmt.Println()
- fmt.Println(time.Unix(int64(msg.Header.TimeStamp), 0).Format(time.DateTime))
- for _, obj := range msg.Objs {
- 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))
-
- if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj) || sizeCheck(&obj)) {
- fmt.Println("!!!")
-
- }
- }
- 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 {}
- }
|