Ruckig 0.17.1
Motion Generation for Robots and Machines
 
Loading...
Searching...
No Matches
(02) Offline Trajectory Generation
  • C++
    #include "plotter.hpp"
    using namespace ruckig;
    int main() {
    // Create input parameters
    input.current_position = {0.0, 0.0, 0.5};
    input.current_velocity = {0.0, -2.2, -0.5};
    input.current_acceleration = {0.0, 2.5, -0.5};
    input.target_position = {5.0, -2.0, -3.5};
    input.target_velocity = {0.0, -0.5, -2.0};
    input.target_acceleration = {0.0, 0.0, 0.5};
    input.max_velocity = {3.0, 1.0, 3.0};
    input.max_acceleration = {3.0, 2.0, 1.0};
    input.max_jerk = {4.0, 3.0, 2.0};
    // Set different constraints for negative direction
    input.min_velocity = {-2.0, -0.5, -3.0};
    input.min_acceleration = {-2.0, -2.0, -2.0};
    // We don't need to pass the control rate (cycle time) when using only offline features
    Trajectory<3> trajectory;
    // Calculate the trajectory in an offline manner (outside of the control loop)
    Result result = ruckig.calculate(input, trajectory);
    if (result == Result::ErrorInvalidInput) {
    std::cout << "Invalid input!" << std::endl;
    return -1;
    }
    // Get duration of the trajectory
    std::cout << "Trajectory duration: " << trajectory.get_duration() << " [s]." << std::endl;
    double new_time = 1.0;
    // Then, we can calculate the kinematic state at a given time
    std::array<double, 3> new_position, new_velocity, new_acceleration;
    trajectory.at_time(new_time, new_position, new_velocity, new_acceleration);
    std::cout << "Position at time " << new_time << " [s]: " << pretty_print(new_position) << std::endl;
    // Get some info about the position extrema of the trajectory
    std::array<Bound, 3> position_extrema = trajectory.get_position_extrema();
    std::cout << "Position extremas for DoF 4 are " << position_extrema[2].min << " (min) to " << position_extrema[2].max << " (max)" << std::endl;
    }
    Main interface for the Ruckig algorithm.
    Definition ruckig.hpp:27
    void at_time(double time, CustomVector< double, DOFs > &new_position, CustomVector< double, DOFs > &new_velocity, CustomVector< double, DOFs > &new_acceleration, CustomVector< double, DOFs > &new_jerk, size_t &new_section) const
    Get the kinematic state, the jerk, and the section at a given time.
    Definition trajectory.hpp:230
    double get_duration() const
    Get the total duration of the (synchronized) trajectory.
    Definition trajectory.hpp:285
    CustomVector< Bound, DOFs > get_position_extrema()
    Get the min/max values of the position for each DoF (only in Ruckig Pro)
    Definition trajectory.hpp:302
    Definition block.hpp:16
    Result
    Result type of methods calculating trajectories (e.g. Ruckig's and Trackig's update and calculate)
    Definition result.hpp:7
  • Python
    from ruckig import InputParameter, Ruckig, Trajectory, Result
    if __name__ == '__main__':
    inp = InputParameter(3)
    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 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}')
    # Get some info about the position extrema of the trajectory
    print(f'Position extremas are {trajectory.position_extrema}')

Output Trajectory