Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: QEI Motordriver ros_lib_melodic
motor/Motor.cpp@12:817da876ae2f, 2019-11-15 (annotated)
- Committer:
- florine_van
- Date:
- Fri Nov 15 17:38:04 2019 +0000
- Revision:
- 12:817da876ae2f
- Parent:
- 11:35809512ec11
Latest code to use with ROS
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| florine_van | 6:858a5116688e | 1 | #include "mbed.h" |
| florine_van | 6:858a5116688e | 2 | |
| florine_van | 5:8ef79eebbc97 | 3 | #include "Motor.h" |
| florine_van | 5:8ef79eebbc97 | 4 | |
| florine_van | 5:8ef79eebbc97 | 5 | /////////////////////////////////////////////////////////////////// |
| florine_van | 5:8ef79eebbc97 | 6 | // Constructor |
| florine_van | 5:8ef79eebbc97 | 7 | /////////////////////////////////////////////////////////////////// |
| florine_van | 12:817da876ae2f | 8 | Motor::Motor(PinName in1, PinName in2, PinName pwm) |
| florine_van | 12:817da876ae2f | 9 | : in1(in1), in2(in2), pwm(pwm) |
| florine_van | 6:858a5116688e | 10 | { |
| florine_van | 6:858a5116688e | 11 | this->pwm.period_ms(10); |
| florine_van | 6:858a5116688e | 12 | } |
| florine_van | 5:8ef79eebbc97 | 13 | |
| florine_van | 5:8ef79eebbc97 | 14 | /////////////////////////////////////////////////////////////////// |
| florine_van | 5:8ef79eebbc97 | 15 | // Public methods |
| florine_van | 5:8ef79eebbc97 | 16 | /////////////////////////////////////////////////////////////////// |
| florine_van | 12:817da876ae2f | 17 | void Motor::stop() |
| florine_van | 5:8ef79eebbc97 | 18 | { |
| florine_van | 12:817da876ae2f | 19 | in1 = 0; |
| florine_van | 12:817da876ae2f | 20 | in2 = 0; |
| florine_van | 5:8ef79eebbc97 | 21 | } |
| florine_van | 5:8ef79eebbc97 | 22 | |
| florine_van | 12:817da876ae2f | 23 | void Motor::moveForward() |
| florine_van | 12:817da876ae2f | 24 | { |
| florine_van | 12:817da876ae2f | 25 | in1 = 1; |
| florine_van | 12:817da876ae2f | 26 | in2 = 0; |
| florine_van | 11:35809512ec11 | 27 | } |
| florine_van | 11:35809512ec11 | 28 | |
| florine_van | 12:817da876ae2f | 29 | void Motor::moveBackward() |
| florine_van | 12:817da876ae2f | 30 | { |
| florine_van | 12:817da876ae2f | 31 | in1 = 0; |
| florine_van | 12:817da876ae2f | 32 | in2 = 1; |
| florine_van | 5:8ef79eebbc97 | 33 | } |
| florine_van | 5:8ef79eebbc97 | 34 | |
| florine_van | 6:858a5116688e | 35 | void Motor::setSpeed(float speed) |
| florine_van | 5:8ef79eebbc97 | 36 | { |
| florine_van | 6:858a5116688e | 37 | pwm.write(speed); |
| florine_van | 5:8ef79eebbc97 | 38 | } |