-
Notifications
You must be signed in to change notification settings - Fork 0
/
pid_control.ino
47 lines (38 loc) · 1.15 KB
/
pid_control.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*double err_p, err_i, err_d, err_last = 0;*/
/*unsigned long lastTick;*/
/*int desired;*/
/*unsigned int current;*/
/*bool drive_vel, drive_position;*/
/*unsigned long last_time;*/
/*const double k_p = 0.8;*/
/*const double k_i = 0.1;*/
/*const double k_d = 0.1;*/
/*void pidControl(int desired)*/
/*{*/
/*[>Serial.println("pid control loop");<] unsigned long time = millis(); unsigned long timestep = time-last_time;*/
/*current = getEncoderPos();*/
/*err_p = desired - current;*/
/*err_i += err_p;*/
/*err_d += (err_p-err_last)/timestep;*/
/*Serial.print("pos: ");*/
/*Serial.print(current);*/
/*Serial.print(" err_p: ");*/
/*Serial.print(err_p);*/
/*Serial.print(" err_i: ");*/
/*Serial.print(err_i);*/
/*Serial.print(" err_d: ");*/
/*Serial.print(err_d);*/
/*Serial.print(" pid output: ");*/
/*double output = err_p*k_p+err_i*k_i+err_d*k_d;*/
/*Serial.println(output);*/
/*[>Serial.print(" pid target: ");<]*/
/*[>Serial.println(desired);<]*/
/*[>dcMotorControl((int)output, CLOCKWISE);<]*/
/*err_last = err_p;*/
/*last_time = time;*/
/*[>return output;<]*/
/*}*/
/*void setDesiredPosition(int desired_pos)*/
/*{*/
/*desired = getEncoderPos()+desired_pos;*/
/*}*/