-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp_2.py
More file actions
36 lines (28 loc) · 930 Bytes
/
Copy pathexp_2.py
File metadata and controls
36 lines (28 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pybullet as p
import pybullet_data
import time
import math
# Set up
physicsClient = p.connect(p.GUI)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.setGravity(0, 0, -9.8)
# Load KUKA
robotId = p.loadURDF("kuka_iiwa/model.urdf", basePosition=[0, 0, 0.5])
# joints
num_joints = p.getNumJoints(robotId)
print(f"KUKA Robot has {num_joints} joints.")
# Slider Control
sliderIds = []
sliderMax = 2 * math.pi # max joint angle
for i in range(num_joints):
sliderId = p.addUserDebugParameter(f"Joint {i}", -sliderMax, sliderMax, 0)
sliderIds.append(sliderId)
# Simulate
for step in range(5000):
p.stepSimulation()
# fetch slider value
for i in range(num_joints):
joint_angle = p.readUserDebugParameter(sliderIds[i])
p.setJointMotorControl2(robotId, jointIndex=i, controlMode=p.POSITION_CONTROL, targetPosition=joint_angle)
time.sleep(1 / 240)
p.disconnect()