Biorobotics / Mbed 2 deprecated Motor_moving_setpoint

Dependencies:   QEI mbed

Committer:
yohoo15
Date:
Mon Sep 28 09:55:41 2015 +0000
Revision:
0:70a6fd5751a6
Child:
1:c855dee2c6d4
script can turn the motor x pi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yohoo15 0:70a6fd5751a6 1 #include "mbed.h"
yohoo15 0:70a6fd5751a6 2 #include "QEI.h"
yohoo15 0:70a6fd5751a6 3
yohoo15 0:70a6fd5751a6 4 Serial pc(USBTX, USBRX);
yohoo15 0:70a6fd5751a6 5 QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in)
yohoo15 0:70a6fd5751a6 6
yohoo15 0:70a6fd5751a6 7 // Define pin for motor control
yohoo15 0:70a6fd5751a6 8 DigitalOut directionPin(D4);
yohoo15 0:70a6fd5751a6 9 PwmOut PWM(D5);
yohoo15 0:70a6fd5751a6 10
yohoo15 0:70a6fd5751a6 11
yohoo15 0:70a6fd5751a6 12
yohoo15 0:70a6fd5751a6 13 // 8400 counts per revolution
yohoo15 0:70a6fd5751a6 14 // so 8400 / (2 *pi) is counts/pi
yohoo15 0:70a6fd5751a6 15
yohoo15 0:70a6fd5751a6 16
yohoo15 0:70a6fd5751a6 17 Ticker tellen;
yohoo15 0:70a6fd5751a6 18 bool stoppen = false;
yohoo15 0:70a6fd5751a6 19
yohoo15 0:70a6fd5751a6 20 void GOTO()
yohoo15 0:70a6fd5751a6 21 {
yohoo15 0:70a6fd5751a6 22 double resolution = 8400 / (2 * 3.14592);
yohoo15 0:70a6fd5751a6 23 double Rotation = 4; // rotation in pi
yohoo15 0:70a6fd5751a6 24 double movement = Rotation * resolution;
yohoo15 0:70a6fd5751a6 25
yohoo15 0:70a6fd5751a6 26 // pc.printf("The number of real rotation is %i \n",Rotation);
yohoo15 0:70a6fd5751a6 27
yohoo15 0:70a6fd5751a6 28
yohoo15 0:70a6fd5751a6 29 if (wheel.getPulses() <= movement) {
yohoo15 0:70a6fd5751a6 30 directionPin.write(1);
yohoo15 0:70a6fd5751a6 31 PWM.write(0.3);
yohoo15 0:70a6fd5751a6 32 pc.printf("Pulses is: %i\n", wheel.getPulses());
yohoo15 0:70a6fd5751a6 33 } else {
yohoo15 0:70a6fd5751a6 34 PWM.write(0);
yohoo15 0:70a6fd5751a6 35 //pc.printf("The motor turned %i rotations \n",Rotation);
yohoo15 0:70a6fd5751a6 36 pc.printf("Pulses is: %i\n The motor turned %.2f rotations\n", wheel.getPulses(),Rotation);
yohoo15 0:70a6fd5751a6 37 stoppen = true;
yohoo15 0:70a6fd5751a6 38
yohoo15 0:70a6fd5751a6 39
yohoo15 0:70a6fd5751a6 40 }
yohoo15 0:70a6fd5751a6 41
yohoo15 0:70a6fd5751a6 42
yohoo15 0:70a6fd5751a6 43
yohoo15 0:70a6fd5751a6 44
yohoo15 0:70a6fd5751a6 45 }
yohoo15 0:70a6fd5751a6 46
yohoo15 0:70a6fd5751a6 47
yohoo15 0:70a6fd5751a6 48
yohoo15 0:70a6fd5751a6 49 int main()
yohoo15 0:70a6fd5751a6 50 {
yohoo15 0:70a6fd5751a6 51 int proberen = 1000;
yohoo15 0:70a6fd5751a6 52 pc.printf("The number of rotation is %i \n",proberen);
yohoo15 0:70a6fd5751a6 53
yohoo15 0:70a6fd5751a6 54
yohoo15 0:70a6fd5751a6 55
yohoo15 0:70a6fd5751a6 56
yohoo15 0:70a6fd5751a6 57
yohoo15 0:70a6fd5751a6 58 tellen.attach(&GOTO, 0.1);
yohoo15 0:70a6fd5751a6 59
yohoo15 0:70a6fd5751a6 60
yohoo15 0:70a6fd5751a6 61
yohoo15 0:70a6fd5751a6 62
yohoo15 0:70a6fd5751a6 63
yohoo15 0:70a6fd5751a6 64
yohoo15 0:70a6fd5751a6 65
yohoo15 0:70a6fd5751a6 66
yohoo15 0:70a6fd5751a6 67
yohoo15 0:70a6fd5751a6 68 }