![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First attempt at Milestone_1. Commit for progress information
main.cpp@0:7fd3327ceec4, 2018-09-28 (annotated)
- Committer:
- ThomBMT
- Date:
- Fri Sep 28 13:43:53 2018 +0000
- Revision:
- 0:7fd3327ceec4
This is the first version of Milestone_1. We are able to control the direction of rotation of both motors individualy. However we do not fully understand how we can edit the rotationfreq. or the dutycycles of both motors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThomBMT | 0:7fd3327ceec4 | 1 | #include "mbed.h" |
ThomBMT | 0:7fd3327ceec4 | 2 | |
ThomBMT | 0:7fd3327ceec4 | 3 | DigitalOut DirectionPin1(D4); |
ThomBMT | 0:7fd3327ceec4 | 4 | PwmOut PwmPin1(D5); |
ThomBMT | 0:7fd3327ceec4 | 5 | DigitalOut DirectionPin2(D7); |
ThomBMT | 0:7fd3327ceec4 | 6 | PwmOut PwmPin2(D6); |
ThomBMT | 0:7fd3327ceec4 | 7 | |
ThomBMT | 0:7fd3327ceec4 | 8 | |
ThomBMT | 0:7fd3327ceec4 | 9 | |
ThomBMT | 0:7fd3327ceec4 | 10 | int main() |
ThomBMT | 0:7fd3327ceec4 | 11 | { |
ThomBMT | 0:7fd3327ceec4 | 12 | PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz |
ThomBMT | 0:7fd3327ceec4 | 13 | for(;;) |
ThomBMT | 0:7fd3327ceec4 | 14 | { |
ThomBMT | 0:7fd3327ceec4 | 15 | float u = -0.4f; //determine useful value, this is not final |
ThomBMT | 0:7fd3327ceec4 | 16 | DirectionPin1 = u > 0.0f; //either true or false |
ThomBMT | 0:7fd3327ceec4 | 17 | // True = CW, for False = CW |
ThomBMT | 0:7fd3327ceec4 | 18 | PwmPin1 = fabs(u); //PWM duty cycle can only be positive, floating point absolute value |
ThomBMT | 0:7fd3327ceec4 | 19 | |
ThomBMT | 0:7fd3327ceec4 | 20 | float v = 0.5f; |
ThomBMT | 0:7fd3327ceec4 | 21 | DirectionPin2 = v > 0.0f; |
ThomBMT | 0:7fd3327ceec4 | 22 | // FIXED! True = CCW, Flase = CW |
ThomBMT | 0:7fd3327ceec4 | 23 | PwmPin2 = fabs(v); |
ThomBMT | 0:7fd3327ceec4 | 24 | } |
ThomBMT | 0:7fd3327ceec4 | 25 | } |