-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lars Berscheid
committed
Mar 3, 2021
1 parent
0fdd39f
commit 141724a
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from copy import copy | ||
from pathlib import Path | ||
from sys import path | ||
|
||
# Path to the build directory including a file similar to '_ruckig.cpython-37m-x86_64-linux-gnu'. | ||
path.insert(0, str(Path(__file__).parent.parent / 'build')) | ||
|
||
from _ruckig import InputParameter, OutputParameter, Result, Ruckig | ||
|
||
|
||
def walk_through_trajectory(otg, inp): | ||
out = OutputParameter() | ||
t, first_output = 0.0, None | ||
|
||
print('\t'.join(['t'] + [str(i) for i in range(otg.degrees_of_freedom)])) | ||
|
||
res = Result.Working | ||
while res == Result.Working: | ||
res = otg.update(inp, out) | ||
|
||
print('\t'.join([f'{t:0.3f}'] + [f'{p:0.3f}' for p in out.new_position])) | ||
|
||
inp.current_position = out.new_position | ||
inp.current_velocity = out.new_velocity | ||
inp.current_acceleration = out.new_acceleration | ||
|
||
if not first_output: | ||
first_output = copy(out) | ||
t += otg.delta_time | ||
|
||
return first_output | ||
|
||
|
||
if __name__ == '__main__': | ||
inp = InputParameter() | ||
inp.current_position = [0.2, 0, -1] | ||
inp.current_velocity = [0, 0.2, 0] | ||
inp.current_acceleration = [0, 1, 0] | ||
inp.target_position = [0, -1, -1] | ||
inp.target_velocity = [0.2, 0, 0] | ||
inp.target_acceleration = [0, 0.1, -0.1] | ||
inp.max_velocity = [2, 1, 1] | ||
inp.max_acceleration = [0.2, 2, 2] | ||
inp.max_jerk = [3, 4, 5] | ||
|
||
otg = Ruckig(0.05) | ||
|
||
first_output = walk_through_trajectory(otg, inp) | ||
|
||
print(f'Calculation duration: {first_output.calculation_duration:0.1f} [µs]') | ||
print(f'Trajectory duration: {first_output.trajectory.duration:0.4f} [s]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters