@@ -112,6 +112,7 @@ class RaisimServer final {
112
112
REQUEST_CONFIG_XML,
113
113
REQUEST_INITIALIZE_VISUALS,
114
114
REQUEST_VISUAL_POSITION,
115
+ REQUEST_SERVER_STATUS,
115
116
};
116
117
117
118
enum ServerMessageType : int {
@@ -248,6 +249,14 @@ class RaisimServer final {
248
249
updateReady_ = true ;
249
250
}
250
251
252
+ void hibernate () {
253
+ state_ = STATUS_HIBERNATING;
254
+ }
255
+
256
+ void wakeup () {
257
+ state_ = STATUS_RENDERING;
258
+ }
259
+
251
260
void killServer () {
252
261
terminateRequested_ = true ;
253
262
serverThread_.join ();
@@ -268,6 +277,8 @@ class RaisimServer final {
268
277
269
278
Visuals& addVisualSphere (const std::string name, double radius, double colorR = 1 , double colorG = 1 , double colorB = 1 ,
270
279
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 ();
271
282
_visualObjects[name] = Visuals ();
272
283
_visualObjects[name].type = Visuals::VisualType::VisualSphere;
273
284
_visualObjects[name].name = name;
@@ -280,6 +291,8 @@ class RaisimServer final {
280
291
281
292
Visuals& addVisualBox (const std::string name, double xLength, double yLength, double zLength, double colorR = 1 ,
282
293
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 ();
283
296
_visualObjects[name] = Visuals ();
284
297
_visualObjects[name].type = Visuals::VisualType::VisualBox;
285
298
_visualObjects[name].name = name;
@@ -294,6 +307,8 @@ class RaisimServer final {
294
307
295
308
Visuals& addVisualCylinder (const std::string name, double radius, double length, double colorR = 1 , double colorG = 1 ,
296
309
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 ();
297
312
_visualObjects[name] = Visuals ();
298
313
_visualObjects[name].type = Visuals::VisualType::VisualCylinder;
299
314
_visualObjects[name].name = name;
@@ -307,6 +322,8 @@ class RaisimServer final {
307
322
308
323
Visuals& addVisualCapsule (const std::string name, double radius, double length, double colorR = 1 , double colorG = 1 ,
309
324
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 ();
310
327
_visualObjects[name] = Visuals ();
311
328
_visualObjects[name].type = Visuals::VisualType::VisualCapsule;
312
329
_visualObjects[name].name = name;
@@ -320,13 +337,21 @@ class RaisimServer final {
320
337
321
338
Visuals& getVisualObject (std::string name)
322
339
{
340
+ if (_visualObjects.find (name) == _visualObjects.end ()) RSFATAL (" Visual object with name \" " + name + " \" doesn't exist." )
323
341
return _visualObjects[name];
324
342
}
325
343
326
344
// void addVisualMesh() {
327
345
// _visualObjects.emplace(name, new VisualObject);
328
346
// }
329
347
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
+
330
355
private:
331
356
332
357
bool processRequests () {
@@ -369,6 +394,10 @@ class RaisimServer final {
369
394
case REQUEST_VISUAL_POSITION:
370
395
serializeVisualWorld ();
371
396
break ;
397
+
398
+ case REQUEST_SERVER_STATUS:
399
+ // Do nothing
400
+ break ;
372
401
}
373
402
374
403
bool eom = false ;
@@ -387,7 +416,7 @@ class RaisimServer final {
387
416
eom = true ;
388
417
}
389
418
}
390
- return state_ == STATUS_RENDERING;
419
+ return state_ == STATUS_RENDERING || state_ == STATUS_HIBERNATING ;
391
420
}
392
421
393
422
void serializeWorld () {
@@ -579,9 +608,6 @@ class RaisimServer final {
579
608
// set message type
580
609
data_ = set (data_, ServerMessageType::CONTACT_INFO_UPDATE);
581
610
582
- // set configuration number.
583
- data_ = set (data_, world_->getConfigurationNumber ());
584
-
585
611
// Data begins
586
612
data_ = set (data_, contactList->size ());
587
613
@@ -767,6 +793,9 @@ class RaisimServer final {
767
793
// set message type
768
794
data_ = set (data_, ServerMessageType::VISUAL_INITILIZATION);
769
795
796
+ // set configuration number
797
+ data_ = set (data_, visualConfiguration_);
798
+
770
799
// Data begins
771
800
data_ = set (data_, _visualObjects.size ());
772
801
@@ -827,6 +856,7 @@ class RaisimServer final {
827
856
828
857
// set message type
829
858
data_ = set (data_, ServerMessageType::VISUAL_POSITION_UPDATE);
859
+ data_ = set (data_, visualConfiguration_);
830
860
831
861
// Data begins
832
862
data_ = set (data_, _visualObjects.size ());
@@ -885,6 +915,8 @@ class RaisimServer final {
885
915
std::mutex worldMutex_;
886
916
887
917
std::unordered_map<std::string, Visuals> _visualObjects;
918
+ unsigned long visualConfiguration_ = 0 ;
919
+ void updateVisualConfig () { visualConfiguration_++; }
888
920
889
921
int raisimPort_ = 8080 ;
890
922
};
0 commit comments