summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/modules/output/engine.h
diff options
context:
space:
mode:
authorsicarius <devnull@localhost>2007-02-18 01:14:00 +0100
committersicarius <devnull@localhost>2007-02-18 01:14:00 +0100
commit3c3c628b617dc53f0b7b59285c7d67888074c33d (patch)
tree1d1848b37d14036542e7b704440f4eb4f4d8ef7b /source/Concept/Framework/modules/output/engine.h
parent803027cbb45ebe01e4f8b427a7cc95728d6e5f47 (diff)
downloadrc2007-soccer-3c3c628b617dc53f0b7b59285c7d67888074c33d.tar
rc2007-soccer-3c3c628b617dc53f0b7b59285c7d67888074c33d.zip
+++ Additional Codework
Diffstat (limited to 'source/Concept/Framework/modules/output/engine.h')
-rwxr-xr-xsource/Concept/Framework/modules/output/engine.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/source/Concept/Framework/modules/output/engine.h b/source/Concept/Framework/modules/output/engine.h
new file mode 100755
index 0000000..27b9905
--- /dev/null
+++ b/source/Concept/Framework/modules/output/engine.h
@@ -0,0 +1,124 @@
+#ifndef _ENGINE_H
+#define _ENGINE_H
+
+#include "../../stdafx.h"
+
+class Engine : public IO_Module
+{
+public:
+ Engine()
+ {
+ this->enabled = false;
+ this->curSpeed = 0;
+ this->parent = NULL;
+ this->moduleId = 0;
+ this->hardwarePort = NULL;
+ this->pwmSpeed = NULL;
+ this->pinForward = 0;
+ this->pinReverse = 0;
+ }
+
+ Engine(uint32 engineId)
+ {
+ this->enabled = false;
+ this->curSpeed = 0;
+ this->parent = NULL;
+ this->moduleId = engineId;
+
+ switch(engineId)
+ {
+ case IO_ENGINE_DRIVE_LEFT:
+ this->hardwarePort = &PORTB;
+ this->pwmSpeed = &OCR1A;
+ this->pinForward = (1 << 0);
+ this->pinReverse = (1 << 1);
+ break;
+ case IO_ENGINE_DRIVE_BACK:
+ this->hardwarePort = &PORTB;
+ this->pwmSpeed = &OCR1B;
+ this->pinForward = (1 << 2);
+ this->pinReverse = (1 << 3);
+ break;
+ case IO_ENGINE_DRIVE_RIGHT:
+ this->hardwarePort = &PORTD;
+ this->pwmSpeed = &OCR3A;
+ this->pinForward = (1 << 5);
+ this->pinReverse = (1 << 4);
+ break;
+ default:
+ this->hardwarePort = NULL;
+ this->pwmSpeed = NULL;
+ this->pinForward = 0;
+ this->pinReverse = 0;
+ break;
+ }
+
+ *this->pwmSpeed = 0;
+ }
+
+protected:
+ bool enabled;
+ float curSpeed;
+
+ //Hardware
+ volatile uint8* hardwarePort;
+ volatile uint16* pwmSpeed;
+ uint8 pinForward;
+ uint8 pinReverse;
+
+ void UpdateDirection()
+ {
+ if(enabled)
+ {
+ if(curSpeed > 0)
+ {
+ *hardwarePort |= pinForward;
+ *hardwarePort &= ~pinReverse;
+ }
+ else if(curSpeed < 0)
+ {
+ *hardwarePort |= pinReverse;
+ *hardwarePort &= ~pinForward;
+ }
+ else
+ {
+ *hardwarePort |= pinForward;
+ *hardwarePort |= pinReverse;
+ }
+ }
+ else
+ {
+ *hardwarePort &= ~pinForward;
+ *hardwarePort &= ~pinReverse;
+ }
+ }
+
+public:
+ float GetSpeed()
+ {
+ return curSpeed;
+ }
+
+ void SetSpeed(float newSpeed)
+ {
+ curSpeed = newSpeed;
+
+ *pwmSpeed = (abs((int16)(newSpeed / SPEED_PER_PWM)));
+
+ UpdateDirection();
+ }
+
+ bool GetEnabled()
+ {
+ return enabled;
+ }
+
+ void SetEnabled(bool newStatus)
+ {
+ enabled = newStatus;
+
+ UpdateDirection();
+ }
+};
+
+#endif