#ifndef _driver_h
#define _driver_h
#include "zf_common_headfile.h"






#define left_zhizi_0 			 20
#define left_zhizi_1             80
#define left_zhizi_2             134
#define left_zhizi_3             199
#define left_zhizi_4             264

#define left_huandao_0 0	
#define left_huandao_1 90 
#define left_huandao_2 150
#define left_huandao_3 210
#define left_huandao_4 270


//环岛内切角度
#define nei_qie_angle_huandao 31
//十字内切角度
#define nei_qie_angle_shizi 25
#define nei_qie_angle_shizi_H_E 15


//环岛移动距离
#define nei_qie_distance_huandao 1.7
#define nei_qie_distance_B  1.7
//十字移动距离
#define nei_qie_distance_shizi 1




//判断到环岛前进距离
#define huan_dao_qianjing_distance  3.6
//判断到十字前进距离
#define shi_zi_qianjing_distance    1.7

#define zhongdian_move 2


#define chu_yuansu_sudu 30
#define chu_yuansu_sudu_time 800

#define Sevor_1 (PWM1_MODULE3_CHB_D1)
#define Sevor_2 (PWM1_MODULE3_CHA_D0)
#define Sevor_3 (PWM4_MODULE2_CHA_C30)
#define Sevor_4 (PWM1_MODULE2_CHB_D17)


#define right_zhizi_0  0     //
#define right_zhizi_1 -80
#define right_zhizi_2 -140
#define right_zhizi_3 -190
#define right_zhizi_4 -245



#define right_huandao_0  0
#define right_huandao_1  left_huandao_4-360    //多了改小 少了改多
#define right_huandao_2  left_huandao_3-360
#define right_huandao_3  left_huandao_2-360
#define right_huandao_4  left_huandao_1-360

extern double coord_error[10];
extern int in_coord_flag;
extern double try_coord[12][2];
extern int16 duty_positive[4];
extern int16 duty_nagtive[4];
extern double duty_temp[4];
extern int16 duty[4];
extern double error_coord[2];
extern int16 sport_state;
extern int coord_state;
extern int err_flag;
extern int coord_num;
extern int find_pic;
extern float pic_er_now;
extern int error_clean;
extern double organ_coord[2];
extern double first_coord[2];
extern int16 car_flag;
extern double test_coord[2];
extern double target_coord[2];
extern double cap_coord[18][2];
extern int in_f;
extern int cap_state;
extern double cap_aim_angle;
extern double flash_coord[12][2];
extern double diss_coord[20][2];
extern int go_back;
extern int go_stright_flag;
extern int yellow_line[2];
extern int find_yellow_line;
extern uint8 warehousing_flag;
extern uint8 grab_stop;
extern uint8 gra;
extern uint8 transport_flag;
extern uint8 release_flag;
extern uint8 cap_line_flag;
extern uint8 target_flag;
extern uint8 left_boundary;
extern uint8 right_boundary;
extern uint8 labyrinth;
extern int classify_flag;
extern int find_object;
extern int arrive_object;


extern double encoder_pic_X;
extern double encoder_pic_y;
extern double encoder_pic_angle;
extern double coord_aim[2];
extern int num;
extern double roate_determine_angle;
extern int roate_determine_angle_flag;
extern int coord_now_flag;
extern int coord_now_flag_right;
extern int left_shizi_flag;//判断左十字进程
extern int right_shizi_flag;
extern int cross_flag_dir;
extern int left_huandao_flag;

extern int eiq_mode_left_flag;
extern int eiq_mode_right_flag;
extern int sevor_left_flag;
extern double num_qipao;
void sevor_set();
void driver_test(void);
void diss_error(void);

void get_error(double *coord_now,double *aim_coord);

void test_PID(void);

void move_coord();

void error_flash(double *aim);

void drive_car(void);

void driver(void);

void driver_photo(void);

void driver_test(void);

void test();

void driver_labyrinth(void);
void calculate_pic();
void moveToPosition(int current_pwm[4], int target_pwm[4], int step_size, int move_delay, int servos[4]) ;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void left_roate_determine();
void right_roate_determine();
void delay_zhongduan(int time) ;
void left_huandao_determine();
void right_huandao_determine();


void camera_determine(int i,int j);
void eiq_mode_determine(int i,int j);
void Zebra_determine();
void yi_yiduiying();
void transformArray(int A[], int B[], int startIdx, int endIdx, int sizeA) ;
int findMinCountElement(const int A[], const int B[], int sizeA, int startIdx, int endIdx);
void countElements(const int B[], int count[], int startIdx, int endIdx) ;

void shizi_test();
#endif