Utilities classes for the Zumo Robot
Dependents: ZumoRobotBluetoothControlled Fsl_Zumo
This library represents some useful code for controlling your Zumo Robot.
Revision 7:d2af97b7cc94, committed 2017-07-23
- Comitter:
- catalincraciun7
- Date:
- Sun Jul 23 12:51:35 2017 +0000
- Parent:
- 6:7740c9d8d834
- Commit message:
- Minor changes to code style;
Changed in this revision
diff -r 7740c9d8d834 -r d2af97b7cc94 Buzzer.cpp --- a/Buzzer.cpp Sun Dec 21 12:46:41 2014 +0000 +++ b/Buzzer.cpp Sun Jul 23 12:51:35 2017 +0000 @@ -2,44 +2,34 @@ // Buzzer.cpp // © 2014 Catalin Craciun -#ifndef BuzzerCpp -#define BuzzerCpp +#include "Buzzer.h" +#define MELODY_LENGTH 5 -#include "Buzzer.h" - -Buzzer::Buzzer(PinName buzzerPinName):buzzerPin(buzzerPinName) -{ - +Buzzer::Buzzer(PinName buzzerPinName):buzzerPin(buzzerPinName) { // Initialising buzzerPin.period_us(0); buzzerPin.pulsewidth_us(0); } -Buzzer::~Buzzer() -{ - +Buzzer::~Buzzer() { // Deinitialising } -void Buzzer::stopBeep() -{ +void Buzzer::stopBeep() { buzzerPin.period_us(0); buzzerPin.pulsewidth_us(0); } -void Buzzer::startBeep(float frequency, float duration) -{ - - buzzerPin.period(1/frequency); +void Buzzer::startBeep(float frequency, float duration) { + buzzerPin.period(1.0f/frequency); buzzerPin.pulsewidth_us(100); timeout.attach(this, &Buzzer::stopBeep, duration); } -void Buzzer::playDefaultMelody() -{ +void Buzzer::playDefaultMelody() { // Playing default melody on buzzer - while (true) { + for (int cycle = 0; cycle < MELODY_LENGTH; cycle++) { buzzerPin.period(16); buzzerPin.pulsewidth_us(200); wait(0.5); @@ -65,5 +55,3 @@ wait(0.5); } } - -#endif // BuzzerCpp \ No newline at end of file
diff -r 7740c9d8d834 -r d2af97b7cc94 Buzzer.h --- a/Buzzer.h Sun Dec 21 12:46:41 2014 +0000 +++ b/Buzzer.h Sun Jul 23 12:51:35 2017 +0000 @@ -9,17 +9,18 @@ class Buzzer { public: - // Public methods and properties Buzzer(PinName buzzerPinName); ~Buzzer(); + void stopBeep(); void startBeep(float frequency, float duration); + void playDefaultMelody(); private: - // Private methods and properties - void playMel(); PwmOut buzzerPin; Timeout timeout; + + void playMel(); }; -#endif // BuzzerH \ No newline at end of file +#endif // BuzzerH
diff -r 7740c9d8d834 -r d2af97b7cc94 ZumoRobotManager.cpp --- a/ZumoRobotManager.cpp Sun Dec 21 12:46:41 2014 +0000 +++ b/ZumoRobotManager.cpp Sun Jul 23 12:51:35 2017 +0000 @@ -2,9 +2,6 @@ // ZumoRobotManager.cpp // © 2014 Catalin Craciun -#ifndef ZumoRobotManagerCpp -#define ZumoRobotManagerCpp - #include "ZumoRobotManager.h" #include "mbed.h" @@ -19,38 +16,41 @@ PwmOut pwmLeft(PTD0); ZumoRobotManager::ZumoRobotManager() { - // Initialising this -> velocityX = 0; this -> velocityY = 0; } ZumoRobotManager::~ZumoRobotManager() { - // Deinitialising - +} + +void ZumoRobotManager::applyPowerToLeftEngine(int power) { + pwmLeft.period_us(60); + pwmLeft.pulsewidth_us(power); +} + +void ZumoRobotManager::applyPowerToRightEngine(int power) { + pwmRight.period_us(60); + pwmRight.pulsewidth_us(power); } float ZumoRobotManager::getVelocityX() { - return this -> velocityX; } float ZumoRobotManager::getVelocityY() { - return this -> velocityY; } void ZumoRobotManager::setVelocityX(float newValue) { - if (this -> velocityX != newValue) { this -> velocityX = newValue; this -> updateMotors(); } } -void ZumoRobotManager::setVelocityY(float newValue) { - +void ZumoRobotManager::setVelocityY(float newValue) { if (this -> velocityY != newValue) { this -> velocityY = newValue; this -> updateMotors(); @@ -58,7 +58,6 @@ } bool ZumoRobotManager::checkPassword(char toCheck[]) { - if (toCheck[0] == '8' && toCheck[1] == '1' && toCheck[2] == '1' && @@ -70,7 +69,6 @@ } void ZumoRobotManager::updateMotors() { - float powerLeftEngine = 0; float powerRightEngine = 0; float dist = sqrt(velocityX*velocityX + velocityY*velocityY); @@ -101,7 +99,6 @@ } // Do whatever you want with these powers - pwmLeft.period_us(60); pwmRight.period_us(60); @@ -121,5 +118,3 @@ pwmRight.pulsewidth_us(-powerRightEngine); } } - -#endif // ZumoRobotManagerCpp \ No newline at end of file
diff -r 7740c9d8d834 -r d2af97b7cc94 ZumoRobotManager.h --- a/ZumoRobotManager.h Sun Dec 21 12:46:41 2014 +0000 +++ b/ZumoRobotManager.h Sun Jul 23 12:51:35 2017 +0000 @@ -7,7 +7,6 @@ class ZumoRobotManager { public: - // Public methods and properties ZumoRobotManager(); ~ZumoRobotManager(); @@ -15,11 +14,13 @@ float getVelocityY(); void setVelocityX(float newValue); void setVelocityY(float newValue); + void applyPowerToRightEngine(int power); + void applyPowerToLeftEngine(int power); bool checkPassword(char toCheck[]); private: - // Private methods and properties float velocityX; float velocityY; + void updateMotors(); };