#ifndef _DATA_H_
#define _DATA_H_

/* ɿͷļ */
#include "zf_common_headfile.h"
#include "zf_common_debug.h"
#include "isr.h"

/* DOGͷļ */
#include "DOG_motor.h"
#include "DOG_data.h"
#include "DOG_vofa.h"
#include "DOG_sensor.h"
#include "DOG_solve.h"
#include "DOG_cv.h"
#include "DOG_path.h"
#include "DOG_filter.h"
#include "DOG_pid.h"
#include "DOG_menu.h"
#include "DOG_timer.h"
#include "DOG_data.h"

/* ûͷļ */
#include "common.h"

/* öٶ */
/*  */
/* ״̬ */
typedef enum _path_state_{
	common_path = 0,			// ͨ
	L_circle_in = 1,			// Բ
	R_circle_in = 2,			// Բ
	L_circle = 3,				// Բ
	R_circle = 4,				// Բ
	L_circle_out = 5,			// Բ
	R_circle_out = 6,			// Բ
	zebra_path = 7,				// 
	box_first_track = 8,		// һζλ
	box_calibration = 9,		// ӽ
	box_inv_calibration = 10,	// 
	box_second_track = 11,		// Ӷζλ
	box_fxxk = 12,				// 
	path_back = 13,				// 
}_path_state_;

typedef enum _control_kind_{
	Angle2Inv2Speed = 0,		// ǶȻ->˶ѧ->ٶȻ
	CircleAngle2Inv2Speed = 1,	// ԲǶȻ->˶ѧ->ٶȻ
	Track_X2Inv2Speed = 2,		// ӶλX->˶ѧ->ٶȻ
	Track_Y2Inv2Speed = 3,		// ӶλY->˶ѧ->ٶȻ
	Track_XY2Inv2Speed = 4,		// ӶλXY->˶ѧ->ٶȻ
	Fxxk_X2Inv2Speed = 5,		// X->˶ѧ->ٶȻ
	Inv2Speed = 6,				// ˶ѧ->ٶȻ
	Speed = 7,					// ٶȻ
	PWM = 8,					// PWM
	Stop = 9,					// ͣ
}_control_kind_;

/* AIͷ */
typedef enum _ai_camera_idx_{
	AI_CAMERA_0 = 0,		// AIͷ0
	AI_CAMERA_1 = 1,		// AIͷ1
	AI_CAMERA_2 = 2,		// AIͷ2
}_ai_camera_idx_;		

/* AIͷʶǩ */
typedef enum _ai_lable_{
	wrench = 0x01,				// 			
	soldering_iron = 0x02,		// 		
	electrodrill = 0x03,		// 			
	tape_measure = 0x04,		// ׳			
	screwdriver = 0x05,			// ˿		
	pliers = 0x06,				// ǯ			
	oscillograph = 0x07,		// ʾ		
	multimeter = 0x08,			// ñ		
	printer = 0x09,				// ӡ		
	keyboard = 0x0A,			// 			
	mobilephone = 0x0B,			// ֻ			
	mouse = 0x0C,				// 			
	headphones = 0X0D,			// 			
	monitor = 0X0E,				// ʾ		
	speaker = 0X0F,				// 			
	other = 0X10,				// ֣	
}_ai_lable_;

/* ṹ嶨 */
typedef struct _ai_camera_detection_result_{
	_bool_ ai_camera_init_flag[2];		// AIͷʼɱ־λ
	_bool_ tool_detection_finsh_flag;	// ʶɱ־λ
	_bool_ num_detection_finsh_flag;	// ʶɱ־λ
	uint8 tool_raw;		// ʶԭʼֵ
	uint8 num_raw;		// ʶԭʼֵ
	_ai_lable_ tool;	// ʶ
	uint8 num;			// ʶ
	/*
		ʶźź󣬵ȴʶɣ־λTrue,в󣬱־λFalse
		ֻе־λΪTrueʱŽӲ
	*/
}_ai_camera_detection_result_;

