Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Encoder HIDScope mbed
Fork of Aansturing_knoppen by
controller.h@0:55f9447aa02b, 2016-10-26 (annotated)
- Committer:
- wikdehaas
- Date:
- Wed Oct 26 10:33:14 2016 +0000
- Revision:
- 0:55f9447aa02b
Aansturing;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wikdehaas | 0:55f9447aa02b | 1 | void controller_1() |
| wikdehaas | 0:55f9447aa02b | 2 | { |
| wikdehaas | 0:55f9447aa02b | 3 | double theta_1 = acos((sqrt(pow(x,2)+pow(yc,2))/(2*L2))+asin(yc/(sqrt(pow(x,2)+pow(yc,2)))); |
| wikdehaas | 0:55f9447aa02b | 4 | double theta_2 = acos((x/L2)-cos(theta_1)); |
| wikdehaas | 0:55f9447aa02b | 5 | |
| wikdehaas | 0:55f9447aa02b | 6 | double reference_1 = theta_1; //reference |
| wikdehaas | 0:55f9447aa02b | 7 | double plaats_1 = 0.0014959*encoder_1.getPosition(); //positie encodercounts naar hoek |
| wikdehaas | 0:55f9447aa02b | 8 | double error_1 = reference_1 - plaats_1 ; |
| wikdehaas | 0:55f9447aa02b | 9 | double pwm_1 = PID(error_1, m1_Kp, m1_Ki, m1_Kd, m1_Ts, m1_N, m1_v1, m1_v2 ); |
| wikdehaas | 0:55f9447aa02b | 10 | if (pwm_1<0){motor_1 = 1;} |
| wikdehaas | 0:55f9447aa02b | 11 | else {motor_1 = 0;} |
| wikdehaas | 0:55f9447aa02b | 12 | pwm_motor_1 = fabs(pwm_1); |
| wikdehaas | 0:55f9447aa02b | 13 | |
| wikdehaas | 0:55f9447aa02b | 14 | double reference_2 = theta_2; //reference |
| wikdehaas | 0:55f9447aa02b | 15 | double plaats_2 = 0.0014959*encoder_2.getPosition(); //positie encodercounts naar hoek |
| wikdehaas | 0:55f9447aa02b | 16 | double error_2 = reference_2 - plaats_2 ; |
| wikdehaas | 0:55f9447aa02b | 17 | double pwm_2 = PID(error_2, m2_Kp, m2_Ki, m2_Kd, m2_Ts, m2_N, m2_v1, m2_v2 ); |
| wikdehaas | 0:55f9447aa02b | 18 | if (pwm_2<0){motor_2 = 0;} |
| wikdehaas | 0:55f9447aa02b | 19 | else {motor_2 = 1;} |
| wikdehaas | 0:55f9447aa02b | 20 | pwm_motor_2 = fabs(pwm_2); |
| wikdehaas | 0:55f9447aa02b | 21 | } |
