
24-03-2015, 15:25
|
 |
 |
Taking a year (mostly) off
 FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
|
|
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
|
|
|
Re: Anti-tipping algorithm
Quote:
Originally Posted by NotInControl
Cool idea. For anyone that wants to try this. You don't need to buy any additional sensors, the RoboRio has a built in accelerometer, and you can use that alone to sense pitch and roll angles, depending on how the RoboRio is mounted with relation to your Robot.
Here is some code to get you started:
Code:
public static double getAccPitch() {
double Y = Robot.accel.getY();
double Z = Robot.accel.getZ();
return Math.atan2(Y,Z) *180 /Math.PI;
}
public static double getAccRoll()
{
double X = Robot.accel.getX();
double Y = Robot.accel.getY();
double Z = Robot.accel.getZ();
return Math.atan2(-X, Math.sqrt(Y*Y + Z*Z)) * 180/Math.PI;
}
You will need to switch the methods if you mount your RoboRio vertically.
To access the built-in accelerometer in the RoboRio simply do this:
Code:
public static BuiltInAccelerometer accel;
accel = new BuiltInAccelerometer();
The above code assumes you instantiated the accelerometer in Robot.java, but you can do it anywhere you like.
Hope this helps,
Regards,
Kevin
|
This approach will make it appear that your robot is pitching or rolling any time you have acceleration due to any force other than gravity (such as the reactive force exerted by the carpet against the tractive force of your wheels).
|