tau new ticker toevoegen.

Dependencies:   HIDScope MODSERIAL QEI mbed

Fork of Tau_new by V D

Committer:
vd
Date:
Thu Nov 02 08:44:58 2017 +0000
Revision:
4:e22508afc194
Parent:
3:48397c80d0e4
tau new ticker toevoegen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ARGroenenboom 0:cf88b023a080 1 #include "mbed.h"
ARGroenenboom 0:cf88b023a080 2 #include "HIDScope.h"
ARGroenenboom 0:cf88b023a080 3 #include "QEI.h"
ARGroenenboom 0:cf88b023a080 4 #include "iostream"
vd 4:e22508afc194 5 #include "MODSERIAL.h"
ARGroenenboom 0:cf88b023a080 6
ARGroenenboom 0:cf88b023a080 7 //Leds
ARGroenenboom 0:cf88b023a080 8 DigitalOut ledb(LED_BLUE);
ARGroenenboom 0:cf88b023a080 9 DigitalOut ledr(LED_RED);
ARGroenenboom 0:cf88b023a080 10 DigitalOut ledg(LED_GREEN);
ARGroenenboom 0:cf88b023a080 11
ARGroenenboom 0:cf88b023a080 12 //Motor
ARGroenenboom 0:cf88b023a080 13 DigitalOut motor1DC(D7);
ARGroenenboom 0:cf88b023a080 14 PwmOut motor1PWM(D6);
ARGroenenboom 0:cf88b023a080 15
ARGroenenboom 0:cf88b023a080 16 //Button
ARGroenenboom 0:cf88b023a080 17 DigitalIn button1(SW2);
ARGroenenboom 0:cf88b023a080 18
ARGroenenboom 0:cf88b023a080 19 // HIDscope
ARGroenenboom 0:cf88b023a080 20 HIDScope scope(1);
ARGroenenboom 0:cf88b023a080 21
vd 4:e22508afc194 22 //Ticker
vd 4:e22508afc194 23 Ticker tick;
vd 4:e22508afc194 24 float f = 0.2;
vd 4:e22508afc194 25
ARGroenenboom 0:cf88b023a080 26 // Encoder
vd 4:e22508afc194 27 float X = 32.0;
vd 4:e22508afc194 28 float N = 131.0;
ARGroenenboom 1:d2fe9abf5082 29 float pulse_count;
ARGroenenboom 1:d2fe9abf5082 30 float angle_motor;
vd 4:e22508afc194 31 QEI Encoder(D8,D9,NC,N);
vd 4:e22508afc194 32 MODSERIAL pc(USBTX,USBRX);
ARGroenenboom 0:cf88b023a080 33
vd 4:e22508afc194 34 //ticker function
ARGroenenboom 0:cf88b023a080 35
vd 4:e22508afc194 36 //void send(angle)
vd 4:e22508afc194 37 //{
ARGroenenboom 0:cf88b023a080 38
vd 4:e22508afc194 39 // scope.set(0, angle);
vd 4:e22508afc194 40 // scope.send();
vd 4:e22508afc194 41 //}
vd 3:48397c80d0e4 42
ARGroenenboom 0:cf88b023a080 43
ARGroenenboom 0:cf88b023a080 44 int main()
ARGroenenboom 0:cf88b023a080 45 {
vd 4:e22508afc194 46
vd 4:e22508afc194 47 pc.baud(9600);
vd 4:e22508afc194 48 pc.printf("Hello world");
vd 4:e22508afc194 49 motor1DC = -1;
ARGroenenboom 0:cf88b023a080 50 ledb = 1;
ARGroenenboom 0:cf88b023a080 51 ledr = 1;
ARGroenenboom 0:cf88b023a080 52 ledg = 0;
vd 4:e22508afc194 53
vd 4:e22508afc194 54 while (true) {
vd 4:e22508afc194 55
vd 4:e22508afc194 56 //angle=0;
vd 4:e22508afc194 57
vd 4:e22508afc194 58 if(button1==false) {
vd 4:e22508afc194 59
vd 4:e22508afc194 60
vd 4:e22508afc194 61
vd 4:e22508afc194 62 wait(1.0); // wait before next roll to protect motors
vd 4:e22508afc194 63 //ledr = 1;
vd 4:e22508afc194 64 ledb = 1;
vd 4:e22508afc194 65 //ledg = 0; // green led on = ready to roll
vd 4:e22508afc194 66
vd 4:e22508afc194 67 ledg = 1; // green led off
vd 4:e22508afc194 68 ledr = 0; // red led on = rolling
vd 4:e22508afc194 69
vd 4:e22508afc194 70 motor1PWM = 1; // motor on
vd 4:e22508afc194 71 wait(3.00); //1.025
vd 4:e22508afc194 72 motor1PWM = 0; // motor off
vd 4:e22508afc194 73
vd 4:e22508afc194 74 wait(1.0);
vd 4:e22508afc194 75 ledr = 1;
ARGroenenboom 0:cf88b023a080 76 ledb = 1;
vd 4:e22508afc194 77 ledg = 0;
vd 4:e22508afc194 78 // green led on = ready to roll
vd 4:e22508afc194 79
vd 4:e22508afc194 80 // Get pulses and send to HIDScope
vd 4:e22508afc194 81 pulse_count = Encoder.getPulses();
vd 4:e22508afc194 82
vd 4:e22508afc194 83 float angle_pp =360/(X * N);
vd 4:e22508afc194 84 float angle = pulse_count*angle_pp;
vd 4:e22508afc194 85
vd 4:e22508afc194 86 pc.printf(" pulse count: %f angle: %f \r \n ", pulse_count, angle);
vd 4:e22508afc194 87
vd 4:e22508afc194 88 //tick.attach(&send(angle), f);
vd 4:e22508afc194 89
vd 4:e22508afc194 90 scope.set(0, angle);
vd 4:e22508afc194 91 scope.send();
vd 4:e22508afc194 92
vd 4:e22508afc194 93 Encoder.reset();
vd 4:e22508afc194 94
vd 4:e22508afc194 95
vd 4:e22508afc194 96 }
vd 4:e22508afc194 97
ARGroenenboom 0:cf88b023a080 98 }
vd 4:e22508afc194 99
vd 4:e22508afc194 100
vd 4:e22508afc194 101
vd 4:e22508afc194 102 }
vd 4:e22508afc194 103
vd 4:e22508afc194 104 // screen /dev/tty.usbmodem1412 9600