thijs ruikes
/
PROJECT-BATJEPOSTITIE
vor bas
Diff: main.cpp
- Revision:
- 0:b48b8c18b1bd
- Child:
- 1:d157905a98d1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 30 17:10:14 2014 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "mbed.h" +#include "encoder.h" +#define K_P (0.1) +#define K_I (0.1) +#define K_D (0.0005 /TSAMP) +#define TSAMP 0.001 +#define I_LIMIT 1. +#include <iostream> + +Encoder encoderA(PTD5,PTA13); + +PwmOut pwm(PTC8); +DigitalOut dir(PTC9); + +int32_t enc = 0,enca2 =0,enca1=0, encp=0, counts =0; +float speed = 0.1, out =0; +int pos =0,zero =0, fout; +float v=0; +float out_i = 0; +int y; + + +int main() +{ + while(1){ + cout<<"typ 1 voor links, 2 voor rechts: "<<endl; + cin>>y; + switch(y) { + case 1: + cout<<"links"<<endl; + dir = 1; + pwm.write(0.4); + wait(0.01); + pwm.write(0); + break; + case 2: + cout<<"rechts"<<endl; + dir = 0; + pwm.write(0.4); + wait(0.01); + pwm.write(0); + break; + case 3: + cout<<encoderA.getPosition()<<endl; + break; + case 4: + encoderA.setPosition(0); + break; + } +} + + +} \ No newline at end of file