Giter VIP home page Giter VIP logo

motion-profile-generator's Introduction

ARCHIVED

Our new motion profile generator library can be found under the motion-profiling module in our new libraries project: https://github.com/MittyRobotics/tko-libraries

OLD LIBRARY, USE AT YOUR OWN RISK

Simple motion profile generator for FRC teams.

JavaDocs: https://mittyrobotics.github.io/motion-profile-generator/

Getting Started

This project can be imported using jitpack.io.

Go to https://jitpack.io/#Mittyrobotics/motion-profile-generator for detailed instructions on how to add this to your project using Gradle, Maven, Sbt, or Leiningen aswell as copy and paste code for the latest version.

Gradle Add this to your root build.gradle:
allprojects {
 repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency:

dependencies {
    compile 'com.github.Mittyrobotics:motion-profile-generator:ENTER_LATEST_VERSION_HERE'
}

Replace ENTER_LATEST_VERSION_HERE with the latest version shown on the badge at the top of the README.

Maven Add the JitPack repository to your build file:
<repositories>
	<repository>
		   <id>jitpack.io</id>
		   <url>https://jitpack.io</url>
	</repository>
</repositories>

Add the dependency:

<dependency>
	   <groupId>com.github.Mittyrobotics</groupId>
	   <artifactId>motion-profile-generator</artifactId>
	   <version>ENTER_LATEST_VERSION_HERE</version>
</dependency>

Replace ENTER_LATEST_VERSION_HERE with the latest version shown on the badge at the top of the README.

Usage

To create a motion profile:

double acceleration = 5; 		//units/sec^2
double deceleration = 5; 		//units/sec^2
double maxVelocity = 10; 		//units/sec
double startVelocity = 0; 		//units/sec
double endVelocity = 0; 		//units/sec
double lowerPositionBound = 0; 		//units
double upperPositionBound = 124.5; 	//units
double currentPosition = 22.4; 		//units
double setpoint = 80; 			//units

VelocityConstraints velocityConstraints = new VelocityConstraints(
acceleration, 
deceleration, 
maxVelocity, 
startVelocity, 
endVelocity
);  

MechanismBounds mechanismBounds = new MechanismBounds(
currentPosition,
lowerPositionBound,
upperPositionBound
);  

TrapezoidalMotionProfile motionProfile = new TrapezoidalMotionProfile(
setpoint,
velocityConstraints,
mechanismBounds
);

VelocityConstraints contain the maximum acceleration, maximum deceleration, maximum velocity, starting velocity, and ending velocity of the motion profile. MechanismBounds contain the current position of the mechanism as the motion profile is instantiated, the mechanism's minimum position bound, and the mechanism's maximum position bound. The TrapezoidalMotionProfile takes in the setpoint, the VelocityConstraints, and the MechanismBounds.

Now that the motion profile is generated, you can get the acceleration, velocity, and position value for an input timestamp using:

double t = 2.43; 				//seconds

MotionFrame frame = motionProfile.getFrameAtTime(t);

double position = frame.getPosition();		//units
double velocity = frame.getVelocity();		//units/sec
double acceleration = frame.getAcceleration();	//units/sec^2

Normally, to follow the motion profile you want to loop through the motion profile periodically and get the current position value for the time since you began following the motion profile. FRC Commands and Subsystems tip: If you are using the FRC commands and subsystems format, commands have a function to get the time since the command began, which comes in handy while following a motion profile:

double t = timeSinceInitialized(); //Time in seconds since the command has been initialized, this is usually the time you would want to get a motion frame from

Visualizing a motion profile

The library has a built in class to allow you to graph a motion profile. This uses JFreeChart to graph the values of the motion profile over time. Simply create a new GraphMotionProfile object and input the desired motion profile to graph as a parameter:

new GraphMotionProfile(motionProfile);

Here is the output graph using the demo code above:

Dark Theme Graphs!

motion-profile-generator's People

Contributors

oleather avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

motion-profile-generator's Issues

Want Help?

I've been watching you work on this for a while. Just wondering if you want any help with anything since you seem dedicated.

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.