I’m trying to write a simple Java code that will make our robot turn clockwise for a second and then turn counterclockwise until it reaches the original heading. I use gyro.reset() in autonomousInit() and then in autonomousPeriodic() have the following code:
How could I use what you just did with a FRC ADXRS450 Gyro Board that sits onto the roborio SPI slot? Is there a special line I put in for this specific gyro and location or can I just plug it in and paste your code and it work?
You put it in whatever class you need to use the gyro in. It can only be instantiated in one place though. If you’re doing a very simple auto program all within Robot.java, then you’d add this line in the same place that you instantiate other hardware such as your motor controllers in Robot.java.
We typically declare the gyro in class declaration area, then instantiate it in robotInit().