/* ඨ */
extern DOG_MOTOR motor_1;						// 1
extern DOG_MOTOR motor_2;						// 2
extern DOG_MOTOR motor_3;						// 3
extern DOG_ENCODER encoder_1;					// 1
extern DOG_ENCODER encoder_2;					// 2
extern DOG_ENCODER encoder_3;					// 3
extern DOG_CURRENT current_1;					// 1
extern DOG_CURRENT current_2;					// 2
extern DOG_CURRENT current_3;					// 3
extern DOG_VOLTAGE gray_sensor;					// Ҷȴ
extern DOG_VOLTAGE bat_voltage;					// صѹ
extern DOG_KARMAN_FILTER current_1_karman;		// 1 ˲ 
extern DOG_KARMAN_FILTER current_2_karman;		// 2 ˲ 
extern DOG_KARMAN_FILTER current_3_karman;		// 3 ˲ 
extern DOG_KARMAN_FILTER path_gyro_karman;		// · ˲ 
extern DOG_KARMAN_FILTER box_center_x_karman;	// еX ˲ 
extern DOG_KARMAN_FILTER box_width_karman;		// ӿ ˲ 
extern DOG_KARMAN_FILTER displacement_solve_gyro_karman;	// λƽ ˲
extern DOG_PID motor_1_pid;						// PID1
extern DOG_PID motor_2_pid;						// PID2
extern DOG_PID motor_3_pid;						// PID3
extern DOG_PID current_1_pid;					// PID1
extern DOG_PID current_2_pid;					// PID2
extern DOG_PID current_3_pid;					// PID3
extern DOG_PID path_pid;						// ·PID
extern DOG_PID path_gyroz_pid;					// ·PID
extern DOG_PID angle_rotate_pid;				// ǶȻתPID
extern DOG_PID circle_rotate_pid;				// ԲתPID
extern DOG_PID box_track_x_pid;					// ӶλX PID
extern DOG_PID box_fxxk_x_pid;					// X PID
extern DOG_PID box_track_y_pid;					// ӶλY PID
extern DOG_VOFA wireless_vofa;					// ߴVOFA
extern DOG_IMU imu660ra;						// IMU660RA
extern DOG_SOLVE euler_angle_solve;				// ŷǽ
extern DOG_SOLVE rotate_euler_angle_solve;		// תŷǽ
extern DOG_SOLVE circle_euler_angle_solve;		// Բŷǽ
extern DOG_SOLVE box_euler_angle_solve;			// ŷǽ
extern DOG_SOLVE chassis_solve;					// ̽
extern DOG_SOLVE displacement_solve;			// λƽ
extern DOG_TIMER zebra_path_timer;				// ߼ʱ
extern DOG_TIMER motor_debug_timer;         	// Լʱ
extern DOG_TIMER rwr_timer;						// RWRʱ
extern DOG_CV dog_cv;							// Ӿ
extern DOG_PATH dog_path;						// ѭ
extern DOG_RWR dog_rwr;							// RWR

/* ʹܱ־λ */
extern _bool_ circle_enable_flag;			// Բ ʹܱ־λ
extern _bool_ zebra_enable_flag;			//  ʹܱ־λ
extern _bool_ ai_camera_0_enable_flag;		// AI0 ʹܱ־λ
extern _bool_ ai_camera_1_enable_flag;		// AI1 ʹܱ־λ
extern _bool_ ai_camera_2_enable_flag;		// AI2 ʹܱ־λ
extern uint8 supplement_lamp_enable_flag;	//  ʹܱ־λ

/* ɱ־λ */
extern _bool_ angle_rotate_finsh_flag;	// ǶȻתɱ־λ
extern _bool_ circle_rotate_finsh_flag;	// Բתɱ־λ
extern _bool_ box_X_finsh_flag;			// Xλɱ־λ
extern _bool_ box_Y_finsh_flag;			// Yλɱ־λ
extern _bool_ box_XY_finsh_flag;		// XYλɱ־λ

