|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Gyro angle in simulation vs reality?
The gyro in the simulation gives angles between -180 to 180 and when it reaches 180 it goes to -180.
Is it like this in real life gyros? It makes it hard to make the simulation robot turn 180 degrees or more ![]() |
|
#2
|
||||||
|
||||||
|
Re: Gyro angle in simulation vs reality?
See this post: http://www.chiefdelphi.com/forums/sh...6&postcount=18
There are also some other great posts in that thread on this topic. Here's the thread: http://www.chiefdelphi.com/forums/sh....php?p=1182626 Last edited by Chris Hibner : 08-11-2013 at 15:11. |
|
#3
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Quote:
Is it like this in the KIT gyro too? |
|
#4
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
The gyro is not the issue. The issue is how the code is interpreting and displaying the data that sensor is sending to it. For all intents, any gyro running this particular could would behave the same way.
If you want the values to continue to increase/decrease, then the code must be written that way. The gyro is just a sensor. What the code does is take the sensors output an converts it into something useable. |
|
#5
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Quote:
Now, the default code is giving me +/-180 degrees range and I can't change it so I'll have to use it that way. I'd like to have a vi that gets X degrees as an input and moves the robot X degrees CW, can I have some help with that? If my current Angle is 90 and I want to move 100 degrees CW, I should end up at -170.. I don't know how to get to that. Last edited by GuyM142 : 08-11-2013 at 16:56. |
|
#6
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
I'm not sure which example you are using, but here is what I found.
If you open LV and click on "Support". Then select Find FRC Examples, you will find a Gyro example under the Analog folder. The Get Angle vi returns two things: The current angle relative to where the robot started, and the current angular rate of rotation. If you use the "Get Angle" output, I believe you will find what you are looking for. See the attached image. |
|
#7
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Quote:
Quote:
Code:
/**
* Return the actual angle in degrees that the robot is currently facing.
*
* The angle is based on the current accumulator value corrected by the oversampling rate, the
* gyro type and the A/D calibration values.
* The angle is continuous, that is can go beyond 360 degrees. This make algorithms that wouldn't
* want to see a discontinuity in the gyro output as it sweeps past 0 on the second time around.
*
* @return the current heading of the robot in degrees. This heading is based on integration
* of the returned rate from the gyro.
*/
Quote:
|
|
#8
|
||||
|
||||
|
Quote:
I think that the cRIO version of it would work the way I want to. What I'm trying to accomplish is a vi which turns X degrees (rather than the shortest way to a certain angle), it doesn't even matter in which direction because I get stuck whenever the (current angle + degrees to rotate) is bigger than 180 or smaller than -180. (The problem is the same for "rotate the shortest way to angle X, but leave it for now) I hope I've explained it well ![]() |
|
#9
|
|||
|
|||
|
Re: Gyro angle in simulation vs reality?
The WPILiib VIs should behave the same for a simulated, analog, and digital gyro. The conventions of the simulator were quite different and had to be manipulated in order to fit into WPILib, and it seems like you've discovered a bug.
If you select the gyro VI in your code and choose Edit>>Create SubVI, it will wrap the WPILib version in a simple subVI. Try to modify it to make the simulated one behave the same as real-world, then use that instead until the bug gets fixed. Greg McKaskle |
|
#10
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Quote:
But i noticed that the angle value is coming from a a Honeywell Compass reference. I don't get it.. why would the VI called gyro and inside it'll be a compass? The gyro output really does behave like a compass would. |
|
#11
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Quote:
Let's say at some point in time your gyro reads "g" degrees and you want the robot to rotate X degrees CW from that reading. Compute target_angle = g + X at that point in time. Then use that target_angle in each iteration of your closed-loop controller as follows: error = target_angle - gyro_reading; error = error - 360.0*floor(0.5 + error/360.0); Then set your SetPoint and ProcessVariable inputs to your closed-loop controller as follows: SetPoint= error; ProcessVariable = 0; or SetPoint=0; Process_Variable= -error; ( choose one or the other depending on how your closed-loop controller handles d/dt(error) ) Once you've turned the desired X degrees, you can receive a new X command and compute a new target_angle and start the process anew. Or you can re-start the process if you receive a new X command before the previous one has completed. Example: The gyro reads 179 degrees and you want to rotate 10 degrees CW. Compute target_angle = 179 + 10 = 189 degrees first iteration: error = 189 - 179 = 10 error = 10 - 360.0*floor(0.5 + 10/360.0) = 10 SetPoint= 10; ProcessVariable = 0; assume that the gyro angle increases by 2 degrees (from 179 to -179) and now look at the second iteration of the closed-loop controller: error = 189 - (-179) = 368 error = 368 - 360.0*floor(0.5 + 368/360.0) = 8 SetPoint= 8; ProcessVariable = 0; ... and so on until the target of 189 is reached (at which point the gyro will read -171 degrees). Last edited by Ether : 09-11-2013 at 19:19. Reason: added example |
|
#12
|
||||||
|
||||||
|
Re: Gyro angle in simulation vs reality?
Quote:
The trick in simulation is to make something that isn't real work "close enough" to something that is real. In this case, most teams are interested in the angle from the gyro. Rather then spend thousands of dollars to make a computer model of a gyro, they used a compass that was already implemented, and produced very similar data. As you noted, it is different in the rollover, however that is easily compensated for. |
|
#13
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Here's a possible implementation of Joe's suggestion. Code:
// initialization: alpha=Go=getGyroReading(); // range -180 to +180 // iteration: G=getGyroReading(); d=G-Go; Go=G; if (d>180) d-=360; else if (d<-180) d+=360; alpha+=d; // alpha is the continuous angle reading you've been asking for |
|
#14
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
Quote:
My goal was to make the simulated gyro work like a real FRC gyro for new programmers training. I've attached my implementation (this is in periodic tasks) ![]() |
|
#15
|
||||
|
||||
|
Re: Gyro angle in simulation vs reality?
I implemented the simulation code. The gyro should work the same as a real robot gyro. You should try a real one - if they differ I will fix the simulated. The reason you see compass VIs down within the simulated gyro is because I used subVIs that already existed as part of our robotics module (a separate commercial module that is not part of FRC). For simulation it doesn't matter what is in the bowels of the code, only that the top layer acts like a gyro.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|