importpybulletaspimporttimeimportpybullet_datap.connect(p.GUI)p.setGravity(0,0,-9.8)# Default PyBullet assetsp.setAdditionalSearchPath(pybullet_data.getDataPath())plane_id=p.loadURDF("plane.urdf")# Additional URDFs locationp.setAdditionalSearchPath("/workspaces/pybullet_tutorial/demos/urdf")# fix base to worldrobot_id=p.loadURDF("rrbot.urdf",useFixedBase=True)# add slider for each jointjoint_sliders={}num_joints=p.getNumJoints(robot_id)foriinrange(num_joints):info=p.getJointInfo(robot_id,i)j_name=info[1].decode("utf-8")j_type=info[2]slider_id=p.addUserDebugParameter(j_name,-3.14,3.14,0.0)joint_sliders[i]=slider_idwhilep.isConnected():forj,slider_idinjoint_sliders.items():target=p.readUserDebugParameter(slider_id)# set joint positionp.setJointMotorControl2(robot_id,j,controlMode=p.POSITION_CONTROL,targetPosition=target,force=5.0)p.stepSimulation()time.sleep(1./240.)
setJointMotorControl2
We can control a robot by setting a desired control mode for one or more joint motors. During the stepSimulation the physics engine will simulate the motors to reach the given target value that can be reached within the maximum motor forces and other constraints. (page 25)
importpybulletaspimporttimeimportpybullet_datap.connect(p.GUI)p.setGravity(0,0,-9.8)# Default PyBullet assetsp.setAdditionalSearchPath(pybullet_data.getDataPath())plane_id=p.loadURDF("plane.urdf")# Additional URDFs locationp.setAdditionalSearchPath("/workspaces/pybullet_tutorial/demos/urdf")# fix base to worldrobot_id=p.loadURDF("rrbot.urdf",useFixedBase=True)# add slider for each jointjoint_sliders={}num_joints=p.getNumJoints(robot_id)foriinrange(num_joints):info=p.getJointInfo(robot_id,i)j_name=info[1].decode("utf-8")j_type=info[2]slider_id=p.addUserDebugParameter(j_name,-2,2,0.0)joint_sliders[i]=slider_idwhilep.isConnected():forj,slider_idinjoint_sliders.items():target=p.readUserDebugParameter(slider_id)# set joint positionp.setJointMotorControl2(robot_id,j,controlMode=p.VELOCITY_CONTROL,targetVelocity=target,force=5.0)p.stepSimulation()time.sleep(1./240.)
importpybulletaspimporttimeimportpybullet_datap.connect(p.GUI)p.setGravity(0,0,-9.8)# Default assetsp.setAdditionalSearchPath(pybullet_data.getDataPath())plane_id=p.loadURDF("plane.urdf")# Your URDFsp.setAdditionalSearchPath("/workspaces/pybullet_tutorial/demos/urdf")robot_id=p.loadURDF("rrbot.urdf",useFixedBase=True)num_joints=p.getNumJoints(robot_id)# Disable default motorsforjinrange(num_joints):p.setJointMotorControl2(robot_id,j,p.VELOCITY_CONTROL,force=0)# Optional: reduce damping so it moves easierforjinrange(num_joints):p.changeDynamics(robot_id,j,linearDamping=0,angularDamping=0)# Start slightly away from upright so gravity is non-zerop.resetJointState(robot_id,0,0.2)# Torque slider ONLY for joint 1 (revolute)MAX_TORQUE=20.0slider_id=p.addUserDebugParameter("joint1_torque",-MAX_TORQUE,MAX_TORQUE,0.0)whilep.isConnected():torque=p.readUserDebugParameter(slider_id)p.setJointMotorControl2(robot_id,0,# control joint1 onlycontrolMode=p.TORQUE_CONTROL,force=torque)p.stepSimulation()time.sleep(1./240.)
TODO: show joint angel
TODO: calc the torque need to apply for this angel
\[\tau = m g r \sin(\theta)\]
\[\tau_\text{max,gravity} = m g r ≈ 1 \cdot 9.81 \cdot 0.45 ≈ 4.4 \text{Nm}\]
If the joint comes to rest at some angle θ because of damping, static equilibrium is roughly: