|
Re: Anti-tipping algorithm
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;
}
This assumes a horizontal, mounted, upright RoboRio. You will need to modify the methods if you mount your RoboRio vertically by changing which acceleration vectors it uses.
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
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner
Last edited by NotInControl : 24-03-2015 at 15:19.
|