Mathias Riis
/
Hackathon
hej
hack_motor.cpp@0:36611331980a, 2014-04-05 (annotated)
- Committer:
- Risifutti
- Date:
- Sat Apr 05 09:30:52 2014 +0000
- Revision:
- 0:36611331980a
hej;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Risifutti | 0:36611331980a | 1 | #include "mbed.h" |
Risifutti | 0:36611331980a | 2 | #include "hack_motor.h" |
Risifutti | 0:36611331980a | 3 | #include "PwmOut.h" |
Risifutti | 0:36611331980a | 4 | |
Risifutti | 0:36611331980a | 5 | Wheel::Wheel() : M1A(PTC8), M1B(PTC10), M2A(PTC9), M2B(PTC11), GrabA(PTA5), GrabB(PTC7), HejsA(PTA4), HejsB(PTC5) |
Risifutti | 0:36611331980a | 6 | { |
Risifutti | 0:36611331980a | 7 | init(); |
Risifutti | 0:36611331980a | 8 | } |
Risifutti | 0:36611331980a | 9 | |
Risifutti | 0:36611331980a | 10 | |
Risifutti | 0:36611331980a | 11 | void Wheel::init() //Initialize the driver pwm to 150Hz |
Risifutti | 0:36611331980a | 12 | { |
Risifutti | 0:36611331980a | 13 | M1A.period(0.0066); |
Risifutti | 0:36611331980a | 14 | M2A.period(0.0066); |
Risifutti | 0:36611331980a | 15 | GrabA.period(0.0066); |
Risifutti | 0:36611331980a | 16 | HejsA.period(0.0066); |
Risifutti | 0:36611331980a | 17 | speed = 0.0; |
Risifutti | 0:36611331980a | 18 | } |
Risifutti | 0:36611331980a | 19 | |
Risifutti | 0:36611331980a | 20 | void Wheel::FW() |
Risifutti | 0:36611331980a | 21 | { |
Risifutti | 0:36611331980a | 22 | fw = 0.5+(0.5*speed); //forward lies in the upper 50% of the duty cycle |
Risifutti | 0:36611331980a | 23 | M1A.write(fw); //Set the duty cycle to the wanted percent, from speed variable |
Risifutti | 0:36611331980a | 24 | M2A.write(fw); // -//- |
Risifutti | 0:36611331980a | 25 | M1B = 0; |
Risifutti | 0:36611331980a | 26 | M2B = 0; |
Risifutti | 0:36611331980a | 27 | wait_ms(1); |
Risifutti | 0:36611331980a | 28 | } |
Risifutti | 0:36611331980a | 29 | |
Risifutti | 0:36611331980a | 30 | void Wheel::BW() |
Risifutti | 0:36611331980a | 31 | { |
Risifutti | 0:36611331980a | 32 | bw = 0.5-(0.5*speed); //Backward lies within the lower 50% of the duty cycle |
Risifutti | 0:36611331980a | 33 | M1A.write(bw); //Set the duty cycle to the wanted percent, from speed variable |
Risifutti | 0:36611331980a | 34 | M2A.write(bw); // -//- |
Risifutti | 0:36611331980a | 35 | M1B = 1; |
Risifutti | 0:36611331980a | 36 | M2B = 1; |
Risifutti | 0:36611331980a | 37 | } |
Risifutti | 0:36611331980a | 38 | |
Risifutti | 0:36611331980a | 39 | void Wheel::right() |
Risifutti | 0:36611331980a | 40 | { |
Risifutti | 0:36611331980a | 41 | M1A.write(0.75); //Left side forward 50% |
Risifutti | 0:36611331980a | 42 | M2A.write(0.25); //Right side backwards 50% |
Risifutti | 0:36611331980a | 43 | M1B = 0; |
Risifutti | 0:36611331980a | 44 | M2B = 1; |
Risifutti | 0:36611331980a | 45 | } |
Risifutti | 0:36611331980a | 46 | |
Risifutti | 0:36611331980a | 47 | void Wheel::left() |
Risifutti | 0:36611331980a | 48 | { |
Risifutti | 0:36611331980a | 49 | M1A.write(0.25); //Right side forward 50% |
Risifutti | 0:36611331980a | 50 | M2A.write(0.75); //Left side backwards 50% |
Risifutti | 0:36611331980a | 51 | M1B = 1; |
Risifutti | 0:36611331980a | 52 | M2B = 0; |
Risifutti | 0:36611331980a | 53 | } |
Risifutti | 0:36611331980a | 54 | |
Risifutti | 0:36611331980a | 55 | void Wheel::stop() |
Risifutti | 0:36611331980a | 56 | { |
Risifutti | 0:36611331980a | 57 | M1A.write(0.0); //Pin A's set low |
Risifutti | 0:36611331980a | 58 | M2A.write(0.0); |
Risifutti | 0:36611331980a | 59 | M1B = 0; |
Risifutti | 0:36611331980a | 60 | M2B = 0; //Pin B's set high |
Risifutti | 0:36611331980a | 61 | GrabA.write(0.0); |
Risifutti | 0:36611331980a | 62 | HejsA.write(0.0); |
Risifutti | 0:36611331980a | 63 | GrabB = 0; |
Risifutti | 0:36611331980a | 64 | HejsB = 0; |
Risifutti | 0:36611331980a | 65 | } |
Risifutti | 0:36611331980a | 66 | |
Risifutti | 0:36611331980a | 67 | void Wheel::open() |
Risifutti | 0:36611331980a | 68 | { |
Risifutti | 0:36611331980a | 69 | GrabA.write(0.3); |
Risifutti | 0:36611331980a | 70 | GrabB = 1; |
Risifutti | 0:36611331980a | 71 | wait(0.9); |
Risifutti | 0:36611331980a | 72 | GrabA.write(0.0); |
Risifutti | 0:36611331980a | 73 | GrabB = 0; |
Risifutti | 0:36611331980a | 74 | } |
Risifutti | 0:36611331980a | 75 | |
Risifutti | 0:36611331980a | 76 | void Wheel::close() |
Risifutti | 0:36611331980a | 77 | { |
Risifutti | 0:36611331980a | 78 | GrabA.write(0.8); |
Risifutti | 0:36611331980a | 79 | GrabB = 0; |
Risifutti | 0:36611331980a | 80 | wait(0.6); |
Risifutti | 0:36611331980a | 81 | GrabA.write(0.0); |
Risifutti | 0:36611331980a | 82 | GrabB = 0; |
Risifutti | 0:36611331980a | 83 | } |
Risifutti | 0:36611331980a | 84 | |
Risifutti | 0:36611331980a | 85 | void Wheel::hejs() |
Risifutti | 0:36611331980a | 86 | { |
Risifutti | 0:36611331980a | 87 | HejsA.write(0.75); |
Risifutti | 0:36611331980a | 88 | HejsB = 0; |
Risifutti | 0:36611331980a | 89 | wait(0.3); |
Risifutti | 0:36611331980a | 90 | HejsA.write(0.0); |
Risifutti | 0:36611331980a | 91 | HejsB = 0; |
Risifutti | 0:36611331980a | 92 | } |
Risifutti | 0:36611331980a | 93 | |
Risifutti | 0:36611331980a | 94 | void Wheel::saenk() |
Risifutti | 0:36611331980a | 95 | { |
Risifutti | 0:36611331980a | 96 | HejsA.write(0.25); |
Risifutti | 0:36611331980a | 97 | HejsB = 1; |
Risifutti | 0:36611331980a | 98 | wait(0.3); |
Risifutti | 0:36611331980a | 99 | HejsA.write(0.0); |
Risifutti | 0:36611331980a | 100 | HejsA = 0; |
Risifutti | 0:36611331980a | 101 | } |