package main

import (
	"cicv-data-closedloop/common/entity"
	"cicv-data-closedloop/pjisuv_msgs"
	"math"
)

func Topic() string {
	return "/tpperception"
}

// Label todo 禁止存在下划线_
func Label() string {
	return "TTC"
}

func Rule(data *pjisuv_msgs.PerceptionObjects, param entity.ExtendParam) string {
	for _, obj := range data.Objs {
		if math.Abs(float64(obj.Y)) <= 2 && obj.X >= 8 {
			theta := DegreesToRadians(param.YawOfCicvLocation)
			vxrel := (float64(obj.Vxabs)-param.VelocityXOfCicvLocation)*math.Cos(theta) + (float64(obj.Vyabs)-param.VelocityYOfCicvLocation)*math.Sin(theta)
			ttc := -((float64(obj.X) - 5.2) / (vxrel + 0.001))
			//fmt.Println("TTC值为:", ttc)
			if ttc >= 0 && ttc <= 5 {
				return "TTC"
			}
		}
	}
	return ""
}

// DegreesToRadians 计算角度转弧度
func DegreesToRadians(degrees float64) float64 {
	return degrees * math.Pi / 180.0
}