package main

import (
	"cicv-data-closedloop/pjisuv_msgs"
	"fmt"
	"math"
	"sync"
)

/*
def callback_cicv_location(data):
    global angular_velocity_z
    global Ego_position_x
    global Ego_position_y
    global Ego_yaw


    Ego_position_x=data.position_x
    Ego_position_y=data.position_y
    Ego_yaw=data.yaw
    #print(Ego_yaw)
    angular_velocity_z=data.angular_velocity_z
    #print(angular_velocity_z)
    if abs(angular_velocity_z)>=27:
        event_label='overswing' #横摆角速度过大
        print(event_label)

*/

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

func Label() string {
	return "OverSwing"
}

func Rule(shareVars *sync.Map, data *pjisuv_msgs.PerceptionLocalization) string {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("Recovered from panic:", r)
		}
	}()
	automodeOfPjVehicleFdbPub, ok := shareVars.Load("AutomodeOfPjVehicleFdbPub")
	OutsideWorkshopFlag, ok1 := shareVars.Load("OutsideWorkshopFlag")
	OutsideWorkshopFlag = OutsideWorkshopFlag.(bool)
	if ok && ok1 {
		if math.Abs(data.AngularVelocityZ) >= 27.0 && automodeOfPjVehicleFdbPub.(int16) == 1 && OutsideWorkshopFlag == true {
			return Label()
		}
	}
	return ""
}