Go to Post Engineers can really make a difference when people are in their time of need. - Elgin Clock [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 02-03-2015, 11:42
Joe Derrick's Avatar
Joe Derrick Joe Derrick is offline
Mentor - Programming
FRC #0319
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Prospect Mountain High School
Posts: 48
Joe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of light
Re: JAVA code to drive straight using H-drive

This is our auto drive straight command for our robot this year.
We are using command based programming and java.
We used the RobotBuilder "PIDCommand" as a template that we modified to what you see below.

It drives forward at a set speed and maintains an angle using values from encoders on each side of the drivetrain.
We have removed some parts of the code as they are specific to our robot.
Hopefully this is of use to you.

Quote:
public class AutoDriveStraight extends PIDCommand {

double driveSpeed = 0;
public AutoDriveStraight(double speed) {

super("AutoDriveStraight", 0.25, 0.0, 0.0, 0.02);

//we set our P to be 0.25 but this will need tuning.

getPIDController().setContinuous(false);
getPIDController().setAbsoluteTolerance(1.0);
driveSpeed = speed;


requires(Robot.driveTrain);

}
protected double returnPIDInput() {

return Robot.driveTrain.getDegreesFromEncoderValues();

//This is a method that uses Encoders and a formula
//to calculate a degree value. You could use the
//difference between the drivetrain encoders.

}
protected void usePIDOutput(double output) {

Robot.driveTrain.arcadeDrive(driveSpeed, output);

//This is a method within our Drivetrain subsystem.
//The driveSpeed is the constant, and the
//PIDController maintains the Setpoint set below.

}

protected void initialize() {



this.setSetpoint(0);

// This maintains the previously calculated
//degrees from the PIDInput at 0. ie: "Straight ahead"

this.getPIDController().enable();

}

protected void execute() {
}

protected boolean isFinished() {

return //a boolean that tells when you want your command to finish

}

protected void end() {
}

protected void interrupted() {
}
}
__________________
2010-2017 Mentor Team 319
2012 - Rockwell Automation Award Winner
2014 - Xerox Creativity in Engineering Winner, Archimedes Division
2015 - Rockwell Automation and Gracious Proffesionalism Winner, Tesla Division
2016 - North Shore and UNH District Event Winner, Carson Division
http://www.frc319.com
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 22:29.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi