Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Commit 95aaff4

Browse files
committed
added hibernating option in raisim server
1 parent d3a6b35 commit 95aaff4

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

include/raisim/RaisimServer.hpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class RaisimServer final {
112112
REQUEST_CONFIG_XML,
113113
REQUEST_INITIALIZE_VISUALS,
114114
REQUEST_VISUAL_POSITION,
115+
REQUEST_SERVER_STATUS,
115116
};
116117

117118
enum ServerMessageType : int {
@@ -248,6 +249,14 @@ class RaisimServer final {
248249
updateReady_ = true;
249250
}
250251

252+
void hibernate() {
253+
state_ = STATUS_HIBERNATING;
254+
}
255+
256+
void wakeup() {
257+
state_ = STATUS_RENDERING;
258+
}
259+
251260
void killServer() {
252261
terminateRequested_ = true;
253262
serverThread_.join();
@@ -268,6 +277,8 @@ class RaisimServer final {
268277

269278
Visuals& addVisualSphere(const std::string name, double radius, double colorR = 1, double colorG = 1, double colorB = 1,
270279
double colorA = 1, const std::string &material = "", bool glow = true, bool shadow = false) {
280+
if(_visualObjects.find(name) != _visualObjects.end()) RSFATAL("Duplicated visual object name: " + name)
281+
updateVisualConfig();
271282
_visualObjects[name] = Visuals();
272283
_visualObjects[name].type = Visuals::VisualType::VisualSphere;
273284
_visualObjects[name].name = name;
@@ -280,6 +291,8 @@ class RaisimServer final {
280291

281292
Visuals& addVisualBox(const std::string name, double xLength, double yLength, double zLength, double colorR = 1,
282293
double colorG = 1, double colorB = 1, double colorA = 1, const std::string &material = "", bool glow = true, bool shadow = false) {
294+
if(_visualObjects.find(name) != _visualObjects.end()) RSFATAL("Duplicated visual object name: " + name)
295+
updateVisualConfig();
283296
_visualObjects[name] = Visuals();
284297
_visualObjects[name].type = Visuals::VisualType::VisualBox;
285298
_visualObjects[name].name = name;
@@ -294,6 +307,8 @@ class RaisimServer final {
294307

295308
Visuals& addVisualCylinder(const std::string name, double radius, double length, double colorR = 1, double colorG = 1,
296309
double colorB = 1, double colorA = 1, const std::string &material = "", bool glow = true, bool shadow = false) {
310+
if(_visualObjects.find(name) != _visualObjects.end()) RSFATAL("Duplicated visual object name: " + name)
311+
updateVisualConfig();
297312
_visualObjects[name] = Visuals();
298313
_visualObjects[name].type = Visuals::VisualType::VisualCylinder;
299314
_visualObjects[name].name = name;
@@ -307,6 +322,8 @@ class RaisimServer final {
307322

308323
Visuals& addVisualCapsule(const std::string name, double radius, double length, double colorR = 1, double colorG = 1,
309324
double colorB = 1, double colorA = 1, const std::string &material = "", bool glow = true, bool shadow = false) {
325+
if(_visualObjects.find(name) != _visualObjects.end()) RSFATAL("Duplicated visual object name: " + name)
326+
updateVisualConfig();
310327
_visualObjects[name] = Visuals();
311328
_visualObjects[name].type = Visuals::VisualType::VisualCapsule;
312329
_visualObjects[name].name = name;
@@ -320,13 +337,21 @@ class RaisimServer final {
320337

321338
Visuals& getVisualObject(std::string name)
322339
{
340+
if(_visualObjects.find(name) == _visualObjects.end()) RSFATAL("Visual object with name \"" + name + "\" doesn't exist.")
323341
return _visualObjects[name];
324342
}
325343

326344
// void addVisualMesh() {
327345
// _visualObjects.emplace(name, new VisualObject);
328346
// }
329347

348+
void removeVisualObject(std::string name)
349+
{
350+
if(_visualObjects.find(name) == _visualObjects.end()) RSFATAL("Visual object with name \"" + name + "\" doesn't exist.")
351+
updateVisualConfig();
352+
_visualObjects.erase(name);
353+
}
354+
330355
private:
331356

332357
bool processRequests() {
@@ -369,6 +394,10 @@ class RaisimServer final {
369394
case REQUEST_VISUAL_POSITION:
370395
serializeVisualWorld();
371396
break;
397+
398+
case REQUEST_SERVER_STATUS:
399+
// Do nothing
400+
break;
372401
}
373402

374403
bool eom = false;
@@ -387,7 +416,7 @@ class RaisimServer final {
387416
eom = true;
388417
}
389418
}
390-
return state_ == STATUS_RENDERING;
419+
return state_ == STATUS_RENDERING || state_ == STATUS_HIBERNATING;
391420
}
392421

393422
void serializeWorld() {
@@ -579,9 +608,6 @@ class RaisimServer final {
579608
// set message type
580609
data_ = set(data_, ServerMessageType::CONTACT_INFO_UPDATE);
581610

582-
// set configuration number.
583-
data_ = set(data_, world_->getConfigurationNumber());
584-
585611
// Data begins
586612
data_ = set(data_, contactList->size());
587613

@@ -767,6 +793,9 @@ class RaisimServer final {
767793
// set message type
768794
data_ = set(data_, ServerMessageType::VISUAL_INITILIZATION);
769795

796+
// set configuration number
797+
data_ = set(data_, visualConfiguration_);
798+
770799
// Data begins
771800
data_ = set(data_, _visualObjects.size());
772801

@@ -827,6 +856,7 @@ class RaisimServer final {
827856

828857
// set message type
829858
data_ = set(data_, ServerMessageType::VISUAL_POSITION_UPDATE);
859+
data_ = set(data_, visualConfiguration_);
830860

831861
// Data begins
832862
data_ = set(data_, _visualObjects.size());
@@ -885,6 +915,8 @@ class RaisimServer final {
885915
std::mutex worldMutex_;
886916

887917
std::unordered_map<std::string, Visuals> _visualObjects;
918+
unsigned long visualConfiguration_ = 0;
919+
void updateVisualConfig() { visualConfiguration_++; }
888920

889921
int raisimPort_ = 8080;
890922
};

0 commit comments

Comments
 (0)