FIRST Tech Challenge Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

HiTechnic Gyro - suggestions for encapsulating in SubVi? (Archived)

Solved!
Go to solution

Update: This discussion applies to Issues from the 2010 FTC season and is no longer relevant for current FTC competition software.

The HiTechnic Gyro is nativly supported in LabVIEW for LEGO MINDSTORMS. You can find it in the schematic editor and in the HiTechnic Palette.


I am trying to create 2 LabView Blocks for the HiTechnic Gyro for the NXT.

1. GyroInit - reads the gyro a bunch of times, takes the average and produces the result as a GyroOffset or Bias value for the zero point.

2. GyroRead - reads the gyro and produces the angular velocity and also integrates it and produces current estimated Heading.

I think my question will reveal that I really don't "get" how to create a function block with history in LabView.

Note: the actual reading of the gyro is no problem - the .vi provided by HiTechnic works fine.

I started with the Gyro example from HiTechnic called GyroSample.vi

It is a program with a while loop on the left which loops until it gets about a hundred consistent readings, then takes the average and exits that loop.  Downstream from that is a while loop which repeatedly reads the gyro and subtracts the offset previously calculated and plots that on a chart.

I thought it would be good style to break this into two reusable sub-vi's, one called GyroInit and one called GyroRead (my attempt attached).

Each of these vi's seem to work OK if I just run them by themselves.

Then I thought I could plop these sub vi's down on a new control block diagram and hook the offset from one to the other and then take the output from the GyroRead block and use it in the balance of my program, for example display on a chart.

That is in GyroTest.vi

Nothing changes in the GyroTest front panel.

If I drill down into the GyroInit and GyroRead front panels, they are displaying data just as I would hope.  But I can't figure out how to get it to come out of the GyroRead block so that I can use it in GyroTest.

Anyone have suggestions?

Thanks much.

David

Download All
0 Kudos
Message 1 of 7
(10,257 Views)

Hi David,

The problem is that the loop in GyroRead.vi never ends and thus never returns the data to the calling program. If a subVI doesn't end, the calling VI does not receive its output. To resolve this problem, you can remove the loop from the subVI and then move the modified subVI into the same loop as your indicators in your main program (GyroTest.vi).

Let me know if you need any clarification about this.

Take care!

Tanya

0 Kudos
Message 2 of 7
(3,365 Views)

Ok, Thanks for the help.

The problem I've having with removing the while loop from the GyroRead block

is that I can't figure out how to "accumulate" the gyro rate value into a

heading value.

In the while loop, i did that with a shift register, but I don't see how to

"remember" something from one block invocation to the next.

Somewhat related to that, with the while loop inside the block, it knows how

long a While iteration takes (approximately), but if the while loop is in

the "caller" of the block, then is there a good way within the GyroRead

block to find out how much time passed since the last time it was invoked?

I see a way to read a free running timer, but I don't see a way to remember

what the value was the previous time (or to initialize it on the first

invocation).

Thoughts?

Thanks much,

David

0 Kudos
Message 3 of 7
(3,365 Views)

Hi David,

I modified your code to show how to use shift registers in the main VI to remember data. See image below.

New_gyro_test_with_timing.png

I added 2 inputs and 1 output to your ReadGyro VI. One of the inputs and the output are connected to a shift register. This replaces what you had before in the subVI to remember the previous value. You can initialize the shift register value by wiring a constant to the left shift register outside the loop. I also added some timing functions to time each loop iteration. I wasn't entirely sure what you wanted to do with the timing. I added code that checks the current value of a millisecond timer to the previous value using shift registers. The difference will be in milliseconds.

Did I understand what you wanted to do?

Tanya V

Tanya Visser
National Instruments
LabVIEW Group Manager
0 Kudos
Message 4 of 7
(3,365 Views)

Hi Tanya,

Thanks for all the suggestions.  I have it working now with your suggestions.  (HiTechnic Gyro vi for NXT in LabView).

I wish there was a way to push all that remembering previous values and calculating elapsed times down inside the gyroRead sub-vi so the person that uses it doesn't need to worry about the shift registers and what not.  oh well.

I learned something, I think: If you don't wire an input to a block (e.g. the offset to the gyro block from HiTechnic) and wire it other times (i.e. at other places it is used in your program) then the value it gets the next time it is used unwired is remembered from the last wired value.

Unrelated to that, it seems there is something fishy with the display of numbers in my Controls.  When running GyroTest, which uses GyroInit and GyroRead, if I look at the front panel for GyroRead, the Control for Elapsed Time flickers between a display of the elapsed time and a display of the previous heading.  I attached screen shots of that too for the disbelievers.

Another thing I learned: Front Panels update much faster over USB than Bluetooth.

Best regards,

David

FTC Team 1001

p.s. wouldn't it be cool if Print->HTML made hyperlinks on the Case structure selector that flipped between the implementations for the various case's!

0 Kudos
Message 5 of 7
(3,365 Views)
Solution
Accepted by David_Fort

Hi David.

Although I don't have a Gyro to test this, it seemed like a fun challenge.

I created a single VI that does calibration and heading calculation.

One Bool input is set true when you want to calibrate.  It has an internal 1 second delay, and then calculates the offset.

Another Bool input can be used to reset the heading to zero.

Otherwise it just calculates the current heading.

If you call the vi repeatedly it will remeber how long since it's last call and calculate an apropriate heading change based on the rate information.

Sorry I couldn't debug it

Phil.

Get a life? This IS my life!
0 Kudos
Message 6 of 7
(3,365 Views)

Using your GEARS Get Heading.vi and the balance equation from the HTWay example in NXT-G on Hitechnic.com, attached is a LabView program that balances a 2 wheeled robot.

I have not yet spent any time on elegance, nor incorporated the remote control commands of the Hitechnic example, but it shows the use of the Get Heading block for the Gyro and it actually does balance!

(also don't have the UI to set wheel size and calibrate the gyro that was in the original program).

Thanks for all the help.

David Fort

FRC/FTC Team 1001

Attached files are for LabView version 2009.

Download All
0 Kudos
Message 7 of 7
(3,365 Views)