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.
GainControl.cpp@0:8d7b6e55609a, 2015-03-24 (annotated)
- Committer:
- LanierUSNA16
- Date:
- Tue Mar 24 13:13:00 2015 +0000
- Revision:
- 0:8d7b6e55609a
- Child:
- 1:d4c2e72540db
Moving plus angle;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LanierUSNA16 | 0:8d7b6e55609a | 1 | #include "mbed.h" |
LanierUSNA16 | 0:8d7b6e55609a | 2 | #include "QEI.h" |
LanierUSNA16 | 0:8d7b6e55609a | 3 | |
LanierUSNA16 | 0:8d7b6e55609a | 4 | PwmOut turret_speed(p21); |
LanierUSNA16 | 0:8d7b6e55609a | 5 | DigitalOut turret_direction(p22); |
LanierUSNA16 | 0:8d7b6e55609a | 6 | |
LanierUSNA16 | 0:8d7b6e55609a | 7 | QEI myEncoder (p16,p15, NC, 1600); |
LanierUSNA16 | 0:8d7b6e55609a | 8 | Timer t; |
LanierUSNA16 | 0:8d7b6e55609a | 9 | |
LanierUSNA16 | 0:8d7b6e55609a | 10 | int main() |
LanierUSNA16 | 0:8d7b6e55609a | 11 | { |
LanierUSNA16 | 0:8d7b6e55609a | 12 | int input_dc =50; |
LanierUSNA16 | 0:8d7b6e55609a | 13 | int user_direction = 0; |
LanierUSNA16 | 0:8d7b6e55609a | 14 | float duty_cycle = 0.6; |
LanierUSNA16 | 0:8d7b6e55609a | 15 | int pulses = 0; |
LanierUSNA16 | 0:8d7b6e55609a | 16 | float theta = 0.0; |
LanierUSNA16 | 0:8d7b6e55609a | 17 | float time =0.0; |
LanierUSNA16 | 0:8d7b6e55609a | 18 | |
LanierUSNA16 | 0:8d7b6e55609a | 19 | while(1) |
LanierUSNA16 | 0:8d7b6e55609a | 20 | { |
LanierUSNA16 | 0:8d7b6e55609a | 21 | printf("Enter duty cycle, 0 to 100:\n"); |
LanierUSNA16 | 0:8d7b6e55609a | 22 | scanf("%d", &input_dc); |
LanierUSNA16 | 0:8d7b6e55609a | 23 | duty_cycle = input_dc/100.0; |
LanierUSNA16 | 0:8d7b6e55609a | 24 | |
LanierUSNA16 | 0:8d7b6e55609a | 25 | printf("%f duty cycle set. Enter 0 for CCW or 1 for CW spin direction:\n",duty_cycle); |
LanierUSNA16 | 0:8d7b6e55609a | 26 | scanf("%d", &user_direction); |
LanierUSNA16 | 0:8d7b6e55609a | 27 | |
LanierUSNA16 | 0:8d7b6e55609a | 28 | printf("it's starting... move the thing!\n"); |
LanierUSNA16 | 0:8d7b6e55609a | 29 | t.start(); |
LanierUSNA16 | 0:8d7b6e55609a | 30 | turret_speed = duty_cycle; |
LanierUSNA16 | 0:8d7b6e55609a | 31 | turret_direction = user_direction; |
LanierUSNA16 | 0:8d7b6e55609a | 32 | |
LanierUSNA16 | 0:8d7b6e55609a | 33 | pulses = myEncoder.getPulses(); |
LanierUSNA16 | 0:8d7b6e55609a | 34 | theta = ((float)pulses/ (1600.0*2.0))*-2.0*3.14; |
LanierUSNA16 | 0:8d7b6e55609a | 35 | time = t.read(); |
LanierUSNA16 | 0:8d7b6e55609a | 36 | |
LanierUSNA16 | 0:8d7b6e55609a | 37 | printf("time = %.5f;\n",time); |
LanierUSNA16 | 0:8d7b6e55609a | 38 | printf("theta = %.5f;\n",theta); |
LanierUSNA16 | 0:8d7b6e55609a | 39 | printf("%f duty cycle. %d spin.\n", duty_cycle, user_direction); |
LanierUSNA16 | 0:8d7b6e55609a | 40 | |
LanierUSNA16 | 0:8d7b6e55609a | 41 | } |
LanierUSNA16 | 0:8d7b6e55609a | 42 | } |