MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / stepSimulation

Method stepSimulation

examples/SharedMemory/RobotControlExample.cpp:392–653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390
391
392void RobotControlExample::stepSimulation(float deltaTime)
393{
394
395 m_physicsServer.processClientCommands();
396
397 if (m_physicsClient.isConnected())
398 {
399
400 SharedMemoryStatus status;
401 bool hasStatus = m_physicsClient.processServerStatus(status);
402 if ((m_option==ROBOT_PING_PONG_JOINT_FEEDBACK) && hasStatus && status.m_type == CMD_ACTUAL_STATE_UPDATE_COMPLETED)
403 {
404 //update sensor feedback: joint force/torque data and measured joint positions
405
406 for (int i=0;i<m_numMotors;i++)
407 {
408 int jointIndex = m_motorTargetState[i].m_jointIndex;
409 int positionIndex = m_motorTargetState[i].m_posIndex;
410 int velocityIndex = m_motorTargetState[i].m_uIndex;
411
412 m_motorTargetState[i].m_measuredJointPosition = status.m_sendActualStateArgs.m_actualStateQ[positionIndex];
413 m_motorTargetState[i].m_measuredJointVelocity = status.m_sendActualStateArgs.m_actualStateQdot[velocityIndex];
414 m_motorTargetState[i].m_measuredJointForce.setValue(status.m_sendActualStateArgs.m_jointReactionForces[6*jointIndex],
415 status.m_sendActualStateArgs.m_jointReactionForces[6*jointIndex+1],
416 status.m_sendActualStateArgs.m_jointReactionForces[6*jointIndex+2]);
417 m_motorTargetState[i].m_measuredJointTorque.setValue(status.m_sendActualStateArgs.m_jointReactionForces[6*jointIndex+3],
418 status.m_sendActualStateArgs.m_jointReactionForces[6*jointIndex+4],
419 status.m_sendActualStateArgs.m_jointReactionForces[6*jointIndex+5]);
420
421 if (m_motorTargetState[i].m_measuredJointPosition>0.1)
422 {
423 m_motorTargetState[i].m_velTarget = -1.5;
424 } else
425 {
426 m_motorTargetState[i].m_velTarget = 1.5;
427 }
428
429 b3Printf("Joint Force (Linear) [%s]=(%f,%f,%f)\n",m_motorTargetState[i].m_jointName.c_str(),m_motorTargetState[i].m_measuredJointForce.x(),m_motorTargetState[i].m_measuredJointForce.y(),m_motorTargetState[i].m_measuredJointForce.z());
430 b3Printf("Joint Torque (Angular) [%s]=(%f,%f,%f)\n",m_motorTargetState[i].m_jointName.c_str(),m_motorTargetState[i].m_measuredJointTorque.x(),m_motorTargetState[i].m_measuredJointTorque.y(),m_motorTargetState[i].m_measuredJointTorque.z());
431
432 }
433
434
435 }
436
437 if (hasStatus && status.m_type == CMD_URDF_LOADING_COMPLETED)
438 {
439 SharedMemoryCommand sensorCommand;
440 sensorCommand.m_type = CMD_CREATE_SENSOR;
441 sensorCommand.m_createSensorArguments.m_numJointSensorChanges = 0;
442
443 for (int jointIndex=0;jointIndex<m_physicsClient.getNumJoints();jointIndex++)
444 {
445 b3JointInfo info;
446 m_physicsClient.getJointInfo(jointIndex,info);
447 if (m_verboseOutput)
448 {
449 b3Printf("Joint %s at q-index %d and u-index %d\n",info.m_jointName,info.m_qIndex,info.m_uIndex);

Callers 10

clientMoveAndDisplayMethod · 0.45
processServerStatusMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
RenderStereoTargetsMethod · 0.45
mainFunction · 0.45

Calls 15

c_strMethod · 0.80
processClientCommandsMethod · 0.45
isConnectedMethod · 0.45
processServerStatusMethod · 0.45
setValueMethod · 0.45
xMethod · 0.45
yMethod · 0.45
zMethod · 0.45
getNumJointsMethod · 0.45
getJointInfoMethod · 0.45
getParameterInterfaceMethod · 0.45

Tested by

no test coverage detected