motor aansturing moet lineair zijn is het niet

Dependencies:   MODSERIAL Encoder mbed HIDScope

Committer:
Zeekat
Date:
Mon Sep 28 09:14:12 2015 +0000
Revision:
1:8918d924f625
Parent:
0:5ea1875b307a
Child:
2:bcd68150136c
added gradual

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zeekat 0:5ea1875b307a 1 #include "mbed.h"
Zeekat 0:5ea1875b307a 2
Zeekat 0:5ea1875b307a 3 //MOTOR
Zeekat 0:5ea1875b307a 4 // motor 1 en 2 zijn omgedraait
Zeekat 0:5ea1875b307a 5 // pinnen motor 1 -> pinnen motor 2
Zeekat 0:5ea1875b307a 6
Zeekat 0:5ea1875b307a 7 //motor 1 gegevens
Zeekat 0:5ea1875b307a 8 PwmOut motor1_aan(D6); // PWM signaal motor 2 (uit sheets)
Zeekat 0:5ea1875b307a 9 DigitalOut motor1_rich(D7); // digitaal signaal voor richting
Zeekat 0:5ea1875b307a 10 // einde motor 1
Zeekat 0:5ea1875b307a 11
Zeekat 0:5ea1875b307a 12 //motor 2 gegevens
Zeekat 0:5ea1875b307a 13 PwmOut motor2_aan(D5); // PWM signaal motor 1 (uit sheets)
Zeekat 0:5ea1875b307a 14 DigitalOut motor2_rich(D4); // digitaal signaal voor richting
Zeekat 0:5ea1875b307a 15 // einde motor 1
Zeekat 0:5ea1875b307a 16 //EINDE MOTOR
Zeekat 0:5ea1875b307a 17
Zeekat 0:5ea1875b307a 18
Zeekat 0:5ea1875b307a 19 //POTMETERS
Zeekat 0:5ea1875b307a 20 AnalogIn potleft(A1);
Zeekat 0:5ea1875b307a 21 AnalogIn potright(A0);
Zeekat 0:5ea1875b307a 22
Zeekat 0:5ea1875b307a 23 void move_mot1(float left)
Zeekat 0:5ea1875b307a 24 {
Zeekat 0:5ea1875b307a 25 if(left < 0.4)
Zeekat 1:8918d924f625 26 {
Zeekat 1:8918d924f625 27 float leftin = left*2.5 ;
Zeekat 1:8918d924f625 28 motor1_aan.write(leftin);
Zeekat 0:5ea1875b307a 29 motor1_rich.write(0);
Zeekat 0:5ea1875b307a 30 }
Zeekat 0:5ea1875b307a 31 else if(left > 0.4 && left < 0.6)
Zeekat 0:5ea1875b307a 32 {
Zeekat 0:5ea1875b307a 33 motor1_aan.write(0);
Zeekat 0:5ea1875b307a 34 }
Zeekat 0:5ea1875b307a 35 else if(left > 0.6)
Zeekat 0:5ea1875b307a 36 {
Zeekat 1:8918d924f625 37 float calc = left - 1;
Zeekat 1:8918d924f625 38 float calc2 = abs(calc);
Zeekat 1:8918d924f625 39 float leftin = calc2*2.5;
Zeekat 1:8918d924f625 40 motor1_aan.write(leftin);
Zeekat 0:5ea1875b307a 41 motor1_rich.write(1);
Zeekat 0:5ea1875b307a 42 }
Zeekat 0:5ea1875b307a 43 }
Zeekat 0:5ea1875b307a 44
Zeekat 0:5ea1875b307a 45 void move_mot2(float right)
Zeekat 0:5ea1875b307a 46 {
Zeekat 0:5ea1875b307a 47 if(right < 0.4)
Zeekat 0:5ea1875b307a 48 {
Zeekat 1:8918d924f625 49 float rightin = right*2.5;
Zeekat 1:8918d924f625 50 motor2_aan.write(rightin);
Zeekat 0:5ea1875b307a 51 motor2_rich.write(0);
Zeekat 0:5ea1875b307a 52 }
Zeekat 0:5ea1875b307a 53 else if(right > 0.4 && right < 0.6)
Zeekat 0:5ea1875b307a 54 {
Zeekat 0:5ea1875b307a 55 motor2_aan.write(0);
Zeekat 0:5ea1875b307a 56 }
Zeekat 0:5ea1875b307a 57 else if(right > 0.6)
Zeekat 0:5ea1875b307a 58 {
Zeekat 1:8918d924f625 59 float calc3 = right-1;
Zeekat 1:8918d924f625 60 float calc4 = abs(calc3);
Zeekat 1:8918d924f625 61 float rightin = calc4*2.5;
Zeekat 1:8918d924f625 62 motor2_aan.write(rightin);
Zeekat 0:5ea1875b307a 63 motor2_rich.write(1);
Zeekat 0:5ea1875b307a 64 }
Zeekat 0:5ea1875b307a 65 }
Zeekat 0:5ea1875b307a 66
Zeekat 0:5ea1875b307a 67
Zeekat 0:5ea1875b307a 68
Zeekat 0:5ea1875b307a 69 int main()
Zeekat 0:5ea1875b307a 70 {
Zeekat 0:5ea1875b307a 71
Zeekat 0:5ea1875b307a 72 while(true)
Zeekat 0:5ea1875b307a 73 {
Zeekat 0:5ea1875b307a 74 float left = potleft.read();
Zeekat 0:5ea1875b307a 75 float right = potright.read();
Zeekat 0:5ea1875b307a 76 move_mot1(left);
Zeekat 0:5ea1875b307a 77 move_mot2(right);
Zeekat 0:5ea1875b307a 78 wait(0.01f);
Zeekat 0:5ea1875b307a 79 }
Zeekat 0:5ea1875b307a 80 }