Roboid Control for C++
Loading...
Searching...
No Matches
d:/Cpp/RoboidControl/Thing.h
1#pragma once
2#include <iostream>
3#include <list>
4#include "LinearAlgebra/Spherical.h"
5#include "LinearAlgebra/SwingTwist.h"
6
7namespace RoboidControl {
8
9class Participant;
10class LocalParticipant;
11
12#define THING_STORE_SIZE 256
13// IMPORTANT: values higher than 256 will need to change the Thing::id type
14// to 16-bit or higher, breaking the networking protocol!
15
16#pragma region Types
17
19class Thing {
20 public:
22 enum Type {
23 Undetermined,
24 // Sensor,
25 Switch,
26 DistanceSensor,
27 DirectionalSensor,
30 // Motor,
31 ControlledMotor,
32 UncontrolledMotor,
33 Servo,
34 // Other
35 Roboid,
36 Humanoid,
37 ExternalSensor,
38 };
39
40// Types
41#pragma endregion
42
43#pragma region Init
44
47 Thing(int thingType = Type::Undetermined);
51 Thing(Participant* participant, Type thingType = Type::Undetermined);
55 Thing(Participant* participant, int thingType);
61 Thing(Participant* participant, unsigned char networkId, unsigned char thingId, Type thingType = Type::Undetermined);
62
63// Init
64#pragma endregion
65
66#pragma region Properties
67
69 Participant* owner = nullptr;
72 unsigned char networkId = 0;
74 unsigned char id = 0;
75
78 unsigned char type = Type::Undetermined;
79
83 virtual void SetParent(Thing* parent);
87 // void SetParent(Thing* root, const char* name);
88
89 protected:
90 Thing* parent = nullptr;
91
92 public:
96 virtual void AddChild(Thing* child);
100 bool RemoveChild(Thing* child);
101
103 unsigned char childCount = 0;
108 Thing* GetChild(unsigned char thingId, bool recursively = false);
112 // Thing* GetChildByIndex(unsigned char ix);
117 Thing* FindChild(const char* name, bool recursively = true);
118
119 protected:
121 Thing** children = nullptr;
122
123 public:
125 const char* name = nullptr;
127 const char* modelUrl = nullptr;
129 // float modelScale = 1;
130
131 public:
134 void SetPosition(Spherical position);
137 Spherical GetPosition();
139 bool positionUpdated = false;
140
141 private:
145 Spherical position;
146
147 public:
150 void SetOrientation(SwingTwist16 orientation);
153 SwingTwist16 GetOrientation();
155 // float scale = 1; // assuming uniform scale
157 bool orientationUpdated = false;
158
159 private:
163 SwingTwist16 orientation;
164
165 public:
168 void SetLinearVelocity(Spherical linearVelocity);
171 virtual Spherical GetLinearVelocity();
172 bool linearVelocityUpdated = false;
173
174 private:
176 Spherical linearVelocity;
177
178 public:
181 virtual void SetAngularVelocity(Spherical angularVelocity);
184 virtual Spherical GetAngularVelocity();
185 bool angularVelocityUpdated = false;
186
187 private:
189 Spherical angularVelocity;
190
191 // Properties
192#pragma endregion
193
194#pragma region Methods
195
196 public:
197 static unsigned long GetTimeMs(); // Move to TimeManager like in C#?
198
201 void Update(bool recursively = false);
205 virtual void Update(unsigned long currentTimeMs, bool recursively = false); // { (void)currentTimeMs; };
206
207 static void UpdateThings(unsigned long currentTimeMs);
208
212 virtual void GenerateBinary(char* buffer, unsigned char* ix);
215 virtual void ProcessBinary(char* bytes);
216
217// Methods
218#pragma endregion
219};
220
221} // namespace RoboidControl
A participant is a device which manages things. It can communicate with other participant to synchron...
Definition Participant.h:11
A temperature sensor.
Definition TemperatureSensor.h:8
A thing is the primitive building block.
Definition Thing.h:19
virtual Spherical GetLinearVelocity()
Get the linear velocity of the thing.
Definition Thing.cpp:222
void SetPosition(Spherical position)
The scale of the model (deprecated I think)
Definition Thing.cpp:200
virtual void SetParent(Thing *parent)
Sets the parent Thing.
Definition Thing.cpp:53
Thing * FindChild(const char *name, bool recursively=true)
Get a child by index.
Definition Thing.cpp:142
virtual void AddChild(Thing *child)
Add a child Thing to this Thing.
Definition Thing.cpp:73
Spherical GetPosition()
Get the position of the thing.
Definition Thing.cpp:204
Thing * GetParent()
Gets the parent Thing.
Definition Thing.cpp:69
Thing * GetChild(unsigned char thingId, bool recursively=false)
Get a child by thing Id.
Definition Thing.cpp:121
Thing ** children
The children of this thing.
Definition Thing.h:121
SwingTwist16 GetOrientation()
Get the orientation of the thing.
Definition Thing.cpp:213
void SetOrientation(SwingTwist16 orientation)
Set the orientation of the thing.
Definition Thing.cpp:208
virtual void ProcessBinary(char *bytes)
FUnction used to process binary data received for this thing.
Definition Thing.cpp:196
virtual void SetAngularVelocity(Spherical angularVelocity)
Set the angular velocity of the thing.
Definition Thing.cpp:226
void SetLinearVelocity(Spherical linearVelocity)
Set the linear velocity of the thing.
Definition Thing.cpp:217
void Update(bool recursively=false)
Update de state of the thing.
Definition Thing.cpp:166
bool RemoveChild(Thing *child)
Remove the given thing as a child of this thing.
Definition Thing.cpp:96
unsigned char networkId
The network ID of this thing.
Definition Thing.h:72
virtual Spherical GetAngularVelocity()
Get the angular velocity of the thing.
Definition Thing.cpp:231
bool positionUpdated
Boolean indicating that the thing has an updated position.
Definition Thing.h:139
const char * name
The name of the thing.
Definition Thing.h:125
bool orientationUpdated
The scale of the thing (deprecated I think)
Definition Thing.h:157
Type
Predefined thing types.
Definition Thing.h:22
Participant * owner
The participant owning this thing.
Definition Thing.h:69
unsigned char childCount
The number of children.
Definition Thing.h:103
unsigned char type
The type of Thing This can be either a Thing::Type of a byte value for custom types.
Definition Thing.h:78
const char * modelUrl
An URL pointing to the location where a model of the thing can be found.
Definition Thing.h:127
virtual void GenerateBinary(char *buffer, unsigned char *ix)
Function used to generate binary data for this thing.
Definition Thing.cpp:192
A sensor which can detect touches.
Definition TouchSensor.h:8