![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
10/25/2015
Dependencies: PID mbed MaxSonar eeprom iSerial Fork_Boss_Communication_Robot
main.cpp@3:365615fa646e, 2015-10-23 (annotated)
- Committer:
- palmdotax
- Date:
- Fri Oct 23 17:05:09 2015 +0000
- Revision:
- 3:365615fa646e
- Parent:
- 2:933d3edf38da
- Child:
- 4:e6ab360e7de6
V3;
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 | 3:365615fa646e | 5 | DigitalOut led1(LED1); |
palmdotax | 0:f02641e3fb91 | 6 | InterruptIn encoderA(D6); |
palmdotax | 0:f02641e3fb91 | 7 | InterruptIn encoderB(D5); |
palmdotax | 2:933d3edf38da | 8 | Timer timerStart; |
palmdotax | 3:365615fa646e | 9 | Timeout timecount; |
palmdotax | 1:7c3dbf140bfc | 10 | move m1; |
palmdotax | 2:933d3edf38da | 11 | PID P1(0.001,0,0,0.1); |
palmdotax | 0:f02641e3fb91 | 12 | |
palmdotax | 0:f02641e3fb91 | 13 | //DigitalIn encoderB(D5); |
palmdotax | 0:f02641e3fb91 | 14 | |
palmdotax | 0:f02641e3fb91 | 15 | |
palmdotax | 0:f02641e3fb91 | 16 | Serial pc(SERIAL_TX,SERIAL_RX); |
palmdotax | 0:f02641e3fb91 | 17 | int Encoderpos = 0; |
palmdotax | 3:365615fa646e | 18 | float valocity =0,pulse=0,count=0; |
palmdotax | 3:365615fa646e | 19 | float outPID =0; |
palmdotax | 3:365615fa646e | 20 | //double Input,Output,setp,Kp=0.005,Ki=0.005,Kd=0; |
palmdotax | 3:365615fa646e | 21 | |
palmdotax | 0:f02641e3fb91 | 22 | |
palmdotax | 0:f02641e3fb91 | 23 | void EncoderA() |
palmdotax | 0:f02641e3fb91 | 24 | { if(encoderB==0) |
palmdotax | 0:f02641e3fb91 | 25 | { Encoderpos = Encoderpos + 1;} |
palmdotax | 0:f02641e3fb91 | 26 | else |
palmdotax | 0:f02641e3fb91 | 27 | { Encoderpos = Encoderpos -1;} |
palmdotax | 1:7c3dbf140bfc | 28 | |
palmdotax | 0:f02641e3fb91 | 29 | //Encoderpos = Encoderpos + 1; |
palmdotax | 3:365615fa646e | 30 | // valocity+=1; |
palmdotax | 1:7c3dbf140bfc | 31 | // pc.printf("%d \n",Encoderpos); |
palmdotax | 3:365615fa646e | 32 | pulse+=1; |
palmdotax | 3:365615fa646e | 33 | if(pulse>=128) |
palmdotax | 3:365615fa646e | 34 | {count+=1;pulse=0;} |
palmdotax | 0:f02641e3fb91 | 35 | } |
palmdotax | 0:f02641e3fb91 | 36 | |
palmdotax | 0:f02641e3fb91 | 37 | |
palmdotax | 3:365615fa646e | 38 | /*void EncoderB() |
palmdotax | 0:f02641e3fb91 | 39 | { |
palmdotax | 0:f02641e3fb91 | 40 | if(encoderA==1) |
palmdotax | 0:f02641e3fb91 | 41 | { Encoderpos = Encoderpos + 1;} |
palmdotax | 0:f02641e3fb91 | 42 | else |
palmdotax | 0:f02641e3fb91 | 43 | { Encoderpos = Encoderpos -1;} |
palmdotax | 0:f02641e3fb91 | 44 | pc.printf("%d",Encoderpos); |
palmdotax | 3:365615fa646e | 45 | }*/ |
palmdotax | 3:365615fa646e | 46 | void getRPM() |
palmdotax | 3:365615fa646e | 47 | { |
palmdotax | 3:365615fa646e | 48 | valocity=count; |
palmdotax | 3:365615fa646e | 49 | count=0; |
palmdotax | 0:f02641e3fb91 | 50 | } |
palmdotax | 0:f02641e3fb91 | 51 | |
palmdotax | 0:f02641e3fb91 | 52 | int main() |
palmdotax | 0:f02641e3fb91 | 53 | { |
palmdotax | 1:7c3dbf140bfc | 54 | |
palmdotax | 0:f02641e3fb91 | 55 | pc.baud(115200); |
palmdotax | 0:f02641e3fb91 | 56 | encoderA.rise(&EncoderA); |
palmdotax | 2:933d3edf38da | 57 | timerStart.start(); |
palmdotax | 2:933d3edf38da | 58 | |
palmdotax | 2:933d3edf38da | 59 | |
palmdotax | 2:933d3edf38da | 60 | P1.setMode(1); |
palmdotax | 2:933d3edf38da | 61 | P1.setProcessValue(0.7); |
palmdotax | 1:7c3dbf140bfc | 62 | P1.setSetPoint(0.8); |
palmdotax | 2:933d3edf38da | 63 | P1.setBias(0); |
palmdotax | 3:365615fa646e | 64 | pc.printf("READY \n"); |
palmdotax | 0:f02641e3fb91 | 65 | while(1) |
palmdotax | 3:365615fa646e | 66 | |
palmdotax | 2:933d3edf38da | 67 | { |
palmdotax | 3:365615fa646e | 68 | led1=1; |
palmdotax | 3:365615fa646e | 69 | |
palmdotax | 3:365615fa646e | 70 | timecount.attach(&getRPM, 60); |
palmdotax | 3:365615fa646e | 71 | // m1.movespeed(1,1.0); |
palmdotax | 3:365615fa646e | 72 | // outPID=P1.compute(); |
palmdotax | 3:365615fa646e | 73 | // pc.printf("%f \n",valocity); |
palmdotax | 2:933d3edf38da | 74 | wait(0.1); |
palmdotax | 1:7c3dbf140bfc | 75 | |
palmdotax | 0:f02641e3fb91 | 76 | // pc.printf("%d \n",Encoderpos); |
palmdotax | 0:f02641e3fb91 | 77 | |
palmdotax | 0:f02641e3fb91 | 78 | } |
palmdotax | 0:f02641e3fb91 | 79 | } |