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
- Committer:
- Xiaofei
- Date:
- 2015-11-28
- Revision:
- 5:0032e2f8949c
- Parent:
- 4:3fbe2d75f7eb
- Child:
- 6:bbaabcc5206d
File content as of revision 5:0032e2f8949c:
#pragma once
#include "Command.h"
#include "mbed.h"
#include "Motor.h"
Motor _LEFT_WHEEL(p25, p6, p5); // Motor A pwm, fwd, rev
Motor _RIGHT_WHEEL(p26, p7, p8); // Motor B pwm, fwd, rev
DigitalOut _STBY(p12); // Set STBY = 1, enable both motor; Set STBY = 0; disable both motor.
AnalogIn _IR(p17); // IR sensor
DigitalOut _LED1(LED1);
DigitalIn _LEFT_ENCODER(p19);
DigitalIn _RIGHT_ENCODER(p20);
Command::Command():_SPEED(0),_IS_NEGATIVE(0)
{}
void Command::setSpeed(const std::int8_t& sp, const std::int8_t& is_negative)
{
_STBY = 1;
_SPEED = sp * 0.33;
_IS_NEGATIVE = is_negative;
}
void LedCommand :: execute()
{
_LED1 = !_LED1;
}
void TurnLeftCommand :: execute()
{
_STBY = 1;
if(_IS_NEGATIVE)
{
_RIGHT_WHEEL.speed(-_SPEED);
_LEFT_WHEEL.speed(-_SPEED*0.72);
}
else
{
_RIGHT_WHEEL.speed(_SPEED);
_LEFT_WHEEL.speed(_SPEED*0.72);
}
}
void TurnRightCommand :: execute()
{
_STBY = 1;
if(_IS_NEGATIVE)
{
_RIGHT_WHEEL.speed(-_SPEED*0.72);
_LEFT_WHEEL.speed(-_SPEED);
}
else
{
_RIGHT_WHEEL.speed(_SPEED*0.72);
_LEFT_WHEEL.speed(_SPEED);
}
}
void StopCommand :: execute()
{
_RIGHT_WHEEL.speed(0.0);
_LEFT_WHEEL.speed(0.0);
_STBY = 0;
}