LabVIEW FPGA and Control - ECpE Senior Design

advertisement
Learning Module : LabVIEW FPGA and Control
Software:
Introduction:
LabVIEW FPGA
The goal of this module is to help you understand how to program the cRIO’s onboard FPGA and access FPGA registers from another section of code. This will
make using the provided FPGA project easier to use and understand.
LabVIEW Real-Time
Tutorials:
LabVIEW 8.6
C .out Library
Things to Remember:
FPGA Registers
Your C function prototype
Network variables
Control loop
http://www.ni.com/pdf/labview/us/fpga_compactrio_getting_started.pdf
FPGA:
Please read through the tutorial provided above. It provides some good
background information that is helpful
to understand while going through this
document.
Open the control project, and expand
the project explorer to open the vi
under the FPGA target. The control.vi
file is the FPGA code that will run on
your cRIO.
You should make sure this is compiled
by opening the vi and running it. If it
runs right away, it has already been
compiled. Otherwise it will take
roughly 10 minutes to compile and
then run.
The FPGA registers match the documentation for your power distribution board.
You will need to be sure that you program
the correct FPGA registers when you right
your control code.
If you want to test the individual components of your robot it is useful to run the
FPGA front panel. Here you have direct
access to the FPGA and check to see if
you are getting correct readings and that
components are behaving correctly.
Tip: Any vi placed under the FPGA Target
in the project explorer will be compiled to
run on the FPGA
Created Dec 2009 for CprE 286X by the Dec09-11 Senior Design Team at Iowa
State University.
Learning Module : LabVIEW FPGA and Control
Software:
LabVIEW 8.6
LabVIEW FPGA
LabVIEW Real-Time
C .out Library
Things to Remember:
FPGA Registers
Your C function prototype
Network variables
Control loop
Robot Control:
Now open the robot algorithm.vi. This
vi will open a reference to the FPGA
code you just looked at. This will give
you access to the FPGA register, allowing you to read your sensor data and
send PWM controls to your servos and
motors.
The reference to the FPGA registers
becomes available when you run the
algorithm vi.
Pass this reference
into read/write control and you have
easy access to the
registers on the FPGA
Below you can see how the vi reads all the sensor data off the FPGA. The vi also
has some variable data that it receives from the camera. Some of this information is packaged together with
the sensor data into an array.
This is one of the arrays that
gets passed into your control
function.
Similarly, output from your
control code will be written the
FPGA registers to control all of
the different PWM values.
If you would like to add more control or data
to your system you may need to modify the
FPGA vi and you will also need to add them
to the sensor and control arrays in this vi.
Tip: If you don’t want to bundle everything
into arrays, you may modify you C control
code prototype and match those inputs and
outputs with your control call seen on the
next page.
Created Dec 2009 for CprE 286X by the Dec09-11 Senior Design Team at Iowa
State University.
Learning Module : LabVIEW FPGA and Control
Software:
LabVIEW 8.6
LabVIEW FPGA
LabVIEW Real-Time
C .out Library
Things to Remember:
FPGA Registers
Robot Control:
The C algorithm that you write will get called from this vi. This gets
done by making a C library call. For this to work correctly you
should make sure that you have compiled your library with no errors or warnings, and that you have downloaded it to the correct
directory on the cRIO.
Once this is done you should double click the C Library Call node and verify that
everything is correct. First check that the parameter match your C prototype.
Keep in mind that to get multiple outputs you need to have pointer parameters.
This will allow you to modify the values and the vi will see your changes.
Your C function prototype
Network variables
Control loop
Also, make sure that the library path points to your library on the cRIO and that
you call the correct function name. The screenshot below matches the library that
was created in the C Development learning module.
Tip: If you make changes to your C library, the cRIO will only reload it if you
modify the vi. So, after you upload your new library, make a change to the vi.
Created Dec 2009 for CprE 286X by the Dec09-11 Senior Design Team at Iowa
State University.
Learning Module : LabVIEW FPGA and Control
Software:
LabVIEW 8.6
LabVIEW FPGA
LabVIEW Real-Time
C .out Library
Things to Remember:
FPGA Registers
Your C function prototype
Network variables
Control loop
Variables:
The final part of this LabVIEW project
is the get field info.vi. The purpose of
this vi is to retrieve field and camera
information. If there are modifications to the competition these variables may need to be modified, or
more may be added.
Open the block diagram to see what
is going on. You can see that it is
fairly simple, and that it just reads
data from the competition server and
passes it along to the cRIO.
If you need to change the properties
of a variable you can right click and
select ‘Properties.’ You can change
whether the variable runs locally or is
published on the network.
In the event that more variables are
added to the competition you should
consult NI’s developer zone website.
Tip: It helps to have a good understanding of how your system is working. Three
different vis were explained in this document. Each runs on a different part of
your system. The control vi runs on the cRIO’s FPGA, the robot algorithm vi runs
on the cRIO’s microprocessor using VxWorks, and the get field info vi will run on
the host computer.
Created Dec 2009 for CprE 286X by the Dec09-11 Senior Design Team at Iowa
State University.
Download