-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Using the Rev IMU to turn in Autonomous #678
Comments
Once you initialize the IMU hardware/code (in init as documented in the example), you can make simple calls to get the orientation update whenever you want it: private void checkOrientation() { This should work well in any autonomous code. Note that the orientation starts a 0 when the OpMode starts, so be in your starting position before you start the OpMode. |
Take a look at my library for more examples of autonomous functions. You can install the module if you want and just use the pre-built functions. |
So that code actually works quite well and I really appreciate it, but how do you reset the imu heading to 0 once you've turned? |
Do NOT init the gyro again. This process does not happen immediately, so you don't want to have to deal with the init process again. Most people just let the gyro run, and write your code so you can turn from any angle to any angle. This way there is no need to set it back to zero each turn. If you have a compelling reason to reset the heading to zero, simply have an intermediary variable that you use as a gyro offset. double live_gyro_value = 0; double getHeading( ) { Then when you want to reset heading back to zero, just update the offset.. void reset_gyro( ) { @gunvir103 Guessing is never the best policy ... |
Another benefit to what @gearsincorg mentioned is that it's more accurate since you turn to absolute headings instead of relative which will build error with each turn. |
This repo appears to be private? |
Thank you for your great advice. |
Different folks have different experiences here for some reason. My team routinely mounts their Expansion hubs in the vertical orientation with no problems. Before you fully commit, I would strongly recommend doing a temporary mount, and then using one of the sample GYRO programs to verify that the xyz axis rotations are what you expect. Double check that when you turn the robot, you know which axis orientation is changing, and which direction gives a +ve change. In fact, ANY time you use a sensor, it's always a good idea to do a temporary setup and look at how the data changes for your specific situation. Understanding how a sensor responds to the real world is probably THE most important lesson that can be learned as you start prototyping your robot. |
Our team members are trying to code our autonomous using the built-in imu on the rev hub to turn at a certain degree or angle. With the imu sample code provided, we haven't been able to achieve this. It provides a loop (if you were doing TeleOp code) but doesn't seem to have a place where we can place our autonomous code. This loop is nessessary in order to continue updating the telemetry and to continue updating the turning (heading) variable. But with this infinite loop here we are unsure how to run an autonomous in the same code. Is it possible to run this loop in the background while still having the autonomous running in real time or are there any other solutions to this problem.
The text was updated successfully, but these errors were encountered: