thijs ruikes
/
PROJECT-BATJEPOSTITIE
vor bas
main.cpp@0:b48b8c18b1bd, 2014-10-30 (annotated)
- Committer:
- wiesdat
- Date:
- Thu Oct 30 17:10:14 2014 +0000
- Revision:
- 0:b48b8c18b1bd
- Child:
- 1:d157905a98d1
BATJE positie, naar links en rechts bewegen, encoder op nul stellen en uitlezen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wiesdat | 0:b48b8c18b1bd | 1 | #include "mbed.h" |
wiesdat | 0:b48b8c18b1bd | 2 | #include "mbed.h" |
wiesdat | 0:b48b8c18b1bd | 3 | #include "encoder.h" |
wiesdat | 0:b48b8c18b1bd | 4 | #define K_P (0.1) |
wiesdat | 0:b48b8c18b1bd | 5 | #define K_I (0.1) |
wiesdat | 0:b48b8c18b1bd | 6 | #define K_D (0.0005 /TSAMP) |
wiesdat | 0:b48b8c18b1bd | 7 | #define TSAMP 0.001 |
wiesdat | 0:b48b8c18b1bd | 8 | #define I_LIMIT 1. |
wiesdat | 0:b48b8c18b1bd | 9 | #include <iostream> |
wiesdat | 0:b48b8c18b1bd | 10 | |
wiesdat | 0:b48b8c18b1bd | 11 | Encoder encoderA(PTD5,PTA13); |
wiesdat | 0:b48b8c18b1bd | 12 | |
wiesdat | 0:b48b8c18b1bd | 13 | PwmOut pwm(PTC8); |
wiesdat | 0:b48b8c18b1bd | 14 | DigitalOut dir(PTC9); |
wiesdat | 0:b48b8c18b1bd | 15 | |
wiesdat | 0:b48b8c18b1bd | 16 | int32_t enc = 0,enca2 =0,enca1=0, encp=0, counts =0; |
wiesdat | 0:b48b8c18b1bd | 17 | float speed = 0.1, out =0; |
wiesdat | 0:b48b8c18b1bd | 18 | int pos =0,zero =0, fout; |
wiesdat | 0:b48b8c18b1bd | 19 | float v=0; |
wiesdat | 0:b48b8c18b1bd | 20 | float out_i = 0; |
wiesdat | 0:b48b8c18b1bd | 21 | int y; |
wiesdat | 0:b48b8c18b1bd | 22 | |
wiesdat | 0:b48b8c18b1bd | 23 | |
wiesdat | 0:b48b8c18b1bd | 24 | int main() |
wiesdat | 0:b48b8c18b1bd | 25 | { |
wiesdat | 0:b48b8c18b1bd | 26 | while(1){ |
wiesdat | 0:b48b8c18b1bd | 27 | cout<<"typ 1 voor links, 2 voor rechts: "<<endl; |
wiesdat | 0:b48b8c18b1bd | 28 | cin>>y; |
wiesdat | 0:b48b8c18b1bd | 29 | switch(y) { |
wiesdat | 0:b48b8c18b1bd | 30 | case 1: |
wiesdat | 0:b48b8c18b1bd | 31 | cout<<"links"<<endl; |
wiesdat | 0:b48b8c18b1bd | 32 | dir = 1; |
wiesdat | 0:b48b8c18b1bd | 33 | pwm.write(0.4); |
wiesdat | 0:b48b8c18b1bd | 34 | wait(0.01); |
wiesdat | 0:b48b8c18b1bd | 35 | pwm.write(0); |
wiesdat | 0:b48b8c18b1bd | 36 | break; |
wiesdat | 0:b48b8c18b1bd | 37 | case 2: |
wiesdat | 0:b48b8c18b1bd | 38 | cout<<"rechts"<<endl; |
wiesdat | 0:b48b8c18b1bd | 39 | dir = 0; |
wiesdat | 0:b48b8c18b1bd | 40 | pwm.write(0.4); |
wiesdat | 0:b48b8c18b1bd | 41 | wait(0.01); |
wiesdat | 0:b48b8c18b1bd | 42 | pwm.write(0); |
wiesdat | 0:b48b8c18b1bd | 43 | break; |
wiesdat | 0:b48b8c18b1bd | 44 | case 3: |
wiesdat | 0:b48b8c18b1bd | 45 | cout<<encoderA.getPosition()<<endl; |
wiesdat | 0:b48b8c18b1bd | 46 | break; |
wiesdat | 0:b48b8c18b1bd | 47 | case 4: |
wiesdat | 0:b48b8c18b1bd | 48 | encoderA.setPosition(0); |
wiesdat | 0:b48b8c18b1bd | 49 | break; |
wiesdat | 0:b48b8c18b1bd | 50 | } |
wiesdat | 0:b48b8c18b1bd | 51 | } |
wiesdat | 0:b48b8c18b1bd | 52 | |
wiesdat | 0:b48b8c18b1bd | 53 | |
wiesdat | 0:b48b8c18b1bd | 54 | } |