Skip to content

Commit bcf3867

Browse files
committed
added needsSensorUpdate
1 parent 407205e commit bcf3867

7 files changed

+27
-6
lines changed

examples/src/server/synchronousServerUpdate.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ int main(int argc, char **argv) {
5454
server.acceptConnection(2000.0);
5555

5656
for (int k = 0; k < loopN; k++) {
57-
// RS_TIMED_LOOP(int(world.getTimeStep()*1e7))
58-
// for (int i = 0; i < 10; i++)
57+
server.applyInteractionForce();
5958
world.integrate();
60-
61-
if (server.waitForMessageFromClient(1.0)) {
62-
if (!server.processRequests()) {
63-
server.acceptConnection(2000.0);
59+
if (server.needsSensorUpdate()) {
60+
if (server.waitForMessageFromClient(1.0)) {
61+
if (!server.processRequests()) {
62+
server.acceptConnection(2000.0);
63+
}
6464
}
6565
}
6666
}

raisim/linux/include/raisim/RaisimServer.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,27 @@ class RaisimServer final {
852852
#endif
853853
}
854854

855+
/**
856+
* Check if there is any sensor that has to be updated from the visualizer
857+
* @return if any of the sensors needs an update
858+
*/
859+
inline bool needsSensorUpdate() {
860+
auto &objList = world_->getObjList();
861+
for (auto *ob: objList) {
862+
if (ob->getObjectType() == ObjectType::ARTICULATED_SYSTEM) {
863+
auto as = dynamic_cast<ArticulatedSystem *>(ob);
864+
for (auto &sensor: as->getSensors()) {
865+
if (sensor.second->getMeasurementSource() == Sensor::MeasurementSource::VISUALIZER &&
866+
sensor.second->getUpdateTimeStamp() + 1. / sensor.second->getUpdateRate()
867+
< world_->getWorldTime() + 1e-10) {
868+
return true;
869+
}
870+
}
871+
}
872+
}
873+
return false;
874+
}
875+
855876
/**
856877
* Synchronous update method.
857878
* Receive a request from the client, process it and return the requested data to the client.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)