bullet3
bullet3 copied to clipboard
getJointState and StateLogging
I use setJointMotorControlMultiDof(ObjectId, JointId, controlMode=p.TORQUE_CONTROL, force=force)
and p.stepSimulation()
to do a simulation and I set numSubSteps=1. Also, I use p.getJointState(ObjectIDd, JointId)
to obtain the force (torque) it applies which should be stored in appliedJointMotorTorque.
However, I find that appliedJointMotorTorque is not equal to force I input.
I'd like to know what appliedJointMotorTorque means and why the difference occured. My code is as follows.
import pybullet as p import numpy as np from utilities import readLogFile
import time
useMaximalCoordinates = False import pybullet_data
p.connect(p.GUI) p.setAdditionalSearchPath(pybullet_data.getDataPath())
print(pybullet_data.getDataPath())
pole = p.loadURDF("cartpole.urdf", [0, 0, 0], useMaximalCoordinates=useMaximalCoordinates)
p.setGravity(0, 0, -9.8)
timeStep = 0.01
taus = [10., 10.]
logID = p.startStateLogging(p.STATE_LOGGING_GENERIC_ROBOT, r"mytest\test.txt",logFlags = p.STATE_LOG_JOINT_TORQUES) p.setPhysicsEngineParameter(fixedTimeStep=timeStep, numSubSteps=1) torque_use = [] for i in range(5): for j in [0, 1]: p.setJointMotorControlMultiDof(pole, j, controlMode=p.TORQUE_CONTROL, force=[taus[j]])
p.stepSimulation()
[jointPosition,jointVelocity,jointReactionForces,appliedJointMotorTorque0] = p.getJointState(pole,0)
[jointPosition,jointVelocity,jointReactionForces,appliedJointMotorTorque1] = p.getJointState(pole,1)
torque_use.append([appliedJointMotorTorque0, appliedJointMotorTorque1])
p.stopStateLogging(logID)
a = np.array(readLogFile(r"mytest\test.txt", True)) a = a[:,41:43] print(a) print(np.array(torque_use)) print('stop')
What's more, I use startStateLogging to log torque. I think it should be equal to appliedJointMotorTorque but it doesn't in fact. What happened?