/* ͨ־λ */
extern _bool_ out_last_box_circle_flag;	// һԲڱ־λ

/* ʼ־λ */
extern _bool_ ai_camera_0_init_flag;					// AIͷ0 ʼ־λ

/* ȫֱ */
/* ͷ */
extern uint16 exp_time;					//ͷعʱ
/* ȡ */
extern int16 path_err;					// ·
extern uint16 path_start;				// ·ʼ߶
extern uint16 path_end;					// ·߽߶
extern uint16 side_extract_start_y;		// ȡʼ߶
extern uint16 side_extract_end_y;		// ȡ߶
extern uint16 prediction_point;			// Ԥ߶ȣ꽫Ϊһ֡
extern uint16 control_point[4];			// Ƶ߶ȣ0лٿƵ㣻1/2Ƶ/ԶƵ㣻3·ȡƵ㣩
extern uint16 longest_white_control_point;	// пƵ
/* Բ */
extern uint16 circle_check_y;			// Բ߸߶
extern uint16 side_x_delta_range[2];	// XֵֵΧ
extern float circle_in_distance;		// Բʼ·
extern float circle_out_distance;		// Բʼ·
extern float circle_in_distance_limit ;	// Բʼ·ֵ·̴ڸֵܳ
extern float circle_out_distance_limit;	// Բʼ·ֵ·̴ڸֵܽ
/*  */
extern uint16 zebra_check_y;			// ߼߸߶
extern uint16 zebra_stop_distance;  	// ͣ
/*  */
extern _path_state_ path_state;			// ״̬
extern _path_state_ last_path_state;	// һ״̬
/*  */
extern _control_kind_ control_kind;					// 
extern float wheel_speed_target[3];					// Ŀٶ
extern float motor_current_target[3];				// Ŀֵ
extern float motor_pwm_duty[3];		       			// PWMռձ
extern _move_solve_kind_ move_solve_kind;			// ˶
extern float linear_speed_target;					// Ŀٶ
extern float translation_yaw_target;				// ĿƽǶ
extern float x_speed_target;						// Ŀxٶ
extern float y_speed_target;						// Ŀyٶ
extern float angular_speed_target;					// Ŀתٶ
extern float angle_rotation_yaw_target;				// ĿǶȻתǶ
extern float circle_rotation_yaw_target;			// ĿԲתǶ
extern float data_1;								// ˶ѧ1ٶ/Xٶȣ
extern float data_2;								// ˶ѧ2/Yٶȣ
extern float x_speed_rate;							// ѭxٶȱĿѭxٶ/Ŀѭתٶȣ
extern uint16 auto_control_point_normalize_range[2];	// ̬ǰհһΧ
/*  */
extern int16 detection_center_err;						// ʶ
extern uint8 detection_box_width;						// ʶ
extern uint8 detection_box_width_limit;					// ʶֵڴֵſԽ׷ģʽ
extern uint8 detection_box_width_target;				// ʶĿ
extern uint8 detection_box_height;						// ʶ߶ȶ
extern uint8 detection_box_height_limit;				// ʶ߶ֵڴֵſԽ׷ģʽ
extern int16 detection_box_center_x;					// ʶĺ
extern uint16 detection_box_center_x_limit;				// ʶĺֵֵΧڲſԽ׷ģʽ
extern uint8 box_y_track_enable_center_x_limit;			// Yλʹܵĺֵ
extern _ai_camera_detection_result_ detection_result;	// ʶ
extern _ai_camera_detection_result_ detection_result_list[BOX_NUM_MAX];	// ʶб
extern uint8 detection_result_num;						// ʶб
extern uint16 rectificate_weight[4];					// ȨأߡMT9V03X_W/8 ߡ2*MT9V03X_W/8 ߡ3*MT9V03X_W/8 ߡ4*MT9V03X_W/8
extern uint32 sum_weight;								// Ȩ
extern uint16 symmetry_rectificate_start_y;				// ԳƷͼʼ߶
extern uint16 symmetry_rectificate_end_y;				// ԳƷͼ߶
extern float sum_weight_normalization;					// Ȩ͹һ	
extern float sum_weight_normalization_limit[2];			// Ȩ͹һֵ
extern float frame_white_num_normalization[2];			// ԳƷͼұ߿׵һ
extern float frame_white_num_normalization_limit;		// ԳƷͼұ߿׵һֵ
extern uint16 frame_offset;								// ͼ߿ƫƫҿƫֹʳ޷ʹöԳƷн 
extern float last_box_world_x[BOX_NUM_MAX];				// һʼX
extern float last_box_world_y[BOX_NUM_MAX];				// һʼY
extern uint8 box_num;									// Ѿƹ
extern float box_distance;								// Ӽ
/* ٶ/Ƕ/ʱ */
extern uint8 plan_idx;								// ɵߣٶ𽥱죩	
extern float path_y_speed_target[4];				// ĿѭYٶ
extern float circle_y_speed_target[4];				// ĿԲYٶ
extern float path_x_speed_enable_y_speed_rate;		// ĿѭYٶȱʵʱĿٶ/Ŀٶ ڸñſXٶȣ
extern float circle_x_speed_enable_y_speed_rate;	// ĿԲYٶȱʵʱĿٶ/Ŀٶ ڸñſXٶȣ
extern float circle_angular_speed_target[4];			// 뻷Ŀٶ
extern float circle_angle_target[2];				// 뻷ĿתǶ
extern float box_x_speed_target;					// ĿXٶ
extern float box_x_angular_speed_rate;				//  תٶ/Xٶ 
extern float box_fxxk_y_speed_target[4];			// YٶĿֵ

