123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package main
- import (
- "cicv-data-closedloop/pjisuv_msgs"
- "fmt"
- "math"
- )
- func Topic() string {
- return "/tpperception"
- }
- // Label todo 禁止存在下划线_
- // MultiPedestrianAhead
- // MultiCarAhead
- // MultiTruckAhead
- // MultiBicycleAhead
- // MultiTricycleAhead
- // MultiTrafficConeAhead
- func Label() string {
- return "MultiPedestrianAhead"
- }
- type Record struct {
- StableFrame int
- LastExistingTime float64
- }
- var record *Record = nil
- // typeCheck 目标物类型检测
- // × 金龙车:CAR_TYPE=0, TRUCK_TYPE=1, PEDESTRIAN_TYPE=2, CYCLIST_TYPE=3, UNKNOWN_TYPE=4, UNKNOWN_MOVABLE_TYPE=5, UNKNOWN_UNMOVABLE_TYPE=6
- // √ 多功能车:UNKNOWN TYPE=O, PEDESTRIAN TYPE=1, CAR TYPE=2, TRUCK TYPE=3, Bicycle TYPE=4, Tricycle TYPE=5, Traffic Cone TYPE=6
- func typeCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- const targetType uint8 = 1
- return targetType == obj.Type
- }
- // posCheck 判断目标物位置关系
- func posCheck(obj *pjisuv_msgs.PerceptionObject) bool {
- const laneWidth = 3.5 // m
- return obj.X > 0 && math.Abs(float64(obj.Y)) < laneWidth*1.5
- }
- // Rule 检测前方指定目标物数量
- func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from panic:", r)
- }
- }()
- const Cgcs2000X = 456256.260152
- const Cgcs2000Y = 4397809.886833
- const MinStableFrameCount = 5 // frame
- const MaxTimeBetweenFrame = 0.5 // second
- const minTargetNum = 4
- if len(msg.Objs) >= minTargetNum {
- currTargetNum := 0
- for _, obj := range msg.Objs {
- // 判断目标物是否满足筛选条件
- if typeCheck(&obj) && posCheck(&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 ""
- }
|