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.
Command.cpp@1:13c4bf8989d5, 2015-11-22 (annotated)
- Committer:
- Xiaofei
- Date:
- Sun Nov 22 01:04:17 2015 +0000
- Revision:
- 1:13c4bf8989d5
- Parent:
- 0:4bc34a5fcc29
- Child:
- 2:3d1c13d63966
Commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Xiaofei | 0:4bc34a5fcc29 | 1 | #pragma once |
| Xiaofei | 0:4bc34a5fcc29 | 2 | #include "Command.h" |
| Xiaofei | 0:4bc34a5fcc29 | 3 | #include "mbed.h" |
| Xiaofei | 1:13c4bf8989d5 | 4 | #include "Motor.h" |
| Xiaofei | 0:4bc34a5fcc29 | 5 | |
| Xiaofei | 1:13c4bf8989d5 | 6 | Motor _RIGHT_WHEEL(p25, p6, p5); // Motor A pwm, fwd, rev |
| Xiaofei | 1:13c4bf8989d5 | 7 | Motor _LEFT_WHEEL(p26, p7, p8);//Motor B pwm, fwd, rev |
| Xiaofei | 1:13c4bf8989d5 | 8 | DigitalOut _STBY(p11); // Set STBY = 1, enable both motor; Set STBY = 0; disable both motor. |
| Xiaofei | 1:13c4bf8989d5 | 9 | AnalogIn _IR(p17); //IR sensor |
| Xiaofei | 1:13c4bf8989d5 | 10 | DigitalOut _LED1(LED1); |
| Xiaofei | 1:13c4bf8989d5 | 11 | |
| Xiaofei | 1:13c4bf8989d5 | 12 | DigitalIn _LEFT_ENCODER(p19); |
| Xiaofei | 1:13c4bf8989d5 | 13 | DigitalIn _RIGHT_ENCODER(p20); |
| Xiaofei | 0:4bc34a5fcc29 | 14 | |
| Xiaofei | 1:13c4bf8989d5 | 15 | Serial pc(USBTX,USBRX); |
| Xiaofei | 1:13c4bf8989d5 | 16 | |
| Xiaofei | 1:13c4bf8989d5 | 17 | Command::Command():_LEFT_SPEED(0),_RIGHT_SPEED(0) |
| Xiaofei | 1:13c4bf8989d5 | 18 | {} |
| Xiaofei | 1:13c4bf8989d5 | 19 | |
| Xiaofei | 1:13c4bf8989d5 | 20 | void Command::setSpeed(const std::int8_t& l_sp,const std::int8_t& r_sp) |
| Xiaofei | 1:13c4bf8989d5 | 21 | { |
| Xiaofei | 1:13c4bf8989d5 | 22 | _STBY = 1; |
| Xiaofei | 1:13c4bf8989d5 | 23 | _LEFT_SPEED = l_sp; |
| Xiaofei | 1:13c4bf8989d5 | 24 | _RIGHT_SPEED = r_sp; |
| Xiaofei | 1:13c4bf8989d5 | 25 | } |
| Xiaofei | 0:4bc34a5fcc29 | 26 | |
| Xiaofei | 0:4bc34a5fcc29 | 27 | void LedCommand :: execute() |
| Xiaofei | 0:4bc34a5fcc29 | 28 | { |
| Xiaofei | 1:13c4bf8989d5 | 29 | _LED1 = !_LED1; |
| Xiaofei | 0:4bc34a5fcc29 | 30 | } |
| Xiaofei | 0:4bc34a5fcc29 | 31 | |
| Xiaofei | 0:4bc34a5fcc29 | 32 | void TurnLeftCommand :: execute() |
| Xiaofei | 0:4bc34a5fcc29 | 33 | { |
| Xiaofei | 1:13c4bf8989d5 | 34 | _STBY = 1; |
| Xiaofei | 1:13c4bf8989d5 | 35 | _RIGHT_WHEEL.speed(_RIGHT_SPEED); |
| Xiaofei | 1:13c4bf8989d5 | 36 | _LEFT_WHEEL.speed(_LEFT_SPEED); |
| Xiaofei | 0:4bc34a5fcc29 | 37 | } |
| Xiaofei | 0:4bc34a5fcc29 | 38 | |
| Xiaofei | 0:4bc34a5fcc29 | 39 | void TurnRightCommand :: execute() |
| Xiaofei | 0:4bc34a5fcc29 | 40 | { |
| Xiaofei | 1:13c4bf8989d5 | 41 | _STBY = 1; |
| Xiaofei | 1:13c4bf8989d5 | 42 | _RIGHT_WHEEL.speed(_RIGHT_SPEED); |
| Xiaofei | 1:13c4bf8989d5 | 43 | _LEFT_WHEEL.speed(_LEFT_SPEED); |
| Xiaofei | 0:4bc34a5fcc29 | 44 | } |
| Xiaofei | 0:4bc34a5fcc29 | 45 | |
| Xiaofei | 0:4bc34a5fcc29 | 46 | void MoveForwardCommand :: execute() |
| Xiaofei | 0:4bc34a5fcc29 | 47 | { |
| Xiaofei | 1:13c4bf8989d5 | 48 | _STBY = 1; |
| Xiaofei | 1:13c4bf8989d5 | 49 | _RIGHT_WHEEL.speed(0.5); |
| Xiaofei | 1:13c4bf8989d5 | 50 | _LEFT_WHEEL.speed(0.5); |
| Xiaofei | 0:4bc34a5fcc29 | 51 | } |
| Xiaofei | 0:4bc34a5fcc29 | 52 | |
| Xiaofei | 0:4bc34a5fcc29 | 53 | void MoveBackwardCommand :: execute() |
| Xiaofei | 0:4bc34a5fcc29 | 54 | { |
| Xiaofei | 1:13c4bf8989d5 | 55 | |
| Xiaofei | 1:13c4bf8989d5 | 56 | _STBY = 1; |
| Xiaofei | 1:13c4bf8989d5 | 57 | _RIGHT_WHEEL.speed(_RIGHT_SPEED); |
| Xiaofei | 1:13c4bf8989d5 | 58 | _LEFT_WHEEL.speed(_LEFT_SPEED); |
| Xiaofei | 0:4bc34a5fcc29 | 59 | } |
| Xiaofei | 0:4bc34a5fcc29 | 60 | |
| Xiaofei | 0:4bc34a5fcc29 | 61 | void StopCommand :: execute() |
| Xiaofei | 0:4bc34a5fcc29 | 62 | { |
| Xiaofei | 1:13c4bf8989d5 | 63 | _RIGHT_WHEEL.speed(_RIGHT_SPEED); |
| Xiaofei | 1:13c4bf8989d5 | 64 | _LEFT_WHEEL.speed(_LEFT_SPEED); |
| Xiaofei | 0:4bc34a5fcc29 | 65 | } |
| Xiaofei | 0:4bc34a5fcc29 | 66 |