Roboid Control for C++ 0.4
Loading...
Searching...
No Matches
D:/Cpp/RoboidControl-cpp/Thing.h
1#pragma once
2
3#if !defined(NO_STD)
4#include <iostream>
5#include <list>
6#endif
7#include "LinearAlgebra/Spherical.h"
8#include "LinearAlgebra/SwingTwist.h"
9
10namespace RoboidControl {
11
12class Participant;
13class ParticipantUDP;
14
15#define THING_STORE_SIZE 256
16// IMPORTANT: values higher than 256 will need to change the Thing::id type
17// to 16-bit or higher, breaking the networking protocol!
18
20class Thing {
21 public:
23 struct Type {
24 static const unsigned char Undetermined = 0x00;
25 // Sensor
26 static const unsigned char Switch = 0x01;
27 static const unsigned char DistanceSensor = 0x02;
28 static const unsigned char DirectionalSensor = 0x03;
29 static const unsigned char TemperatureSensor = 0x04;
30 static const unsigned char TouchSensor = 0x05;
31 // Motor
32 static const unsigned char ControlledMotor = 0x06;
33 static const unsigned char UncontrolledMotor = 0x07;
34 static const unsigned char Servo = 0x08;
35 static const unsigned char RelativeEncoder = 0x19;
36 // Other
37 static const unsigned char Root = 0x10;
38 static const unsigned char Roboid = 0x09;
39 static const unsigned char Humanoid = 0x0A;
40 static const unsigned char ExternalSensor = 0x08;
41 static const unsigned char Animator = 0x0C;
42 static const unsigned char DifferentialDrive = 0x0D;
43 };
44
45#pragma region Init
46
47 private:
48 public:
54 Thing(Thing* parent = LocalRoot());
55
56 private:
61 Thing(Participant* owener);
62
63 public:
65 ~Thing();
66
69 static void CreateRoot(Participant* owner);
70
73 static Thing* LocalRoot();
74
75#pragma endregion Init
76
77 public:
79 bool terminate = false;
80
81#pragma region Properties
82
83 public:
85 unsigned char id = 0;
86
89 unsigned char type = Type::Undetermined;
90
92 Participant* owner = nullptr;
93
95 const char* name = nullptr;
96
97 void SetName(const char* name);
98 const char* GetName() const;
99 bool nameChanged = false;
100
106 void SetModel(const char* url);
107
110 const char* modelUrl = nullptr;
111
112#pragma endregion Properties
113
114#pragma region Hierarchy
115
118 void SetParent(Thing* parent);
121 Thing* GetParent();
122
125 bool IsRoot() const;
126
128 unsigned char childCount = 0;
132 Thing* GetChildByIndex(unsigned char ix);
133
137 virtual void AddChild(Thing* child);
141 Thing* RemoveChild(Thing* child);
142
147 Thing* GetChild(unsigned char id, bool recurse = false);
148
153 Thing* FindChild(const char* name, bool recurse = true);
154
156 bool hierarchyChanged = true;
157
158 private:
159 Thing* parent = nullptr;
160 Thing** children = nullptr;
161
162#pragma endregion Hierarchy
163
164#pragma region Pose
165
166 public:
169 void SetPosition(Spherical position);
172 Spherical GetPosition();
174 bool positionUpdated = false;
175
178 void SetOrientation(SwingTwist orientation);
181 SwingTwist GetOrientation();
183 bool orientationUpdated = false;
184
188 void SetLinearVelocity(Spherical linearVelocity);
191 virtual Spherical GetLinearVelocity();
194
197 virtual void SetAngularVelocity(Spherical angularVelocity);
200 virtual Spherical GetAngularVelocity();
203
204 private:
208 Spherical position;
212 SwingTwist orientation;
213
216 Spherical linearVelocity;
219 Spherical angularVelocity;
220
221#pragma endregion Pose
222
223#pragma region Update
224
225 public:
226 virtual void PrepareForUpdate();
227
230 virtual void Update(bool recurse = false);
231
234 static unsigned long GetTimeMs();
235
236#pragma endregion Update
237
238 public:
243 virtual int GenerateBinary(char* buffer, unsigned char* ix);
246 virtual void ProcessBinary(char* bytes);
247};
248
249} // namespace RoboidControl
A motor with speed control It uses a feedback loop from an encoder to regulate the speed The speed is...
Definition ControlledMotor.h:11
A thing which can move itself using a differential drive system.
Definition DifferentialDrive.h:11
A participant is a device which manages things. It can communicate with other participant to synchron...
Definition Participant.h:62
An Incremental Encoder measures the rotations of an axle using a rotary sensor. Some encoders are abl...
Definition RelativeEncoder.h:10
A temperature sensor.
Definition TemperatureSensor.h:8
A thing is the primitive building block.
Definition Thing.h:20
virtual Spherical GetLinearVelocity()
Get the linear velocity of the thing.
Definition Thing.cpp:225
bool angularVelocityUpdated
Boolean indicating the thing has an updated angular velocity.
Definition Thing.h:202
void SetModel(const char *url)
Sets the location from where the 3D model of this Thing can be loaded from.
Definition Thing.cpp:87
virtual void Update(bool recurse=false)
Updates the state of the thing.
Definition Thing.cpp:262
void SetPosition(Spherical position)
Set the position of the thing.
Definition Thing.cpp:201
void SetParent(Thing *parent)
Sets the parent of this Thing.
Definition Thing.cpp:93
Thing * GetChildByIndex(unsigned char ix)
Get a child by index.
Definition Thing.cpp:112
SwingTwist GetOrientation()
Get the orientation of the thing.
Definition Thing.cpp:214
void SetOrientation(SwingTwist orientation)
Set the orientation of the thing.
Definition Thing.cpp:209
virtual void AddChild(Thing *child)
Add a child Thing to this Thing.
Definition Thing.cpp:116
Spherical GetPosition()
Get the position of the thing.
Definition Thing.cpp:205
Thing * GetParent()
Gets the parent of this Thing.
Definition Thing.cpp:108
bool linearVelocityUpdated
Boolean indicating the thing has an updated linear velocity.
Definition Thing.h:193
bool terminate
Terminated things are no longer updated.
Definition Thing.h:79
bool IsRoot() const
Check if this is a root thing.
Definition Thing.cpp:104
virtual void ProcessBinary(char *bytes)
Function used to process binary data received for this thing.
Definition Thing.cpp:288
virtual void SetAngularVelocity(Spherical angularVelocity)
Set the angular velocity of the thing.
Definition Thing.cpp:229
void SetLinearVelocity(Spherical linearVelocity)
Set the linear velocity of the thing.
Definition Thing.cpp:218
~Thing()
Destructor for a Thing.
Definition Thing.cpp:72
bool hierarchyChanged
Indicator that the hierarchy of the thing has changed.
Definition Thing.h:156
virtual Spherical GetAngularVelocity()
Get the angular velocity of the thing.
Definition Thing.cpp:236
bool positionUpdated
Boolean indicating that the thing has an updated position.
Definition Thing.h:174
const char * name
The name of the thing.
Definition Thing.h:95
Thing * RemoveChild(Thing *child)
Remove the given thing as a child of this thing.
Definition Thing.cpp:139
Thing * GetChild(unsigned char id, bool recurse=false)
Get a child by thing Id.
Definition Thing.cpp:164
bool orientationUpdated
Boolean indicating the thing has an updated orientation.
Definition Thing.h:183
static unsigned long GetTimeMs()
Get the current time in milliseconds.
Definition Thing.cpp:244
Participant * owner
The participant owning this thing.
Definition Thing.h:92
virtual int GenerateBinary(char *buffer, unsigned char *ix)
Function used to generate binary data for this thing.
Definition Thing.cpp:283
unsigned char childCount
The number of children.
Definition Thing.h:128
Thing * FindChild(const char *name, bool recurse=true)
Find a thing by name.
Definition Thing.cpp:181
static Thing * LocalRoot()
The root thing for the local participant.
Definition Thing.cpp:23
unsigned char type
The type of Thing This can be either a Thing::Type of a byte value for custom types.
Definition Thing.h:89
static void CreateRoot(Participant *owner)
Create a root thing for a participant.
Definition Thing.cpp:48
const char * modelUrl
An URL pointing to the location where a model of the thing can be found.
Definition Thing.h:110
A sensor which can detect touches.
Definition TouchSensor.h:8
Predefined thing types.
Definition Thing.h:23