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 LocalParticipant;
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 {
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,
39 };
40
43 Thing(int thingType = Type::Undetermined);
46 Thing(Participant* participant, Type thingType = Type::Undetermined);
49 Thing(Participant* participant, int thingType);
55 Thing(Participant* participant,
56 unsigned char networkId,
57 unsigned char thingId,
58 Type thingType = Type::Undetermined);
59
64 unsigned char networkId = 0;
66 unsigned char id = 0;
67
70 unsigned char type = 0;
71
75 Thing* FindThing(const char* name);
76
80 virtual void SetParent(Thing* parent);
81 void SetParent(Thing* root, const char* name);
85
89 virtual void AddChild(Thing* child);
93 Thing* RemoveChild(Thing* child);
94
96 unsigned char childCount = 0;
101 Thing* GetChild(unsigned char id, bool recursive = false);
105 Thing* GetChildByIndex(unsigned char ix);
106
107 protected:
108 Thing* parent = nullptr;
109 Thing** children = nullptr;
110
111 public:
113 const char* name = nullptr;
116 const char* modelUrl = nullptr;
118 float modelScale = 1;
119
122 void SetPosition(Spherical position);
125 Spherical GetPosition();
128 void SetOrientation(SwingTwist orientation);
131 SwingTwist GetOrientation();
133 // float scale = 1; // assuming uniform scale
134
136 bool positionUpdated = false;
138 bool orientationUpdated = false;
139
143 void SetLinearVelocity(Spherical linearVelocity);
146 virtual Spherical GetLinearVelocity();
149 virtual void SetAngularVelocity(Spherical angularVelocity);
152 virtual Spherical GetAngularVelocity();
153 bool linearVelocityUpdated = false;
154 bool angularVelocityUpdated = false;
155
156 private:
160 Spherical position;
164 SwingTwist orientation;
165
167 Spherical linearVelocity;
169 Spherical angularVelocity;
170
171 public:
173 void Terminate();
174
180 void SetModel(const char* url);
181
182 static unsigned long GetTimeMs();
183
184 void Update(bool recursive = false);
185
188 virtual void Update(unsigned long currentTimeMs, bool recursive = false);
189
190 static void UpdateThings(unsigned long currentTimeMs);
191
195 virtual void GenerateBinary(char* buffer, unsigned char* ix);
196 // /// @brief FUnction used to process binary data received for this thing
198 virtual void ProcessBinary(char* bytes);
199};
200
201} // namespace RoboidControl
A participant is a device which manages things. It can communicate with other participant to synchron...
Definition Participant.h:14
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:237
void SetModel(const char *url)
Sets the location from where the 3D model of this Thing can be loaded from.
Definition Thing.cpp:172
Thing * FindThing(const char *name)
Find a thing by name.
Definition Thing.cpp:67
void SetPosition(Spherical position)
Set the position of the thing.
Definition Thing.cpp:215
virtual void SetParent(Thing *parent)
Sets the parent Thing.
Definition Thing.cpp:83
Thing * GetChildByIndex(unsigned char ix)
Get a child by index.
Definition Thing.cpp:168
SwingTwist GetOrientation()
Get the orientation of the thing.
Definition Thing.cpp:228
void Terminate()
Terminated things are no longer updated.
Definition Thing.cpp:63
void SetOrientation(SwingTwist orientation)
Set the orientation of the thing.
Definition Thing.cpp:223
virtual void AddChild(Thing *child)
Add a child Thing to this Thing.
Definition Thing.cpp:103
float modelScale
The scale of the model (deprecated I think)
Definition Thing.h:118
Spherical GetPosition()
Get the position of the thing.
Definition Thing.cpp:219
Thing * GetParent()
Gets the parent Thing.
Definition Thing.cpp:99
virtual void ProcessBinary(char *bytes)
Definition Thing.cpp:211
virtual void SetAngularVelocity(Spherical angularVelocity)
Set the angular velocity of the thing.
Definition Thing.cpp:241
void SetLinearVelocity(Spherical linearVelocity)
Set the linear velocity of the thing.
Definition Thing.cpp:232
Thing * GetChild(unsigned char id, bool recursive=false)
Get a child by thing Id.
Definition Thing.cpp:151
unsigned char networkId
The network ID of this thing.
Definition Thing.h:64
virtual Spherical GetAngularVelocity()
Get the angular velocity of the thing.
Definition Thing.cpp:246
bool positionUpdated
The scale of the thing (deprecated I think)
Definition Thing.h:136
const char * name
The name of the thing.
Definition Thing.h:113
Thing * RemoveChild(Thing *child)
Remove the given thing as a child of this thing.
Definition Thing.cpp:126
bool orientationUpdated
boolean indicating if the orientation was updated
Definition Thing.h:138
Type
Predefined thing types.
Definition Thing.h:23
Participant * owner
The participant managing this thing.
Definition Thing.h:61
unsigned char childCount
The number of children.
Definition Thing.h:96
unsigned char type
The type of Thing This can be either a Thing::Type of a byte value for custom types.
Definition Thing.h:70
const char * modelUrl
An URL pointing to the location where a model of the thing can be found.
Definition Thing.h:116
virtual void GenerateBinary(char *buffer, unsigned char *ix)
Function used to generate binary data for this thing.
Definition Thing.cpp:207
A sensor which can detect touches.
Definition TouchSensor.h:8