From d22cf4b33b7e9a3de5e4e3cb8aec617f739c465a Mon Sep 17 00:00:00 2001 From: masterm Date: Sun, 14 Jan 2007 18:07:03 +0000 Subject: +++ added soccer robot framework --- source/Concept/Concept.vcproj | 208 ++++++++++++++++++++++++++++++++++++++++++ source/Concept/defines.h | 91 ++++++++++++++++++ source/Concept/engine.cpp | 1 + source/Concept/engine.h | 19 ++++ source/Concept/io_module.cpp | 1 + source/Concept/io_module.h | 29 ++++++ source/Concept/main.cpp | 47 ++++++++++ source/Concept/module.cpp | 0 source/Concept/module.h | 0 source/Concept/robot.cpp | 37 ++++++++ source/Concept/robot.h | 46 ++++++++++ source/Concept/sensor.cpp | 1 + source/Concept/sensor.h | 29 ++++++ source/Concept/stdafx.h | 12 +++ source/RoboCode.sln | 21 +++++ 15 files changed, 542 insertions(+) create mode 100644 source/Concept/Concept.vcproj create mode 100644 source/Concept/defines.h create mode 100644 source/Concept/engine.cpp create mode 100644 source/Concept/engine.h create mode 100644 source/Concept/io_module.cpp create mode 100644 source/Concept/io_module.h create mode 100644 source/Concept/main.cpp create mode 100644 source/Concept/module.cpp create mode 100644 source/Concept/module.h create mode 100644 source/Concept/robot.cpp create mode 100644 source/Concept/robot.h create mode 100644 source/Concept/sensor.cpp create mode 100644 source/Concept/sensor.h create mode 100644 source/Concept/stdafx.h create mode 100644 source/RoboCode.sln diff --git a/source/Concept/Concept.vcproj b/source/Concept/Concept.vcproj new file mode 100644 index 0000000..61c34c2 --- /dev/null +++ b/source/Concept/Concept.vcproj @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/Concept/defines.h b/source/Concept/defines.h new file mode 100644 index 0000000..698163a --- /dev/null +++ b/source/Concept/defines.h @@ -0,0 +1,91 @@ +#ifndef _DEFINES_H +#define _DEFINES_H + +#ifndef NULL +#define NULL 0 +#endif + +//Integer definition +#ifndef int8 + #ifdef __int8 + #define int8 __int8 + #else + #define int8 char + #endif +#endif + +#ifndef int16 + #ifdef __int16 + #define int16 __int16 + #else + #define int16 int + #endif +#endif + +#ifndef int32 + #ifdef __int32 + #define int32 __int32 + #else + #define int32 long + #endif +#endif + +#ifndef int64 + #ifdef __int64 + #define int64 __int64 + #else + #define int64 long long + #endif +#endif + +//Unsigned +#ifndef uint8 +#define uint8 unsigned int8 +#endif + +#ifndef uint16 +#define uint16 unsigned int16 +#endif + +#ifndef uint32 +#define uint32 unsigned int32 +#endif + +#ifndef uint64 +#define uint64 unsigned int64 +#endif + +//Sensor types +enum SensorTypes +{ + SENSOR_TYPE_ANALOG, + SENSOR_TYPE_DIGITAL, +}; + +//IO Module Names +enum IOModuleNames +{ + //General + IO_START, + + //Engines + IO_ENGINE_START = IO_START, + + IO_ENGINE_DRIVE_LEFT = IO_ENGINE_START, + IO_ENGINE_DRIVE_RIGHT, + IO_ENGINE_DRIVE_BACK, + + IO_ENGINE_END, + + //Sensors + IO_SENSOR_START = IO_ENGINE_END, + + IO_SENSOR_MOUSE = IO_SENSOR_START, + + IO_SENSOR_END, + + //General + IO_END = IO_SENSOR_END, +}; + +#endif \ No newline at end of file diff --git a/source/Concept/engine.cpp b/source/Concept/engine.cpp new file mode 100644 index 0000000..11856cc --- /dev/null +++ b/source/Concept/engine.cpp @@ -0,0 +1 @@ +#include "engine.h" \ No newline at end of file diff --git a/source/Concept/engine.h b/source/Concept/engine.h new file mode 100644 index 0000000..406d46e --- /dev/null +++ b/source/Concept/engine.h @@ -0,0 +1,19 @@ +#ifndef _ENGINE_H +#define _ENGINE_H + +#include "stdafx.h" + +class Engine : public IO_Module +{ +public: + Engine() + { + } + + Engine(uint32 engineId) + { + this->moduleId = engineId; + } +}; + +#endif \ No newline at end of file diff --git a/source/Concept/io_module.cpp b/source/Concept/io_module.cpp new file mode 100644 index 0000000..93f78ae --- /dev/null +++ b/source/Concept/io_module.cpp @@ -0,0 +1 @@ +#include "io_module.h" \ No newline at end of file diff --git a/source/Concept/io_module.h b/source/Concept/io_module.h new file mode 100644 index 0000000..8aa7ef7 --- /dev/null +++ b/source/Concept/io_module.h @@ -0,0 +1,29 @@ +#ifndef _MODULE_H +#define _MODULE_H + +#include "defines.h" + +class IO_Module +{ +public: + IO_Module(uint32 moduleId) + { + this->moduleId = moduleId; + } + + IO_Module(){} + +protected: + uint32 moduleId; + +public: + + uint32 GetId() + { + return moduleId; + } + + +}; + +#endif \ No newline at end of file diff --git a/source/Concept/main.cpp b/source/Concept/main.cpp new file mode 100644 index 0000000..6305a1e --- /dev/null +++ b/source/Concept/main.cpp @@ -0,0 +1,47 @@ +#include "stdafx.h" + +int main() +{ + //Init our robot + Robot* localRobot = new Robot(); + + //Init Engines + for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++) + { + Engine* newEngine = new Engine(i); + localRobot->AddModule(newEngine); + newEngine = NULL; + } + + //Init Sensors + for(uint8 i = IO_SENSOR_START; i < IO_SENSOR_END; i++) + { + SensorTypes newSensorType; + + switch(i) + { + //Cases when sensor is digital: + // newSensorType = SENSOR_TYPE_DIGITAL; + // break; + + //Other cases + default: + newSensorType = SENSOR_TYPE_ANALOG; + break; + } + + Sensor* newSensor = new Sensor(i, newSensorType); + localRobot->AddModule(newSensor); + newSensor = NULL; + } + + //Run + while(true) + { + localRobot->Update(); + } + + //Cleanup + delete localRobot; + localRobot = NULL; +} \ No newline at end of file diff --git a/source/Concept/module.cpp b/source/Concept/module.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Concept/module.h b/source/Concept/module.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Concept/robot.cpp b/source/Concept/robot.cpp new file mode 100644 index 0000000..768554e --- /dev/null +++ b/source/Concept/robot.cpp @@ -0,0 +1,37 @@ +#include "robot.h" + +//----------------------------------------------------------------------------- +Robot::~Robot() +{ + while(!modules.empty()) + { + moduleMap::iterator iter = modules.begin(); + delete iter->second; + modules.erase(iter); + } +} + +//----------------------------------------------------------------------------- +bool Robot::AddModule(IO_Module* newModule) +{ + moduleMap::iterator itr = modules.find(newModule->GetId()); + if(itr != modules.end()) + return false; + + modules[newModule->GetId()] = newModule; + return true; +} + +//----------------------------------------------------------------------------- +bool Robot::RemoveModule(IO_Module* oldModule) +{ + return RemoveModule(oldModule->GetId()); +} + +//----------------------------------------------------------------------------- +void Robot::Update() +{ + //insert code here +} + +//--- EOF --- \ No newline at end of file diff --git a/source/Concept/robot.h b/source/Concept/robot.h new file mode 100644 index 0000000..543f1ed --- /dev/null +++ b/source/Concept/robot.h @@ -0,0 +1,46 @@ +#ifndef _ROBOT_H +#define _ROBOT_H + +#include "stdafx.h" + +class IO_Module; +class Sensor; +class Engine; + +class Robot +{ +public: + ~Robot(); + +private: + typedef hash_map moduleMap; + moduleMap modules; + +public: + bool AddModule(IO_Module* newModule); + + template T* GetModule(uint32 moduleId) + { + moduleMap::const_iterator itr = modules.find(moduleId); + if(itr == modules.end()) + return NULL; + else + return ((T*)itr->second); + } + + bool RemoveModule(uint32 moduleId) + { + moduleMap::iterator itr = modules.find(moduleId); + if(itr == modules.end()) + return false; + + modules.erase(itr); + return true; + } + + bool RemoveModule(IO_Module* oldModule); + + void Update(); +}; + +#endif \ No newline at end of file diff --git a/source/Concept/sensor.cpp b/source/Concept/sensor.cpp new file mode 100644 index 0000000..b9b4936 --- /dev/null +++ b/source/Concept/sensor.cpp @@ -0,0 +1 @@ +#include "sensor.h" \ No newline at end of file diff --git a/source/Concept/sensor.h b/source/Concept/sensor.h new file mode 100644 index 0000000..23e40e9 --- /dev/null +++ b/source/Concept/sensor.h @@ -0,0 +1,29 @@ +#ifndef _SENSOR_H +#define _SENSOR_H + +#include "stdafx.h" + +class Sensor : public IO_Module +{ +public: + Sensor() + { + } + + Sensor(uint32 sensorId, SensorTypes sensorType) + { + this->moduleId = sensorId; + this->sensorType = sensorType; + } + +protected: + SensorTypes sensorType; + +public: + SensorTypes GetType() + { + return sensorType; + } +}; + +#endif \ No newline at end of file diff --git a/source/Concept/stdafx.h b/source/Concept/stdafx.h new file mode 100644 index 0000000..0a5a81e --- /dev/null +++ b/source/Concept/stdafx.h @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +using namespace std; + +#include "defines.h" +#include "io_module.h" +#include "sensor.h" +#include "engine.h" +#include "robot.h" \ No newline at end of file diff --git a/source/RoboCode.sln b/source/RoboCode.sln new file mode 100644 index 0000000..59f2d66 --- /dev/null +++ b/source/RoboCode.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Concept", "Concept\Concept.vcproj", "{556125BE-937F-4A2B-89C7-B086575BE0F0}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {556125BE-937F-4A2B-89C7-B086575BE0F0}.Debug.ActiveCfg = Debug|Win32 + {556125BE-937F-4A2B-89C7-B086575BE0F0}.Debug.Build.0 = Debug|Win32 + {556125BE-937F-4A2B-89C7-B086575BE0F0}.Release.ActiveCfg = Release|Win32 + {556125BE-937F-4A2B-89C7-B086575BE0F0}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal -- cgit v1.2.3