/* PID */
// 
#ifdef FUZZY_SPEED_AND_CURRENT
extern float MOTOR_RANGE[3];
extern float MOTOR_PID[4][5];
#else
extern float MOTOR_1_PID[5];
extern float MOTOR_2_PID[5];
extern float MOTOR_3_PID[5];
#endif
// 
extern float I_1_PID[5];
extern float I_2_PID[5];
extern float I_3_PID[5];
// ѭ
extern float PATH_RANGE[2][3];
extern float GYRO_RANGE[2][3];
extern float PATH_PID[4][4][6];
// ת
extern float ROTATE_RANGE[3];
extern float ROTATE_PID[4][5];						  
// BOX Xλ
extern float BOX_TRACK_X_RANGE[3];	
extern float BOX_TRACK_X_PID[4][5];		
// BOX X 룩
extern float BOX_FXXK_X_PID[4][5];		
// BOX Yλ
extern float BOX_TRACK_Y_RANGE[3];		
extern float BOX_TRACK_Y_PID[4][5];

/* KARMAN˲ */
extern float I_KARMAN[2];
extern float PATH_GYRO_KARMAN[2];
extern float BOX_CENTER_X_KARMAN[2];
extern float BOX_WIDTH_KARMAN[2];


/* ģPID  */
extern _fuzzy_subset_ motor_fuzzy_rules[8][8];
extern _fuzzy_subset_ path_fuzzy_rules[8][8];
extern _fuzzy_subset_ gyro_fuzzy_rules[8][8];
extern _fuzzy_subset_ xy_fuzzy_rules[8][8];
extern _fuzzy_subset_ angle_rotate_fuzzy_rules[8][8];
extern _fuzzy_subset_ circle_rotate_fuzzy_rules[8][8];

/* ־λʼ */	
void flag_init(void);
/* ʼ */	
void variable_init(void);
/* ˵ɱȡ */
void menu_changea_parameter_read(void);
/* ˵ɱд */
void menu_changea_parameter_write(void);


#endif