00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __ENKI_ASEBA_MARXBOT_H
00025 #define __ENKI_ASEBA_MARXBOT_H
00026
00027 #include <enki/robots/marxbot/Marxbot.h>
00028 #ifndef ASEBA_ASSERT
00029 #define ASEBA_ASSERT
00030 #endif
00031 #include "../../vm/vm.h"
00032 #include "../../common/consts.h"
00033 #include <dashel/dashel.h>
00034 #include <deque>
00035 #include <string.h>
00036
00041 namespace Enki
00042 {
00043
00045
00053 class AsebaMarxbot : public Marxbot, public Dashel::Hub
00054 {
00055 public:
00056 struct Event
00057 {
00058 unsigned short source;
00059 std::valarray<unsigned char> data;
00060
00061 Event(unsigned short source, const uint8* data, uint16 length) :
00062 source(source),
00063 data(length)
00064 {
00065 memcpy(&this->data[0], data, length);
00066 }
00067
00068 Event(Dashel::Stream* stream)
00069 {
00070 uint16 len;
00071 stream->read(&len, 2);
00072 stream->read(&source, 2);
00073 data.resize(len+2);
00074 stream->read(&data[0], data.size());
00075 }
00076 };
00077
00078 struct Module
00079 {
00080 Module();
00081
00082 AsebaVMState vm;
00083 std::valarray<unsigned short> bytecode;
00084 std::valarray<signed short> stack;
00085
00086
00087 std::deque<Event> events;
00088 };
00089
00090 private:
00091 struct BaseVariables
00092 {
00093 sint16 id;
00094 sint16 source;
00095 sint16 args[32];
00096 };
00097
00098 struct MotorVariables
00099 {
00100 sint16 id;
00101 sint16 source;
00102 sint16 args[32];
00103 sint16 speed;
00104 sint16 odo[2];
00105 sint16 user[220];
00106 };
00107
00108 struct ProximitySensorVariables
00109 {
00110 sint16 id;
00111 sint16 source;
00112 sint16 args[32];
00113 sint16 bumpers[24];
00114 sint16 ground[12];
00115 sint16 user[188];
00116 };
00117
00118 struct DistanceSensorVariables
00119 {
00120 sint16 id;
00121 sint16 source;
00122 sint16 args[32];
00123 sint16 distances[180];
00124 sint16 user[44];
00125 };
00126
00127 MotorVariables leftMotorVariables;
00128 MotorVariables rightMotorVariables;
00129 ProximitySensorVariables proximitySensorVariables;
00130 DistanceSensorVariables distanceSensorVariables;
00131
00132 Module leftMotor;
00133 Module rightMotor;
00134 Module proximitySensors;
00135 Module distanceSensors;
00136
00137 public:
00138
00139 std::vector<Module *> modules;
00140 static int marxbotNumber;
00141
00142 public:
00143
00145 AsebaMarxbot();
00147 virtual ~AsebaMarxbot();
00149 virtual void controlStep(double dt);
00150
00151 virtual void connectionCreated(Dashel::Stream *stream);
00152 virtual void incomingData(Dashel::Stream *stream);
00153 virtual void connectionClosed(Dashel::Stream *stream, bool abnormal);
00154
00155
00156 Dashel::Stream* stream;
00157 };
00158
00159 }
00160 #endif
00161