123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package main
- import (
- "cicv-data-closedloop/pjisuv_msgs"
- "fmt"
- "math"
- "sync"
- )
- func Topic() string {
- return "/tpperception"
- }
- func Label() string {
- return "MultiTrafficConeAhead"
- }
- type Record struct {
- StableFrame int
- LastExistingTime float64
- }
- var record *Record = nil
- func objTypeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- const targetType uint8 = 6
- return targetType == obj.Type
- }
- func objPosCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- const laneWidth = 3.5
- return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
- }
- func isEgoStationary(shareVars *sync.Map) bool {
- const minSpeed = 1
- VelocityXOfCicvLocation, _ := shareVars.Load("VelocityXOfCicvLocation")
- VelocityYOfCicvLocation, _ := shareVars.Load("VelocityYOfCicvLocation")
- speed := math.Sqrt(math.Pow(VelocityXOfCicvLocation.(float64), 2) + math.Pow(VelocityYOfCicvLocation.(float64), 2))
- return speed > minSpeed
- }
- func Rule(shareVars *sync.Map, msg *pjisuv_msgs.PerceptionObjects) string {
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from panic:", r)
- }
- }()
- outsideWorkshopFlag, _ := shareVars.Load("OutsideWorkshopFlag")
- if !outsideWorkshopFlag.(bool) || !isEgoStationary(shareVars) {
- return ""
- }
-
-
- const MinStableFrameCount = 5
- const MaxTimeBetweenFrame = 0.5
- const minTargetNum = 3
- if len(msg.Objs) >= minTargetNum {
- currTargetNum := 0
-
- for _, obj := range msg.Objs {
-
- if objTypeCheck(&obj) && objPosCheck(&obj) {
-
-
- currTargetNum++
- }
- }
- if currTargetNum >= minTargetNum {
- if nil == record {
- record = &Record{
- StableFrame: 1,
- LastExistingTime: msg.Header.TimeStamp,
- }
-
- } else {
- newRecord := Record{
- StableFrame: 1,
- LastExistingTime: msg.Header.TimeStamp,
- }
- if newRecord.LastExistingTime-record.LastExistingTime <= MaxTimeBetweenFrame {
- newRecord.StableFrame = record.StableFrame + 1
- if newRecord.StableFrame == MinStableFrameCount {
- record = nil
-
- return Label()
- } else {
-
- }
- } else {
-
- }
- record = &newRecord
- }
- }
- }
- return ""
- }
|