-
Notifications
You must be signed in to change notification settings - Fork 0
/
traj_example.py
67 lines (57 loc) · 1.79 KB
/
traj_example.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import numpy as np
from ManipulaPy.sim import Simulation
from ManipulaPy.ManipulaPy_data.ur5 import urdf_file as ur5_urdf_file
import time
import pybullet as p
def main():
# Define the joint limits for the UR5 robot
joint_limits = [
(-2 * np.pi, 2 * np.pi),
(-2 * np.pi, 2 * np.pi),
(-2 * np.pi, 2 * np.pi),
(-2 * np.pi, 2 * np.pi),
(-2 * np.pi, 2 * np.pi),
(-2 * np.pi, 2 * np.pi)
]
# Define the torque limits for the UR5 robot (optional)
torque_limits = [
(-100, 100),
(-100, 100),
(-100, 100),
(-100, 100),
(-100, 100),
(-100, 100)
]
# Initialize the simulation
sim = Simulation(
urdf_file_path=ur5_urdf_file,
joint_limits=joint_limits,
torque_limits=torque_limits,
time_step=0.01,
real_time_factor=1.0
)
# Define a simple joint trajectory for demonstration
num_steps = 100
joint_trajectory = np.linspace(
np.zeros(len(joint_limits)),
np.array([np.pi/2, -np.pi/4, np.pi/4, -np.pi/2, np.pi/2, -np.pi/4]),
num=num_steps
)
try:
while True:
# Simulate robot motion using the defined trajectory
sim.simulate_robot_motion(joint_trajectory)
# Allow manual control
sim.manual_control()
# Check for reset button press
if p.readUserDebugParameter(sim.reset_button) == 1:
sim.set_joint_positions(sim.home_position)
# Step the simulation
p.stepSimulation()
time.sleep(sim.time_step / sim.real_time_factor)
except KeyboardInterrupt:
print("Simulation stopped by user.")
sim.close_simulation()
if __name__ == "__main__":
main()