speed measure routine
This commit is contained in:
parent
c9ae41802b
commit
5db2e22563
3 changed files with 55 additions and 16 deletions
|
@ -19,6 +19,8 @@ typedef struct {
|
|||
double kd;
|
||||
int max_speed;
|
||||
int min_speed;
|
||||
double max_esc_out;
|
||||
double min_esc_out
|
||||
}PIDStruct;
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -102,9 +102,16 @@ const uint8_t HALL8_PIN = 14;
|
|||
|
||||
const uint8_t TIME_PER_ROUND_VALS = 10;
|
||||
|
||||
const uint16_t MIN_SPEED = 500;
|
||||
const uint16_t MAX_SPEED = 5000;
|
||||
const uint8_t MAX_ESC_SPEED = 100;
|
||||
const uint8_t MIN_ESC_SPEED = 6;
|
||||
//const uint16_t MIN_SPEED = 500;
|
||||
//const uint16_t MAX_SPEED = 5000;
|
||||
const uint8_t MAX_ESC_OUT = 100;
|
||||
const uint8_t MIN_ESC_OUT = 0;
|
||||
|
||||
const long MAX_D_VALUE = 10;
|
||||
const long MIN_D_VALUE = -10;
|
||||
const long MAX_I_VALUE = 10;
|
||||
const long MIN_I_VALUE = -10;
|
||||
const long MAX_P_VALUE = 10;
|
||||
const long MIN_P_VALUE = -10;
|
||||
|
||||
#endif //MAIN_HPP
|
|
@ -119,6 +119,34 @@ void loop()
|
|||
|
||||
}
|
||||
|
||||
void eval_max_min_speed()
|
||||
{
|
||||
Pid_params.min_esc_out = 0;
|
||||
Pid_params.min_speed = 0;
|
||||
for(uint8_t out = Pid_params.min_speed; out < Pid_params.max_esc_out; out++)
|
||||
{
|
||||
ESC.write(out);
|
||||
delay(1000);
|
||||
for(uint8_t i=0;i<10;i++)
|
||||
{
|
||||
data_check();
|
||||
delay(1000);
|
||||
|
||||
if (0 == Pid_params.min_speed && HallData[0].value > 0)
|
||||
{
|
||||
Pid_params.min_speed = HallData[0].value;
|
||||
Pid_params.min_esc_out = out
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ESC.write(Pid_params.max_esc_out);
|
||||
delay(2000);
|
||||
Pid_params.max_speed = HallData[0].value;
|
||||
ESC.write(0);
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void count_secs(time_t* run_time)
|
||||
{
|
||||
static time_t last_update_ms = 0;
|
||||
|
@ -151,13 +179,13 @@ void PID()
|
|||
double int_derivative = Pid_params.err - last_error;
|
||||
if(Pid_params.ki != 0)
|
||||
{
|
||||
if(Pid_params.ki*int_integ > MAX_ESC_SPEED)
|
||||
if(Pid_params.ki*int_integ > MAX_I_VALUE)
|
||||
{
|
||||
Pid_params.integ = MAX_ESC_SPEED/Pid_params.ki;
|
||||
Pid_params.integ = MAX_I_VALUE/Pid_params.ki;
|
||||
}
|
||||
else if(Pid_params.ki*int_integ < -1*MAX_ESC_SPEED)
|
||||
else if(Pid_params.ki*int_integ < MIN_I_VALUE)
|
||||
{
|
||||
Pid_params.integ = -1*MAX_ESC_SPEED/Pid_params.ki;
|
||||
Pid_params.integ = MIN_I_VALUE/Pid_params.ki;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -171,13 +199,13 @@ void PID()
|
|||
|
||||
if(Pid_params.kd != 0)
|
||||
{
|
||||
if(Pid_params.kd*int_derivative > MAX_ESC_SPEED)
|
||||
if(Pid_params.kd*int_derivative > MAX_D_VALUE)
|
||||
{
|
||||
Pid_params.derivative = MAX_ESC_SPEED/Pid_params.kd;
|
||||
Pid_params.derivative = MAX_D_VALUE/Pid_params.kd;
|
||||
}
|
||||
else if(Pid_params.kd*int_derivative < -1*MAX_ESC_SPEED)
|
||||
else if(Pid_params.kd*int_derivative < MIN_D_VALUE)
|
||||
{
|
||||
Pid_params.derivative = -1*MAX_ESC_SPEED/Pid_params.kd;
|
||||
Pid_params.derivative = MIN_D_VALUE/Pid_params.kd;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -280,11 +308,13 @@ void data_init()
|
|||
Pid_params.current_speed = 0.0;
|
||||
Pid_params.err = 0;
|
||||
Pid_params.output = 0.0;
|
||||
Pid_params.kp = 0.002;
|
||||
Pid_params.ki = 0.0008;
|
||||
Pid_params.kp = 0.001;
|
||||
Pid_params.ki = 0.001;
|
||||
Pid_params.kd = 0.001;
|
||||
Pid_params.max_speed = MAX_SPEED;
|
||||
Pid_params.min_speed = MIN_SPEED;
|
||||
Pid_params.max_speed = 5000;
|
||||
Pid_params.min_speed = 0;
|
||||
Pid_params.max_esc_out = MAX_ESC_OUT;
|
||||
Pid_params.min_esc_out = MIN_ESC_OUT;
|
||||
#ifdef MACHINE_RESTART
|
||||
run_time = 0;
|
||||
start_time = capportal.epochTime();
|
||||
|
|
Loading…
Add table
Reference in a new issue