Roboid Control for C++
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 enum Type : unsigned char {
24 Undetermined,
25 // Sensor,
26 Switch,
27 DistanceSensor,
28 DirectionalSensor,
31 // Motor,
32 ControlledMotor,
33 UncontrolledMotor,
34 Servo,
35 // Other
36 Roboid,
37 Humanoid,
38 ExternalSensor,
40 };
41
42#pragma region Init
43
46 Thing(unsigned char thingType = Type::Undetermined);
47
54 unsigned char thingType = Type::Undetermined,
55 unsigned char thingId = 0);
56
63 Thing(Thing* parent, unsigned char thingType = 0, unsigned char thingId = 0);
64
65#pragma endregion Init
66
67 public:
69 bool terminate = false;
70
71#pragma region Properties
72
74 Participant* owner = nullptr;
76 unsigned char id = 0;
77
80 unsigned char type = Type::Undetermined;
81
83 const char* name = nullptr;
84
85 public:
86 void SetName(const char* name);
87 const char* GetName() const;
88 bool nameChanged = false;
89
95 void SetModel(const char* url);
96
99 const char* modelUrl = nullptr;
101 float modelScale = 1;
102
103#pragma endregion Properties
104
105#pragma region Hierarchy
106
109 virtual void SetParent(Thing* parent);
112 Thing* GetParent();
113
115 unsigned char childCount = 0;
119 Thing* GetChildByIndex(unsigned char ix);
120
124 virtual void AddChild(Thing* child);
128 Thing* RemoveChild(Thing* child);
129
134 Thing* GetChild(unsigned char id, bool recurse = false);
135
140 Thing* FindChild(const char* name, bool recurse = true);
141
143 bool hierarchyChanged = true;
144
145 private:
146 Thing* parent = nullptr;
147 Thing** children = nullptr;
148
149#pragma endregion Hierarchy
150
151#pragma region Pose
152
153 public:
156 void SetPosition(Spherical position);
159 Spherical GetPosition();
161 bool positionUpdated = false;
162
165 void SetOrientation(SwingTwist orientation);
168 SwingTwist GetOrientation();
170 bool orientationUpdated = false;
171
175 void SetLinearVelocity(Spherical linearVelocity);
178 virtual Spherical GetLinearVelocity();
181
184 virtual void SetAngularVelocity(Spherical angularVelocity);
187 virtual Spherical GetAngularVelocity();
190
191 private:
195 Spherical position;
199 SwingTwist orientation;
200
202 Spherical linearVelocity;
204 Spherical angularVelocity;
205
206#pragma endregion Pose
207
208#pragma region Update
209
210 public:
213 static unsigned long GetTimeMs();
214
216 void Update(bool recursive = false);
217
222 virtual void Update(unsigned long currentTimeMs, bool recurse = false);
223
224 static void UpdateThings(unsigned long currentTimeMs);
225
226#pragma endregion Update
227
228 public:
233 virtual int GenerateBinary(char* buffer, unsigned char* ix);
236 virtual void ProcessBinary(char* bytes);
237};
238
239} // namespace RoboidControl
A thing which can move itself using a differential drive system.
Definition DifferentialDrive.h:10
A participant is a device which manages things. It can communicate with other participant to synchron...
Definition Participant.h:52
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:203
bool angularVelocityUpdated
Boolean indicating the thing has an updated angular velocity.
Definition Thing.h:189
void SetModel(const char *url)
Sets the location from where the 3D model of this Thing can be loaded from.
Definition Thing.cpp:63
void SetPosition(Spherical position)
Set the position of the thing.
Definition Thing.cpp:179
virtual void SetParent(Thing *parent)
Sets the parent of this Thing.
Definition Thing.cpp:69
Thing * GetChildByIndex(unsigned char ix)
Get a child by index.
Definition Thing.cpp:90
SwingTwist GetOrientation()
Get the orientation of the thing.
Definition Thing.cpp:192
void SetOrientation(SwingTwist orientation)
Set the orientation of the thing.
Definition Thing.cpp:187
virtual void AddChild(Thing *child)
Add a child Thing to this Thing.
Definition Thing.cpp:94
float modelScale
The scale of the model (deprecated I think)
Definition Thing.h:101
Spherical GetPosition()
Get the position of the thing.
Definition Thing.cpp:183
Thing * GetParent()
Gets the parent of this Thing.
Definition Thing.cpp:86
bool linearVelocityUpdated
Boolean indicating the thing has an updated linear velocity.
Definition Thing.h:180
void Update(bool recursive=false)
Updates the state of the thing.
Definition Thing.cpp:233
bool terminate
Terminated things are no longer updated.
Definition Thing.h:69
virtual void ProcessBinary(char *bytes)
Function used to process binary data received for this thing.
Definition Thing.cpp:268
virtual void SetAngularVelocity(Spherical angularVelocity)
Set the angular velocity of the thing.
Definition Thing.cpp:207
void SetLinearVelocity(Spherical linearVelocity)
Set the linear velocity of the thing.
Definition Thing.cpp:196
bool hierarchyChanged
Indicator that the hierarchy of the thing has changed.
Definition Thing.h:143
virtual Spherical GetAngularVelocity()
Get the angular velocity of the thing.
Definition Thing.cpp:214
bool positionUpdated
Boolean indicating that the thing has an updated position.
Definition Thing.h:161
const char * name
The name of the thing.
Definition Thing.h:83
Thing * RemoveChild(Thing *child)
Remove the given thing as a child of this thing.
Definition Thing.cpp:117
Thing * GetChild(unsigned char id, bool recurse=false)
Get a child by thing Id.
Definition Thing.cpp:142
bool orientationUpdated
Boolean indicating the thing has an updated orientation.
Definition Thing.h:170
static unsigned long GetTimeMs()
Get the current time in milliseconds.
Definition Thing.cpp:222
Type
Predefined thing types.
Definition Thing.h:23
Participant * owner
The participant managing this thing.
Definition Thing.h:74
virtual int GenerateBinary(char *buffer, unsigned char *ix)
Function used to generate binary data for this thing.
Definition Thing.cpp:263
unsigned char childCount
The number of children.
Definition Thing.h:115
Thing * FindChild(const char *name, bool recurse=true)
Find a thing by name.
Definition Thing.cpp:159
unsigned char type
The type of Thing This can be either a Thing::Type of a byte value for custom types.
Definition Thing.h:80
const char * modelUrl
An URL pointing to the location where a model of the thing can be found.
Definition Thing.h:99
A sensor which can detect touches.
Definition TouchSensor.h:8