Package ca.teamdave.predicdave.pathmaking

Source Code of ca.teamdave.predicdave.pathmaking.LinearPathMaker

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ca.teamdave.predicdave.pathmaking;

import ca.teamdave.predicdave.pathmaking.linearpathtypes.ALD;
import ca.teamdave.predicdave.pathmaking.linearpathtypes.DALD;
import ca.teamdave.predicdave.pathmaking.linearpathtypes.DLD;
import ca.teamdave.predicdave.pathmaking.linearpathtypes.DSCurve;
import ca.teamdave.predicdave.pathmaking.linearpathtypes.SCurve;

/**
* Constructs a path for the provided start/end conditions and returns a
* Path object
* @author leigh
*/
public class LinearPathMaker {

    public static Path createPath(
            double curTime,
            double curPos,
            double curSpeed,
            final double destPos,
            double destSpeed,
            double Dmax,
            double Amax,
            double Vmax,
            final double epsilon) {
        // try all of the different path types (each attempt is O(1), so no real performace hit here)
        Path res = new DALD(curTime, curPos, curSpeed, destPos, destSpeed, Dmax, Amax, Vmax);
        if (res.selfValidate()) {
            return res;
        }
        res = new ALD(curTime, curPos, curSpeed, destPos, destSpeed, Dmax, Amax, Vmax);
        if (res.selfValidate()) {
            return res;
        }
        res = new SCurve(curTime, curPos, curSpeed, destPos, destSpeed, Dmax, Amax, Vmax);
        if (res.selfValidate()) {
            return res;
        }
        res = new DSCurve(curTime, curPos, curSpeed, destPos, destSpeed, Dmax, Amax, Vmax);
        if (res.selfValidate()) {
            return res;
        }
        res = new DLD(curTime, curPos, curSpeed, destPos, destSpeed, Dmax, Amax, Vmax);
        if (res.selfValidate()) {
            return res;
        }

        // if no path could be found, then give up and return a zero-feedforward path
        return new Path() {

            public double getPosition(double time) {
                return destPos;
            }

            public double getSpeed(double time) {
                return 0.0;
            }

            public double getAccel(double time) {
                return 0.0;
            }

            public boolean isDone(double time, double position) {
                return Math.abs(position - destPos) <= epsilon;
            }

            public boolean selfValidate() {
                return true;
            }
        };
    }

}
TOP

Related Classes of ca.teamdave.predicdave.pathmaking.LinearPathMaker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.