|
6 | 6 |
|
7 | 7 | import pybullet_data
|
8 | 8 |
|
9 |
| -use_real_hardware = False |
| 9 | +use_real_hardware = True |
10 | 10 | if use_real_hardware:
|
11 | 11 | import serial
|
12 | 12 |
|
|
27 | 27 |
|
28 | 28 | #collision tweak
|
29 | 29 | #p.setPhysicsEngineParameter(enableSAT=1)
|
30 |
| - |
31 | 30 | p.resetDebugVisualizerCamera(cameraDistance=1.0, cameraYaw=128, cameraPitch=-28, cameraTargetPosition=[-0.5,-0.4,-0.3])
|
32 | 31 |
|
33 | 32 | p.configureDebugVisualizer(p.COV_ENABLE_RENDERING, 0)
|
|
43 | 42 | #robot = p.loadURDF("surge_v13_hand_right_pybullet.urdf", useMaximalCoordinates=False, useFixedBase=True, flags=flags)
|
44 | 43 |
|
45 | 44 | p.configureDebugVisualizer(p.COV_ENABLE_RENDERING, 1)
|
46 |
| -gravId = p.addUserDebugParameter("gravity", -10, 10, -10) |
47 | 45 | jointIds = []
|
48 | 46 | paramIds = []
|
49 | 47 |
|
|
63 | 61 | joint_name_to_hw_scaling[b"Middle_MCP_Joint"]=1.0
|
64 | 62 | joint_name_to_hw_scaling[b"Ring_MCP_Joint"]=1.0
|
65 | 63 | joint_name_to_hw_scaling[b"Pinky_MCP_Joint"]=1.0
|
66 |
| -joint_name_to_hw_scaling[b"Metacarpal_Joint"]=0.25 |
67 |
| -joint_name_to_hw_scaling[b"Thumb_Joint"]=0.25 |
| 64 | +joint_name_to_hw_scaling[b"Metacarpal_Joint"]=0.4 |
| 65 | +joint_name_to_hw_scaling[b"Thumb_Joint"]=0.3 |
68 | 66 |
|
69 | 67 |
|
70 | 68 | joint_index_to_name={}
|
|
141 | 139 | paramIds.append(p.addUserDebugParameter(jointName.decode("utf-8"), 0, 1.92, 0))
|
142 | 140 |
|
143 | 141 | print("coupled_child_joints=",coupled_child_joints)
|
144 |
| -p.setRealTimeSimulation(1) |
145 | 142 |
|
146 | 143 | while (1):
|
147 |
| - p.setGravity(0, 0, p.readUserDebugParameter(gravId)) |
148 | 144 | for i in range(len(paramIds)):
|
149 | 145 |
|
150 | 146 | c = paramIds[i]
|
151 |
| - targetPos = p.readUserDebugParameter(c) |
152 |
| - if i in joint_index_to_name: |
| 147 | + try: |
| 148 | + targetPos = p.readUserDebugParameter(c) |
| 149 | + if i in joint_index_to_name: |
153 | 150 | deg = int(math.degrees(targetPos))
|
154 | 151 | #print(joint_name_to_hw[joint_index_to_name[i]], deg)
|
155 | 152 |
|
|
165 | 162 | response = ser.read(ser.inWaiting()) # Read all available data
|
166 | 163 | #print("Response:", response.decode(errors='ignore')) # Decode and print response
|
167 | 164 |
|
168 |
| - finger_force= 100 #Newton |
169 |
| - p.setJointMotorControl2(robot, jointIds[i], p.POSITION_CONTROL, targetPos, force=finger_force) |
170 |
| - if jointIds[i] in coupled_parent_to_child: |
171 |
| - distal_to_proximal_scaling=0.7 #you can also use a position-dependent non-linear function here |
| 165 | + finger_force= 100 #Newton |
| 166 | + p.setJointMotorControl2(robot, jointIds[i], p.POSITION_CONTROL, targetPos, force=finger_force) |
| 167 | + if jointIds[i] in coupled_parent_to_child: |
| 168 | + distal_to_proximal_scaling=0.65 #you can also use a position-dependent non-linear function here |
172 | 169 | p.setJointMotorControl2(robot, coupled_parent_to_child[jointIds[i]], p.POSITION_CONTROL, targetPos*distal_to_proximal_scaling, force=finger_force)
|
173 |
| - |
| 170 | + except(e): |
| 171 | + print(e) |
| 172 | + |
174 | 173 | contacts = p.getContactPoints()
|
175 | 174 | num_contacts = len(contacts)
|
176 | 175 | if (num_contacts):
|
177 | 176 | print("num_contacts=", num_contacts)
|
178 |
| - |
179 |
| - time.sleep(0.01) |
| 177 | + p.stepSimulation() |
| 178 | + time.sleep(1./240.) |
0 commit comments