Go to Post ...It's like Christmas morning and waiting to see if Santa got you that soldering iron you wanted. - CLandrum3081 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2012, 20:21
adf0221 adf0221 is offline
Registered User
FRC #1517 (Lumberjacks)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Bow NH
Posts: 24
adf0221 is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 03-02-2012, 20:48
BurtGummer BurtGummer is offline
Electrical/Mechanical/Programming
FRC #3020
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Southern CA
Posts: 89
BurtGummer will become famous soon enoughBurtGummer will become famous soon enough
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();
Does that help?
__________________
I'm a mentor looking for a home in Southern California! I know Java, C++, electrical and mechanical.

Need Java or C++ help? Send me a PM!
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2012, 09:41
adf0221 adf0221 is offline
Registered User
FRC #1517 (Lumberjacks)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Bow NH
Posts: 24
adf0221 is an unknown quantity at this point
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-02-2012, 10:16
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Integrating Gyro Code

Quote:
Originally Posted by adf0221 View Post
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.
You could try using simple trapezoidal integration:

Code:
read the new_rate

new_position = ½(new_rate + previous_rate)*cycle_time

previous_rate = new_rate
"cycle_time" would be 0.02 seconds if you're doing this in TeleOp

Is that what you meant?

Reply With Quote
  #5   Spotlight this post!  
Unread 04-02-2012, 10:33
adf0221 adf0221 is offline
Registered User
FRC #1517 (Lumberjacks)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Bow NH
Posts: 24
adf0221 is an unknown quantity at this point
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?
Reply With Quote
  #6   Spotlight this post!  
Unread 04-02-2012, 10:51
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Integrating Gyro Code

Quote:
Originally Posted by adf0221 View Post
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?
I don't understand the question. What do you mean by "refreshing the gyro value after you use it the first time"?

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.

Reply With Quote
  #7   Spotlight this post!  
Unread 04-02-2012, 10:53
adf0221 adf0221 is offline
Registered User
FRC #1517 (Lumberjacks)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Bow NH
Posts: 24
adf0221 is an unknown quantity at this point
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?
Reply With Quote
  #8   Spotlight this post!  
Unread 04-02-2012, 11:01
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 990
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Integrating Gyro Code

Quote:
Originally Posted by Ether View Post
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 depends what template is being used. In the Simple Template you add your own loop and it will not necessarily run every 20 ms, the TeleopPeriodic method of the Iterative template will run ~ every 20ms provided your code in that method returns in less than 20ms.

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.
Reply With Quote
  #9   Spotlight this post!  
Unread 04-02-2012, 11:17
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Integrating Gyro Code

Quote:
Originally Posted by RufflesRidge View Post
That depends what template is being used. In the Simple Template you add your own loop and it will not necessarily run every 20 ms, the TeleopPeriodic method of the Iterative template will run ~ every 20ms provided your code in that method returns in less than 20ms.

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.
I'm not intimately familiar with the FRC Java Framework so I can't comment in detail about RufflesRidge's comments above, but I will add the following remarks:

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.

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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