Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Gyro angle in simulation vs reality? (http://www.chiefdelphi.com/forums/showthread.php?t=121409)

GuyM142 08-11-2013 14:57

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 :(

Chris Hibner 08-11-2013 15:09

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

GuyM142 08-11-2013 15:22

Re: Gyro angle in simulation vs reality?
 
Quote:

Originally Posted by Chris Hibner (Post 1301032)
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

Ok, I understand now how to solve it.
Is it like this in the KIT gyro too?

billbo911 08-11-2013 15:30

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.

GuyM142 08-11-2013 16:08

Re: Gyro angle in simulation vs reality?
 
Quote:

Originally Posted by billbo911 (Post 1301035)
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.

Ok, so for my needs continuous increase/decrease would be the best "convertion" of the gyro volts readings.
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.

billbo911 08-11-2013 19:52

Re: Gyro angle in simulation vs reality?
 
1 Attachment(s)
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.

Ether 08-11-2013 22:03

Re: Gyro angle in simulation vs reality?
 
Quote:

Originally Posted by GuyM142 (Post 1301036)
Ok, so for my needs continuous increase/decrease would be the best "convertion" of the gyro volts readings.

Would you mind sharing with us what you are trying to accomplish and how you determined that a continuous increase/decrease sensor output would be best?

Quote:

Now, the default code is giving me +/-180 degrees range...
Interesting. In Java, the gyro angle is returned as a continuous increase/decrease from the starting value:

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:

I'd like to have a vi that gets X degrees as an input and moves the robot X degrees CW
Is there a reason you always want to rotate the robot clockwise? In other words, if "X" is 359 degrees wouldn't it be better to rotate the robot 1 degree counter-clockwise?



GuyM142 09-11-2013 03:27

Quote:

Originally Posted by billbo911 (Post 1301064)
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.

That's the vi I'm using, but it works differently in the simulator.
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 :)

Greg McKaskle 09-11-2013 06:22

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

GuyM142 09-11-2013 10:51

Re: Gyro angle in simulation vs reality?
 
Quote:

Originally Posted by Greg McKaskle (Post 1301164)
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

I can't really change the code inside the gyro VI, I get to a level where I need to enter a password in order to make changes to the VI.
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.

Ether 09-11-2013 15:02

Re: Gyro angle in simulation vs reality?
 
Quote:

Originally Posted by GuyM142 (Post 1301154)
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...

I hope I've explained it well :)

It's still not clear to me what you are trying to do. If it doesn't matter which direction, what's wrong with taking the shortest angle to get to the target?

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).



Joe Ross 10-11-2013 07:34

Re: Gyro angle in simulation vs reality?
 
Quote:

Originally Posted by GuyM142 (Post 1301213)
I can't really change the code inside the gyro VI, I get to a level where I need to enter a password in order to make changes to the VI.

Greg's suggestion was to make your own VI that looked for a rollover from 180 to -180, and when that happened, add 360 to the gyro output. If you kept a running total of gyro rollovers, this would work forever. This doesn't require any changes to the simulation.

Quote:

Originally Posted by GuyM142 (Post 1301213)
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.

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.

Ether 10-11-2013 14:39

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



GuyM142 13-11-2013 13:22

Re: Gyro angle in simulation vs reality?
 
1 Attachment(s)
Quote:

Originally Posted by Ether (Post 1301413)

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



Thank you! that's what I was looking for.
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) :)

Doug Norman 14-11-2013 08:59

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.


All times are GMT -5. The time now is 17:57.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi