![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
10/25/2015
Dependencies: PID mbed MaxSonar eeprom iSerial Fork_Boss_Communication_Robot
main.cpp@1:7c3dbf140bfc, 2015-10-18 (annotated)
- Committer:
- palmdotax
- Date:
- Sun Oct 18 18:48:47 2015 +0000
- Revision:
- 1:7c3dbf140bfc
- Parent:
- 0:f02641e3fb91
- Child:
- 2:933d3edf38da
v.1.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
palmdotax | 0:f02641e3fb91 | 1 | #include"mbed.h" |
palmdotax | 1:7c3dbf140bfc | 2 | #include "move.h" |
palmdotax | 0:f02641e3fb91 | 3 | #include "PID.h" |
palmdotax | 1:7c3dbf140bfc | 4 | |
palmdotax | 0:f02641e3fb91 | 5 | InterruptIn encoderA(D6); |
palmdotax | 0:f02641e3fb91 | 6 | InterruptIn encoderB(D5); |
palmdotax | 1:7c3dbf140bfc | 7 | move m1; |
palmdotax | 1:7c3dbf140bfc | 8 | |
palmdotax | 1:7c3dbf140bfc | 9 | PID P1(0.001,0.005,0,0.1); |
palmdotax | 0:f02641e3fb91 | 10 | |
palmdotax | 0:f02641e3fb91 | 11 | //DigitalIn encoderB(D5); |
palmdotax | 0:f02641e3fb91 | 12 | |
palmdotax | 0:f02641e3fb91 | 13 | |
palmdotax | 0:f02641e3fb91 | 14 | Serial pc(SERIAL_TX,SERIAL_RX); |
palmdotax | 0:f02641e3fb91 | 15 | int Encoderpos = 0; |
palmdotax | 1:7c3dbf140bfc | 16 | float valocity =0; |
palmdotax | 1:7c3dbf140bfc | 17 | float outPID =0; |
palmdotax | 0:f02641e3fb91 | 18 | |
palmdotax | 0:f02641e3fb91 | 19 | void EncoderA() |
palmdotax | 0:f02641e3fb91 | 20 | { if(encoderB==0) |
palmdotax | 0:f02641e3fb91 | 21 | { Encoderpos = Encoderpos + 1;} |
palmdotax | 0:f02641e3fb91 | 22 | else |
palmdotax | 0:f02641e3fb91 | 23 | { Encoderpos = Encoderpos -1;} |
palmdotax | 1:7c3dbf140bfc | 24 | |
palmdotax | 0:f02641e3fb91 | 25 | //Encoderpos = Encoderpos + 1; |
palmdotax | 0:f02641e3fb91 | 26 | valocity+=1; |
palmdotax | 1:7c3dbf140bfc | 27 | // pc.printf("%d \n",Encoderpos); |
palmdotax | 0:f02641e3fb91 | 28 | } |
palmdotax | 0:f02641e3fb91 | 29 | |
palmdotax | 0:f02641e3fb91 | 30 | |
palmdotax | 0:f02641e3fb91 | 31 | void EncoderB() |
palmdotax | 0:f02641e3fb91 | 32 | { |
palmdotax | 0:f02641e3fb91 | 33 | if(encoderA==1) |
palmdotax | 0:f02641e3fb91 | 34 | { Encoderpos = Encoderpos + 1;} |
palmdotax | 0:f02641e3fb91 | 35 | else |
palmdotax | 0:f02641e3fb91 | 36 | { Encoderpos = Encoderpos -1;} |
palmdotax | 0:f02641e3fb91 | 37 | pc.printf("%d",Encoderpos); |
palmdotax | 0:f02641e3fb91 | 38 | } |
palmdotax | 0:f02641e3fb91 | 39 | |
palmdotax | 0:f02641e3fb91 | 40 | int main() |
palmdotax | 0:f02641e3fb91 | 41 | { |
palmdotax | 1:7c3dbf140bfc | 42 | |
palmdotax | 0:f02641e3fb91 | 43 | pc.baud(115200); |
palmdotax | 0:f02641e3fb91 | 44 | encoderA.rise(&EncoderA); |
palmdotax | 1:7c3dbf140bfc | 45 | //pc.printf("Encode\n"); |
palmdotax | 1:7c3dbf140bfc | 46 | P1.setMode(0); |
palmdotax | 1:7c3dbf140bfc | 47 | P1.setProcessValue(0.7); |
palmdotax | 1:7c3dbf140bfc | 48 | P1.setSetPoint(0.8); |
palmdotax | 1:7c3dbf140bfc | 49 | // P1.setBias(0); |
palmdotax | 0:f02641e3fb91 | 50 | while(1) |
palmdotax | 1:7c3dbf140bfc | 51 | { P1.setProcessValue(0.7); |
palmdotax | 1:7c3dbf140bfc | 52 | P1.setSetPoint(0.8); |
palmdotax | 1:7c3dbf140bfc | 53 | outPID=P1.compute(); |
palmdotax | 1:7c3dbf140bfc | 54 | // pc.printf("palm \n"); |
palmdotax | 1:7c3dbf140bfc | 55 | pc.printf("%f \n",outPID); |
palmdotax | 1:7c3dbf140bfc | 56 | wait(1); |
palmdotax | 1:7c3dbf140bfc | 57 | |
palmdotax | 0:f02641e3fb91 | 58 | // pc.printf("%d \n",Encoderpos); |
palmdotax | 0:f02641e3fb91 | 59 | |
palmdotax | 0:f02641e3fb91 | 60 | } |
palmdotax | 0:f02641e3fb91 | 61 | } |