Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __ENKI_ASEBA_MARXBOT_H
00022 #define __ENKI_ASEBA_MARXBOT_H
00023
00024 #include <enki/robots/marxbot/Marxbot.h>
00025 #ifndef ASEBA_ASSERT
00026 #define ASEBA_ASSERT
00027 #endif
00028 #include "../../vm/vm.h"
00029 #include "../../common/consts.h"
00030 #include <dashel/dashel.h>
00031 #include <deque>
00032 #include <string.h>
00033
00038 namespace Enki
00039 {
00040
00042
00050 class AsebaMarxbot : public Marxbot, public Dashel::Hub
00051 {
00052 public:
00053 struct Event
00054 {
00055 unsigned short source;
00056 std::valarray<unsigned char> data;
00057
00058 Event(unsigned short source, const uint8* data, uint16 length) :
00059 source(source),
00060 data(length)
00061 {
00062 memcpy(&this->data[0], data, length);
00063 }
00064
00065 Event(Dashel::Stream* stream)
00066 {
00067 uint16 temp;
00068 uint16 len;
00069 stream->read(&temp, 2);
00070 len = bswap16(temp);
00071 stream->read(&temp, 2);
00072 source = bswap16(temp);
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