|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Integrating Gyro Code
Hi, my programming team is trying to use three gyroscopes on our robot this year and we know that there are only two FPGA ports that can actively integrate the inputs and give us an angle. We are currently trying to figure out how to integrate the rate that we can obtain with using an analog channel in order to give us the displacement of the gyroscope but are struggling. Has anyone had any success with this? If so how did you manage it?
|
|
#2
|
|||
|
|||
|
Re: Integrating Gyro Code
Like you mentioned, just use an analog input on the analog cRIO module. Be sure that the gyro is wired correctly too.
Then in Java, simply create a new gyro object. Code:
Gyro newGyro = new Gyro(1); // '1' is what channel the input is attached to on the module. Change it if necessary. // The below code is to get the current angle of the gyro. double gyroAngle; gyroAngle = newGyro.getAngle(); |
|
#3
|
|||
|
|||
|
Re: Integrating Gyro Code
We have the first two of our gyros working with that code, however the third one cannot perform that code because there are only two FPGA ports that are active on the crio. We need to write an integral to take the rate that plugging the gyro into the analog port and using the analogchannel in the code.
|
|
#4
|
||||
|
||||
|
Re: Integrating Gyro Code
Quote:
Code:
read the new_rate new_position = ½(new_rate + previous_rate)*cycle_time previous_rate = new_rate Is that what you meant? |
|
#5
|
|||
|
|||
|
Re: Integrating Gyro Code
Yes that's exactly what we needed! thanks a bunch! do you have any recommendation as to how we would implement this, mainly refreshing the gyro value after we use it the first time?
|
|
#6
|
||||
|
||||
|
Re: Integrating Gyro Code
Quote:
The code I showed you should be in TeleOp so that it runs every time TeleOp runs (which is about once every .02 seconds). That is to say, every time TeleOp runs you should read the new rate from the gyro and calculate the new position. |
|
#7
|
|||
|
|||
|
Re: Integrating Gyro Code
How would the code work so that the previous rate and the new rate are not the same values? How would you introduce that delay into the program?
|
|
#8
|
|||
|
|||
|
Re: Integrating Gyro Code
Quote:
It also depends on what you are using the gyro for and if it has to keep track of it's orientation starting at the very beginning of the match. To do that you could make an object called something like CustomGyro that extends AnalogChannel and add the appropriate variables and code Ether listed. Instantiate a copy of your object in RobotInit, then call your CustomGyro.Integrate method from AutonomousPeriodic, TeleopPeriodic and DisabledPeriodic (if the robot might be turning at the beginning of auto and continue rotating a bit in disabled, otherwise leave this one out to avoid drift) If you really need precision you probably need to calculate the delta time each time you go to integrate instead of trusting it to be ~20ms. |
|
#9
|
||||
|
||||
|
Re: Integrating Gyro Code
Quote:
Whatever rate you are doing the integration at, that's the cycle_time you should use in the integration. And, as mentioned above, if that rate is not expected to be very steady, it might help to measure the actual elapsed time each cycle and use that elapsed time in your calculation. If you are concerned about gyro drift, you should add a button that the driver can press during the match to zero the gyro when it's at a known position. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|