Go to Post I believe there is a strong link between a reliable drivetrain and an inspirational FIRST season. - Joe Johnson [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-03-2015, 20:31
RobOTies RobOTies is offline
Registered User
FRC #5122
 
Join Date: Mar 2015
Location: Old Town, ME
Posts: 3
RobOTies is an unknown quantity at this point
JAVA code to drive straight using H-drive

We are a second year team and are using 6" omni wheels in an H-drive configuration for the first time. Our robot tends to veer left when we are trying to drive straight ahead during auto and teleop, and I was wondering if anyone would be willing to share any code ideas that would help with this issue. We have a gyro as well, but not sure how to effectively utilize it for this purpose. We have already tried making sure the gear boxes that are attached to CIM motors are as identical as possible.

Go robots! Thank you!!
Reply With Quote
  #2   Spotlight this post!  
Unread 01-03-2015, 21:09
kinganu123 kinganu123 is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Piscataway, NJ
Posts: 243
kinganu123 is on a distinguished road
Re: JAVA code to drive straight using H-drive

FIRST gave an example on their docs as to how you can accomplish driving straight using a gyro. However, just be wary that gyros don't always work as well as you want it to.
http://wpilib.screenstepslive.com/s/...ving-direction
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 01-03-2015, 21:26
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: JAVA code to drive straight using H-drive

The usual way to ensure you're driving straight is to put encoders on your wheel gearboxes, and get both sides going at the same speed. As long as the wheels don't slip, you can make this work by creating a PID on each axle based on speed, and set the target speed from your joysticks rather than the voltage. If you have time to do this, this is the better solution.

However, you probably don't have time, and you already have a gyroscope. During teleop, you're probably better off letting the driver compensate, unless you really do have a "directly forward" control (which means, among other things, not arcade or tank controls). If you do have a "directly forward", do the same as for autonomous below.

Autonomous: First, calibrate the gyroscope to determine the value received when the robot is not rotating. Then, as you're driving forward (or reverse), periodically check the rotation rate. If you are rotating to the left, decrease the right voltage a bit (or increase the left). Likewise, if you are rotating right, decrease the left voltage speed a bit. As you drive, continue the decrease/increase until the rotation rate is the desired value of zero.

As noted above, a gyroscope won't pinpoint you in an exact spot, but it may get you close enough so that you can use other sensors (rangefinders, touch sensors, etc) to get exactly where you want to be.

BTW, we've lost three analog KoP gyroscopes in the past year, two during this year's build season. If you can't get things working with the gyroscope, try checking it with a voltmeter or reading the values from it directly to verify that the hardware is still working.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 01-03-2015 at 21:29.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-03-2015, 22:05
RobOTies RobOTies is offline
Registered User
FRC #5122
 
Join Date: Mar 2015
Location: Old Town, ME
Posts: 3
RobOTies is an unknown quantity at this point
Re: JAVA code to drive straight using H-drive

Thank you for the suggestions! We did put encoders on both gearboxes before we bagged up, but we weren't sure how to use them with PIDs. Any tips on setting the constant values if we try using velocity? Will that work in auto since the robot would not be getting input from a joystick?

I'm a little confused about how to control the voltages independently for each axis because we use arcade drive. Is there another drive class that would work better for this task?

We will check the gyro when we unbag - thank you for that tip!
Reply With Quote
  #5   Spotlight this post!  
Unread 01-03-2015, 22:36
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by GeeTwo View Post
BTW, we've lost three analog KoP gyroscopes in the past year, two during this year's build season.
That seems kind of odd, given that we have used to exact same KOP gyro for two years without any problems.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #6   Spotlight this post!  
Unread 01-03-2015, 23:32
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by GeeTwo View Post
BTW, we've lost three analog KoP gyroscopes in the past year, two during this year's build season. If you can't get things working with the gyroscope, try checking it with a voltmeter or reading the values from it directly to verify that the hardware is still working.
Quote:
Originally Posted by lopsided98 View Post
That seems kind of odd, given that we have used to exact same KOP gyro for two years without any problems.
I agree that it's odd. Our 4 KoP gyroscopes were the literal KoPs from the previous 3 years, and one we bought our first year; all four were working in Jan 2014. I would have thought we were doing something wrong electrically, but one of them was working before lunch break, and did not come up after lunch break. No one was working on the robot during that time, apart from the battery change. I suppose the warranties are running out. I just wanted to throw this out to try to keep other teams from spending as many hours as we did trying to get a navigation system work because we were focused on software and ignored the hardware.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #7   Spotlight this post!  
Unread 01-03-2015, 23:42
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by RobOTies View Post
We did put encoders on both gearboxes before we bagged up, but we weren't sure how to use them with PIDs. Any tips on setting the constant values if we try using velocity? Will that work in auto since the robot would not be getting input from a joystick?

I'm a little confused about how to control the voltages independently for each axis because we use arcade drive. Is there another drive class that would work better for this task?
From screenstepslive:
Quote:
You can use RobotDrive with other types of speed controllers as well. In this case you must create the speed controller objects manually and pass the references or pointers to the RobotDrive constructor.
The speed controller in this case would have both the actual speed controller and a PID "front end". This is described at this page.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #8   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
  #9   Spotlight this post!  
Unread 02-03-2015, 12:12
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is online now
Not Allowed Near Power Tools
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 162
nickbrickmaster is an unknown quantity at this point
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by GeeTwo View Post
I agree that it's odd. Our 4 KoP gyroscopes were the literal KoPs from the previous 3 years, and one we bought our first year; all four were working in Jan 2014. I would have thought we were doing something wrong electrically, but one of them was working before lunch break, and did not come up after lunch break. No one was working on the robot during that time, apart from the battery change. I suppose the warranties are running out. I just wanted to throw this out to try to keep other teams from spending as many hours as we did trying to get a navigation system work because we were focused on software and ignored the hardware.
We lost a gyro during competition this weekend because the roboRIO decided to output 12v instead of 5v and melted the cable off the gyro. Another one just didn't work when we got it. I'm switching to I2C gyros or maybe the navX.
Reply With Quote
  #10   Spotlight this post!  
Unread 02-03-2015, 12:56
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by nickbrickmaster View Post
the roboRIO decided to output 12v instead of 5v
Was this intended as this a joke? Hard to tell.


Reply With Quote
  #11   Spotlight this post!  
Unread 02-03-2015, 15:51
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is online now
Not Allowed Near Power Tools
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 162
nickbrickmaster is an unknown quantity at this point
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by Ether View Post
Was this intended as this a joke? Hard to tell.


Sorry, it was not. Our auto started acting up during testing and we decided to check the gyro. The circuit was extremely hot, and upon investigating, the male PWM pins had melted up to the header. I checked the analog input with a multimeter to discover that what should have been 5v with a 2.5v signal pin was getting 12v with a 2.5v signal pin. We got a new gyro from spare parts, switched the pin in the code, and have not run into the problem again.

It was most likely some kind of short, but we have a cover on the gyro as well as a mounting plate, and Cable Magics on all the 3-pin roboRIO ports.
Reply With Quote
  #12   Spotlight this post!  
Unread 02-03-2015, 19:52
techplex's Avatar
techplex techplex is offline
Blake B
AKA: Blake
FRC #4909 (The Bionics)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2007
Location: Massachusetts
Posts: 95
techplex is just really nicetechplex is just really nicetechplex is just really nicetechplex is just really nice
Re: JAVA code to drive straight using H-drive

@Joe can you share the getDegreesFromEncoderValues method? That is the part we are having trouble with.
Quote:
Originally Posted by Joe Derrick View Post
Robot.driveTrain.getDegreesFromEncoderValues(); .
__________________
Blake
Electrical, Programming and Design

Creator FRC Q&A 2017
Mass FRC Team 4909: The Bionics
Maine FRC Team 5122: The RobOTies (2014-2015)
Maine FRC Team 2648: Infinite Loop (2008-2011)
Reply With Quote
  #13   Spotlight this post!  
Unread 04-03-2015, 09:17
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

sure

Quote:
public double getDegreesFromEncoderValues(){

double leftDistance = Robot.drivetrain.leftEncoder.getDistance();
double rightDistance = Robot.drivetrain.rightEncoder.getDistance();
double robotArcLength = (leftDistance-rightDistance)/2;
double robotDegrees = 360*(robotArcLength/(Math.PI*wheelbase);

return robotDegrees;
}
__________________
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
  #14   Spotlight this post!  
Unread 04-03-2015, 09:49
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by Joe Derrick View Post
double robotArcLength = (leftDistance-rightDistance)/2;
double robotDegrees = 360*(robotArcLength/(Math.PI*wheelbase);
You want to use the trackwidth (distance between left and right wheels), not wheelbase (distance between front and back wheels).


Reply With Quote
  #15   Spotlight this post!  
Unread 04-03-2015, 11:17
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: JAVA code to drive straight using H-drive

Quote:
Originally Posted by Joe Derrick View Post
double robotArcLength = (leftDistance-rightDistance)/2;
double robotDegrees = 360*(robotArcLength/(Math.PI*wheelbase);
Also, that should be 180, not 360. If your left wheels have traveled an extra track width, you will have turned one radian (57 degrees), not two (114 deg). If you're just using this for a PID, it probably didn't matter, because you wound up dividing all your PID constants by 2 in the tuning. It should read:

Code:
double robotArcLength = (leftDistance-rightDistance)/2;
 double robotDegrees = 180*(robotArcLength/(Math.PI*trackWidth);
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
Reply


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 18:06.

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