I’m trying to find out the angle a robot (holonomic) is traveling relative to the side walls of the field. I’m pretty sure that, when using field centric steering, the angle the robot should be traveling is represented by
theta = atan2(X,Y) * (180/pi);
//unit circle stuff
where X and Y are the axes on a joystick, but I need to know the angle the robot is actually traveling, so I think I need to use a gyro and accelerometer. Normally, I would need two coordinates to come up with the slope of a line which I could then find the angle from, but I’m not sure how to do this with a gyro and accelerometer. Has anyone done this before? Thanks!
The gyro gives you the angle of the robot relative to the robot’s position at power-up.
from Gyro.java in WPILib:
/**
* Use a rate gyro to return the robots heading relative to a starting position.
* The Gyro class tracks the robots heading based on the starting position. As the robot
* rotates the new heading is computed by integrating the rate of rotation returned
* by the sensor. When the class is instantiated, it does a short calibration routine
* where it samples the gyro while at rest to determine the default offset. This is
* subtracted from each sample to determine the heading.
*/
Thanks I knew that, though. The reason I need to figure out the angle relative to the sides is so that I can calculate the reflection angle off of any one or two walls. I was hoping it could be done computationally using just rangefinders and not the servo or accelerometer, but I think that might take some experimentation to get right. I know it would be easy to do if the robot was always facing the same direction, but it could be facing any direction when it’s near a wall. Thanks for your reply
The gyro gives you the angle the robot is facing relative to its starting position.
So if you start with the robot parallel to the sides then the gyro will give you the angle relative to the sides, which is what you said above you are looking for.
Not all robots will start parallel to the sides of the field. It’s often advantageous to NOT start parallel to the side, in which case, a “best guess” at the value probably won’t help.
You COULD do it with rangefinders, two to a side (one at each corner on each side of the robot)–“snap” a measurement and take the difference, which will give you two sides of the triangle, repeat to make sure you aren’t bouncing off another robot–but that’s probably more trouble than it’s worth.
However, I think there’s another way to do it, provided that you have a camera onboard that can track a vision target. If you can see the target, you can use the size to find how far away you are and the distortion from square (or circular) to find out your angle. If you think about it, this will also enable you to determine such items as whether you are in range to fire, your exact location on the field, and other things about position that you may desire to know. The problem? It might take a bit to figure out how to work it.
Simple is easy. You could just mount the gyro on something that rotates (bearing, bushing, whirling dervish, whatever) and align the gyro to the field for each match…
And lock the spinning device right before you start–say, a wedge between two plates. That might be the way to go. (Unless, of course, you like to think your robot is the Tasmanian Devil.)
We found the accelerometer to be not as useful as we thought, but others might have had different experiences.
If you use Java, you can simply call ‘gyro.reset;’ (“gyro” being whatever variable is assigned to the Gyro) to “zero” the Gyro. I would think that the easiest way would be to drive into any of the walls and assign a button to zero the Gyro. Just drive into the wall, zero the Gyro, and then you can tell the angle relative to the side.