Utilities classes for the Zumo Robot
Dependents: ZumoRobotBluetoothControlled Fsl_Zumo
This library represents some useful code for controlling your Zumo Robot.
ZumoRobotManager.cpp
- Committer:
- catalincraciun7
- Date:
- 2014-11-27
- Revision:
- 4:dcd52a961392
- Parent:
- 3:b1fde0759c94
- Child:
- 5:5e12111ef01f
File content as of revision 4:dcd52a961392:
// Craciun Catalin // ZumoRobotManager.cpp // © 2014 Catalin Craciun #ifndef ZumoRobotManagerCpp #define ZumoRobotManagerCpp #include "ZumoRobotManager.h" #include "mbed.h" #define maxEngPow 100 // The maximum engine power Serial console(USBTX, USBRX); ZumoRobotManager::ZumoRobotManager() { // Initialising this -> velocityX = 0; this -> velocityY = 0; } ZumoRobotManager::~ZumoRobotManager() { // Deinitialising } 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) { if (this -> velocityY != newValue) { this -> velocityY = newValue; this -> updateMotors(); } } bool ZumoRobotManager::checkPassword(char toCheck[]) { if (toCheck[0] == '8' && toCheck[1] == '1' && toCheck[2] == '1' && toCheck[3] == '1' && toCheck[4] == '$') return true; return false; } void ZumoRobotManager::updateMotors() { float powerLeftEngine = 0; float powerRightEngine = 0; float dist = sqrt(velocityX*velocityX + velocityY*velocityY); if (velocityX >= 0 && velocityY >= 0) { // First chart powerLeftEngine = dist * (float)maxEngPow; powerRightEngine = powerLeftEngine * (1 - velocityX); } else if (velocityX < 0 && velocityY >= 0) { // Second chart powerRightEngine = dist * (float)maxEngPow; powerLeftEngine = powerRightEngine * (1 + velocityX); } else if (velocityX < 0 && velocityY < 0) { // Third chart powerRightEngine = dist * (float)maxEngPow; powerLeftEngine = powerRightEngine * (1 + velocityX); powerRightEngine = -powerRightEngine; powerLeftEngine = -powerLeftEngine; } else if (velocityX >= 0 && velocityY < 0) { // Fourth chart powerLeftEngine = dist * (float)maxEngPow; powerRightEngine = powerLeftEngine * (1 - velocityX); powerLeftEngine = -powerLeftEngine; powerRightEngine = -powerRightEngine; } // Do whatever you want with these powers } #endif // ZumoRobotManagerCpp