MCPcopy Create free account
hub / github.com/TeleHuman/TextOp / PhysicsLoop

Function PhysicsLoop

TextOpDeploy/src/unitree_mujoco/simulate/src/main.cc:294–507  ·  view source on GitHub ↗

simulate in background thread (while rendering in main thread)

Source from the content-addressed store, hash-verified

292
293// simulate in background thread (while rendering in main thread)
294void PhysicsLoop(mj::Simulate &sim)
295{
296 // cpu-sim syncronization point
297 std::chrono::time_point<mj::Simulate::Clock> syncCPU;
298 mjtNum syncSim = 0;
299
300 // ChannelFactory::Instance()->Init(0);
301 // UnitreeDds ud(d);
302
303 // run until asked to exit
304 while (!sim.exitrequest.load())
305 {
306 if (sim.droploadrequest.load())
307 {
308 sim.LoadMessage(sim.dropfilename);
309 mjModel *mnew = LoadModel(sim.dropfilename, sim);
310 sim.droploadrequest.store(false);
311
312 mjData *dnew = nullptr;
313 if (mnew)
314 dnew = mj_makeData(mnew);
315 if (dnew)
316 {
317 sim.Load(mnew, dnew, sim.dropfilename);
318
319 mj_deleteData(d);
320 mj_deleteModel(m);
321
322 m = mnew;
323 d = dnew;
324 mj_forward(m, d);
325
326 // allocate ctrlnoise
327 free(ctrlnoise);
328 ctrlnoise = (mjtNum *)malloc(sizeof(mjtNum) * m->nu);
329 mju_zero(ctrlnoise, m->nu);
330 }
331 else
332 {
333 sim.LoadMessageClear();
334 }
335 }
336
337 if (sim.uiloadrequest.load())
338 {
339 sim.uiloadrequest.fetch_sub(1);
340 sim.LoadMessage(sim.filename);
341 mjModel *mnew = LoadModel(sim.filename, sim);
342 mjData *dnew = nullptr;
343 if (mnew)
344 dnew = mj_makeData(mnew);
345 if (dnew)
346 {
347 sim.Load(mnew, dnew, sim.filename);
348
349 mj_deleteData(d);
350 mj_deleteModel(m);
351

Callers 1

PhysicsThreadFunction · 0.85

Calls 7

LoadModelFunction · 0.85
loadMethod · 0.80
LoadMessageMethod · 0.80
LoadMethod · 0.80
LoadMessageClearMethod · 0.80
AddToHistoryMethod · 0.80
AdvanceMethod · 0.45

Tested by

no test coverage detected