Giter VIP home page Giter VIP logo

trajectory-planner's Introduction

State-Space Trajectory Planner

Given N dimensional sequential waypoints, this code will develop a n dimensional path that yields a smooth transition between states in real time.

The final path will be given in time intervals of the frequency of the motor controller, allowing for seemless integration into any control system.

PIDs are most commonly used to go from point n-1 -> point n -> point n+1. To have the most success, one should compute a motion profile that will follow the smooth path.

Alt text

Alt text

C

Declare a 2d array of your original way points

    int num_points = 5;
    int dim_points = 2;
    float** points = malloc(num_points * sizeof(float*));
    for (int i = 0; i < num_points; i++) {
      points[i] = malloc(dim_points * sizeof(float));
    }
    
    //populate points with values here....

then the maximum time you want this path to be completed in, as well as your motor controller's frequency

    float totalTime = 15;
    float timeStep = .1;

Call smoothPath, which returns a 2d array (float) of your path, that starts at [1][0]. )[0][0] stores the length of the pointer, which includes the first slot.

    float** sPath = smoothPath(num_points, dim_points, points, totalTime, timeStep);

to read the values

        for(int i = 1; i < sPath[0][0]; i++) {
            for(int j = 0; j < dim_points; j++) {
            //do something with sPath[i][j]
            }
        }

Java

Declare a 2d array of your original way points

        double[][] waypoints = new double[][]{
                {1, 2},
                {2, 7},
                {4, 7},
                {6, 9},
                {10, 11}
        };

then the maximum time you want this path to be completed in, as well as your motor controller's frequency

    double totalTime = 15;
    double timeStep = .1;

Construct a new PathPlanner class, set optimization parameters (optional), then call .calculate to generate the smoothPath.

        final PathPlanner path = new PathPlanner(waypoints);

        path.setPathAlpha(0.7);
        path.setPathBeta(0.3);
        path.setPathTolerance(0.0000001);
        path.calculate(totalTime, timeStep);

The smooth path will be stored in

    path.smoothPath

Python

Declare a 2d array of your original way points

    points = [[1, 2], [2, 7], [4, 7], [6, 9], [10, 11]]

then the maximum time you want this path to be completed in, as well as your motor controller's frequency

    total_time = 15
    time_step = .1

Now call smooth_path

    path = smooth_path(points, total_time, time_step)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.