# This example shows the usage of intermediate waypoints. It will only work with Ruckig Pro or enabled Online API (e.g. default when installed by pip / PyPI). 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]
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;
if __name__ == '__main__': inp = InputParameter(3) # inp.interface = InputParameter.Interface.Velocity # inp.synchronization = InputParameter.TimeIfNecessary # inp.duration_discretization = InputParameter.Discrete inp.current_position = [0.5, -1, -1] inp.current_velocity = [0, 0.2, 0] inp.current_acceleration = [0, 1, 1] inp.target_position = [1, -1, -1] inp.target_velocity = [0, 0, 0] inp.target_acceleration = [0, 1, 1] inp.max_velocity = [2, 2, 2] inp.max_acceleration = [2, 2, 2] inp.max_jerk = [1, 1, 1] # otg = Quintic(3, 0.005) # otg = Smoothie(3, 0.005) # otg = Reflexxes(3, 0.005) otg = Ruckig(3, 0.005) t_list, out_list = walk_through_trajectory(otg, inp) # print(out_list[0].trajectory.get_position_extrema()) print(f'Calculation duration: {out_list[0].calculation_duration:0.1f} [µs]') print(f'Trajectory duration: {out_list[0].trajectory.duration:0.4f} [s]') plot_trajectory(t_list, out_list)
return out_list, time_offsets, time_offset if __name__ == '__main__': inp = InputParameter(3) inp.current_position = [0, 0, 0] inp.current_velocity = [0, 0, 0] inp.current_acceleration = [0, 0, 0] inp.target_position = [1, 1, 1] inp.target_velocity = [0, 0, 0] inp.target_acceleration = [0, 0, 0] inp.max_velocity = [100, 100, 100] inp.max_acceleration = [100, 100, 100] inp.max_jerk = [1, 1, 1] intermediate_waypoints = [( [0.7, 0.2, 0.1], [0.56, 0.1, 0.1], [-0.3, 0, 0], )] otg = Ruckig(inp.degrees_of_freedom, 0.005) out_list, time_offsets, duration = walk_through_trajectory(otg, inp, intermediate_waypoints) print(f'Calculation duration: {out_list[0].calculation_duration:0.1f} [µs]') print(f'Trajectory duration: {duration:0.6f} [s]') Plotter.plot_trajectory('otg_multiple.png', otg, inp, out_list, plot_jerk=False, time_offsets=time_offsets)
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, ControlInterface if __name__ == '__main__': # Create instances: the Ruckig OTG as well as input and output parameters otg = Ruckig(3, 0.01) # DoFs, control cycle inp = InputParameter(3) out = OutputParameter(3) inp.control_interface = ControlInterface.Velocity inp.current_position = [0.0, 0.0, 0.5] inp.current_velocity = [3.0, -2.2, -0.5] inp.current_acceleration = [0.0, 2.5, -0.5] inp.target_velocity = [0.0, -0.5, -1.5] inp.target_acceleration = [0.0, 0.0, 0.5] inp.max_acceleration = [3.0, 2.0, 1.0] inp.max_jerk = [6.0, 6.0, 4.0] print('\t'.join(['t'] + [str(i) for i in range(otg.degrees_of_freedom)]))
0.1839756723363622, -0.4356283320280516, 0.7490399525818022 ] inp.current_acceleration = [-1.057769973808928, 0, -2.368645439140517] inp.target_position = [ -4.928244836531066, -4.821780824003112, -8.20567952461017 ] inp.target_velocity = [0.1097319156272965, -0.9272874846270881, 0] inp.target_acceleration = [0.03089046366221739, -0.9744054582899561, 0] inp.max_velocity = [ 6.144314006624488, 2.93258338415229, 0.1820021269527196 ] inp.max_acceleration = [ 5.199401036221791, 1.848176490768948, 11.11168017805234 ] inp.max_jerk = [9.940940357283978, 10.46997753899755, 0.08166297169205029] # otg = Quintic(3, 0.005) # otg = Smoothie(3, 0.005) # otg = Reflexxes(3, 0.005) otg = Ruckig(3, 0.5) t_list, out_list = walk_through_trajectory(otg, inp) # print(out_list[0].trajectory.get_position_extrema()) print( f'Calculation duration: {out_list[0].calculation_duration:0.1f} [µs]') print(f'Trajectory duration: {out_list[0].trajectory.duration:0.4f} [s]') plot_trajectory(t_list, out_list)
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 different constraints for negative direction inp.min_velocity = [-1.0, -0.5, -3.0] inp.min_acceleration = [-2.0, -1.0, -2.0] # We don't need to pass the control rate (cycle time) when using only offline features otg = Ruckig(3) trajectory = Trajectory(3) # Calculate the trajectory in an offline manner result = otg.calculate(inp, trajectory) if result == Result.ErrorInvalidInput: raise Exception('Invalid input!') print(f'Trajectory duration: {trajectory.duration:0.4f} [s]') new_time = 1.0 # Then, we can calculate the kinematic state at a given time new_position, new_velocity, new_acceleration = trajectory.at_time(new_time) print(f'Position at time {new_time:0.4f} [s]: {new_position}')