-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruckig_example.py
More file actions
45 lines (34 loc) · 1.24 KB
/
ruckig_example.py
File metadata and controls
45 lines (34 loc) · 1.24 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
import numpy as np
from ruckig import InputParameter, Ruckig, Trajectory, Result
from trajectory_executor import TrajectoryExecutor
# === 1. Initialize Ruckig ===
inp = InputParameter(6)
inp.current_position = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
inp.target_position = [0.0, -1.01, -1.7, -1.82, 1.45, 0.0]
inp.max_velocity = [3.14, 3.14, 3.14, 3.14, 3.14, 3.14]
inp.max_acceleration = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
inp.max_jerk = [4.0, 4.0, 4.0, 4.0, 4.0, 4.0]
inp.minimum_duration = 5.0
otg = Ruckig(6)
trajectory = Trajectory(6)
# === 2. Calculate trajectory ===
result = otg.calculate(inp, trajectory)
if result == Result.ErrorInvalidInput:
raise Exception("Invalid input!")
times = []
positions = []
for new_time in np.linspace(0, trajectory.duration, 10):
# Then, we can calculate the kinematic state at a given time
pos, _, _ = trajectory.at_time(new_time)
times.append(new_time)
positions.append(pos)
# === 3. Define callback and trajectory executor ===
def update_callback(target_state):
print(f"Target position: {target_state}")
executor = TrajectoryExecutor(
dof=trajectory.degrees_of_freedom,
update_callback=update_callback,
loop_rate_hz=50.0,
)
# === 4. Execute the trajectory ===
executor.execute(positions, times)