#define SENDPERIOD 20 //ms. delay for sending speed and steer data to motor controller via serial
#define FEEDBACKRECEIVETIMEOUT 500
// Global variables for serial communication
typedefstruct{
uint8_tidx=0;// Index for new data pointer
uint16_tbufStartFrame;// Buffer Start Frame
byte*p;// Pointer declaration for the new received data
byteincomingByte;
byteincomingBytePrev;
longlastValidDataSerial_time;
}SerialRead;
typedefstruct{
uint16_tstart;
int16_tspeedLeft;
int16_tspeedRight;
uint16_tchecksum;
}SerialCommand;
typedefstruct{//match this struct to hoverboard-firmware SerialFeedback struct in main.c
uint16_tstart;
int16_tcmd1;
int16_tcmd2;
int16_tspeedL_meas;//left speed is positive when driving forward
int16_tspeedR_meas;//right speed is negatie when driving forward
int16_tbatVoltage;
int16_tboardTemp;
int16_tcurL_DC;//negative values are current consumed. positive values mean generated current
int16_tcurR_DC;
uint16_tcmdLed;
uint16_tchecksum;
}SerialFeedback;
#define CURRENT_FILTER_SIZE 60 //latency is about CURRENT_FILTER_SIZE/2*MEASURE_INTERVAL (measure interval is defined by hoverboard controller)
#define CURRENT_MEANVALUECOUNT 20 //0<= meanvaluecount < CURRENT_FILTER_SIZE/2. how many values will be used from sorted weight array from the center region. abour double this values reading are used
typedefstruct{
int16_tcurL_DC[CURRENT_FILTER_SIZE]={0};//current will be inverted for this so positive value means consumed current
int16_tcurR_DC[CURRENT_FILTER_SIZE]={0};
uint8_tcur_pos=0;
int16_tcmdL=0;
int16_tcmdR=0;
floatfiltered_curL=0;
floatfiltered_curR=0;
unsignedlongmillis=0;//time when last message received