scale_radio=(delta_us-RADIO_LEFT)*100/(RADIO_RANGE);//scale the recieved radio to a value between 0-100
}
go_print=true;
}
...
...
@@ -141,11 +158,11 @@ void serialEvent2()
}
else//chain all the bytes to have the number that indicates a position
{
recv=(recv<<8)+Serial2.read();
recv=(recv<<BYTE_CARRY_LEFT)+Serial2.read();
}
count++;
}
if(count==4)//when all 4 bytes of the message have been recieved, do the control
if(count==TOTAL_OF_MESSAGES)//when all 4 bytes of the message have been recieved, do the control
{
pos=recv;
count=0;
...
...
@@ -181,21 +198,21 @@ void serialEvent2()
intv=_kp*error_pos;//Control
if(v>=-1&&v<=1)//if the error is at 0 with a threshold, send stop to the motor
if(v>=-ERROR_CENTER_THRESHOLD&&v<=ERROR_CENTER_THRESHOLD)//if the error is at 0 with a threshold, send stop to the motor
{
speed_command=COMM_STOP;
}
elseif(v>=30)//if the error (-50,50) is more than "30" (value arbitrarily chosen) send the maximum speed, this is done to minimize the time of the mouvement
elseif(v>=MAX_ERROR_BEFORE_SPEED_IS_SET_TO_MAX)//if the error (-50,50) is more than "30" (value arbitrarily chosen) send the maximum speed, this is done to minimize the time of the mouvement
{
speed_command=COMM_FULL_FWD;
}
elseif(v<=-30)//if the error (-50,50) is less than "-30" (value arbitrarily chosen) send the maximum speed, this is done to minimize the time of the mouvement
elseif(v<=-MAX_ERROR_BEFORE_SPEED_IS_SET_TO_MAX)//if the error (-50,50) is less than "-30" (value arbitrarily chosen) send the maximum speed, this is done to minimize the time of the mouvement
{
speed_command=COMM_FULL_BCK;
}
else//Calculate the speed with this formula that transforms the error (-50,50) into the speed command (1,127)