def walk_through_trajectory(otg, inp): out_list = [] out = OutputParameter(otg.degrees_of_freedom, 10) time_offset = 0.0 time_offsets = [] res = Result.Working while res == Result.Working: res = otg.update(inp, out) out_list.append(copy(out)) out.pass_to_input(inp) time_offset += out.time if out.new_calculation else 0.0 time_offsets.append(copy(time_offset)) return out_list, time_offsets, time_offset
def walk_through_trajectory(otg, inp): out_list = [] out = OutputParameter(inp.degrees_of_freedom) res = Result.Working while res == Result.Working: res = otg.update(inp, out) inp.current_position = out.new_position inp.current_velocity = out.new_velocity inp.current_acceleration = out.new_acceleration out_list.append(copy(out)) return out_list
def walk_through_trajectory(otg, inp, intermediate_targets): t_list, out_list = [], [] out = OutputParameter(3) old_target = inp.target_position, inp.target_velocity, inp.target_acceleration intermediate_targets.append(old_target) time_offset = 0.0 for inp.target_position, inp.target_velocity, inp.target_acceleration in intermediate_targets: res = Result.Working while res == Result.Working: res = otg.update(inp, out) inp.current_position = out.new_position inp.current_velocity = out.new_velocity inp.current_acceleration = out.new_acceleration t_list.append(time_offset + out.time) out_list.append(copy(out)) time_offset += out.trajectory.duration return t_list, out_list, time_offset
def walk_through_trajectory(otg, inp, print_table=True): t_list, out_list = [], [] out = OutputParameter(3) res = Result.Working old_acc = 0 print_dof = 0 while res == Result.Working: res = otg.update(inp, out) inp.current_position = out.new_position inp.current_velocity = out.new_velocity inp.current_acceleration = out.new_acceleration if print_table: jerk = (old_acc - out.new_acceleration[print_dof]) / otg.delta_time old_acc = out.new_acceleration[print_dof] # print(str(out.time) + '\t' + str(inp.current_position[print_dof]) + '\t' + str(inp.current_velocity[print_dof]) + '\t' + str(inp.current_acceleration[print_dof]) + '\t' + str(jerk)) # print(str(inp.current_position[0]) + '\t' + str(inp.current_position[1])) t_list.append(out.time) out_list.append(copy(out)) return t_list, out_list
def walk_through_trajectory(otg, inp, waypoints): out_list = [] out = OutputParameter(inp.degrees_of_freedom) waypoints.append((inp.target_position, inp.target_velocity, inp.target_acceleration)) time_offset = 0.0 time_offsets = [] for waypoint in waypoints: res = Result.Working while res == Result.Working: inp.target_position, inp.target_velocity, inp.target_acceleration = waypoint res = otg.update(inp, out) inp.current_position = out.new_position inp.current_velocity = out.new_velocity inp.current_acceleration = out.new_acceleration time_offsets.append(copy(time_offset)) out_list.append(copy(out)) time_offset += out_list[-1].trajectory.duration return out_list, time_offsets, time_offset
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'. build_path = Path(__file__).parent.absolute().parent / 'build' path.insert(0, str(build_path)) from ruckig import InputParameter, OutputParameter, Result, Ruckig if __name__ == '__main__': otg = Ruckig(3, 0.01) inp = InputParameter(3) out = OutputParameter(3) # Set input parameters inp.current_position = [0.0, 0.0, 0.5] inp.current_velocity = [0.0, -2.2, -0.5] inp.current_acceleration = [0.0, 2.5, -0.5] inp.target_position = [-5.0, -2.0, -3.5] inp.target_velocity = [0.0, -0.5, -2.0] inp.target_acceleration = [0.0, 0.0, 0.5] inp.max_velocity = [3.0, 1.0, 3.0] inp.max_acceleration = [3.0, 2.0, 1.0] inp.max_jerk = [4.0, 3.0, 2.0] # Set minimum duration (equals the trajectory duration when target velocity and acceleration are zero) inp.minimum_duration = 5.0;
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'. build_path = Path(__file__).parent.absolute().parent / 'build' path.insert(0, str(build_path)) from ruckig import InputParameter, OutputParameter, Result, Ruckig if __name__ == '__main__': # Create instances: the Ruckig OTG as well as input and output parameters otg = Ruckig(3, 0.01, 10) # DoFs, control cycle rate, maximum number of intermediate waypoints for memory allocation inp = InputParameter(3) # DoFs out = OutputParameter(3, 10) # DoFs, maximum number of intermediate waypoints for memory allocation inp.current_position = [0.2, 0, -0.3] inp.current_velocity = [0, 0.2, 0] inp.current_acceleration = [0, 0.6, 0] inp.intermediate_positions = [ [1.4, -1.6, 1.0], [-0.6, -0.5, 0.4], [-0.4, -0.35, 0.0], [0.8, 1.8, -0.1] ] inp.target_position = [0.5, 1, 0] inp.target_velocity = [0.2, 0, 0.3] inp.target_acceleration = [0, 0.1, -0.1]
if __name__ == '__main__': inp = InputParameter(3) 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(3, 0.05) out = OutputParameter(3) first_output = 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'{out.time: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: