-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrobot_control_example.py
More file actions
executable file
·53 lines (40 loc) · 1.28 KB
/
robot_control_example.py
File metadata and controls
executable file
·53 lines (40 loc) · 1.28 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""Example of basic task-space control of a robot arm."""
import time
import numpy as np
import pybullet as pyb
import pybullet_data
import pyb_utils
STEPS_PER_SEC = 60
TIMESTEP = 1.0 / STEPS_PER_SEC
def main():
pyb.connect(pyb.GUI)
pyb.setGravity(0, 0, -9.81)
pyb.setTimeStep(TIMESTEP)
pyb.setAdditionalSearchPath(pybullet_data.getDataPath())
pyb.loadURDF("plane.urdf", [0, 0, 0], useFixedBase=True)
kuka_id = pyb.loadURDF(
"kuka_iiwa/model.urdf",
[0, 0, 0],
useFixedBase=True,
)
robot = pyb_utils.Robot(kuka_id)
r = robot.get_link_frame_pose()[0]
# desired end effector positions
goals = np.array(
[[0.75, 0, 0.5], [0, 0.75, 0.5], [-0.75, 0, 0.5], [0, -0.75, 0.5]]
)
for goal in goals:
pyb_utils.debug_frame_world(size=0.1, origin=goal)
for goal in goals:
print(f"Goal = {goal}")
while np.linalg.norm(goal - r) > 0.01:
r = robot.get_link_frame_pose()[0]
J = robot.compute_link_frame_jacobian()[:3, :]
# simple inverse kinematics controller
u = np.linalg.lstsq(J, goal - r, rcond=None)[0]
robot.command_velocity(u)
pyb.stepSimulation()
time.sleep(TIMESTEP)
print("Done")
main()