First fare 2013 basic-labview

32
Basic LabVIEW Kristina Landen FRC 2093 Bowtie Brigade [email protected]

Transcript of First fare 2013 basic-labview

Page 1: First fare 2013   basic-labview

Basic LabVIEWKristina Landen

FRC 2093 Bowtie [email protected]

Page 2: First fare 2013   basic-labview

Who has heard of or used LabVIEW before today?

Page 3: First fare 2013   basic-labview

Who has ever programmed in another language before?

Page 4: First fare 2013   basic-labview

Has anyone ever programmed for FRC before?

Page 5: First fare 2013   basic-labview

OverviewO What is LabVIEW?O Get familiarO Code 4 wheel tank drive by PWMO Add actuator, controlled by buttonsO Global Variable benefits and usage

Page 6: First fare 2013   basic-labview

What is LabVIEW?O Visual – no endless lines of codeO Easy to followO .vi – Virtual Instrument

Page 7: First fare 2013   basic-labview

Getting Familiar with LabVIEW

At this point, I will leave the presentation, and go into LabVIEW and explain things in there.

The following slides are what I covered.

Page 8: First fare 2013   basic-labview

Getting StartedO Open LabVIEWO On the “Getting Started” window,

select “FRC cRIO Robot Project.” This will be what you use for all of your code involving the robot.

O Name your project something memorable.

Page 9: First fare 2013   basic-labview
Page 10: First fare 2013   basic-labview

Project ExplorerO Direct links to all of the .vi’s in your

program

This is where your team number will go so the code knows what it is talking to.

Under “Team Code” is where you will find the majority of the .vi files you will need to program the robot.

Page 11: First fare 2013   basic-labview

Begin.viO This is where all of the things you

will be coding are initiated.

Page 12: First fare 2013   basic-labview

Finish.viO This is where you terminate all of the

things you setup in Begin.vi.O This is important because if not

done, things on the robot don’t shut down properly and can cause code issues later on.

Page 13: First fare 2013   basic-labview

Teleop.viO This is where you can write code to

make the robot complete tasks, but is not always the best place to do so.

Page 14: First fare 2013   basic-labview

Teleop.vi ContinuedO You can put display messages to the

Driver Station here which will display when Tele-operated mode is enabled. This message is the name of the project that I am working on.

Page 15: First fare 2013   basic-labview

Periodic Tasks.viO This is where I do the majority of my

programmingO Sensor data gathered here can be

utilized in Autonomous mode as well as in Tele-operated

O You can control how often sensors are checked for data

Page 16: First fare 2013   basic-labview

If you plan to use pneumatics, delete this Disable Structure and fill in the refnum name and set it up in Begin.vi and Finish.vi.

This is where you will be putting code for driving and sensors.

Page 17: First fare 2013   basic-labview

Where Do I Get .vi’s?O Right click – WPI Robotics Library

O WPI Robotics Library has all of the FIRST related .vi’s needed for competition. You will have to use .vi’s from the “Programming” category to complete your code.

Page 18: First fare 2013   basic-labview

WPI Robotics Library

Page 19: First fare 2013   basic-labview

ExamplesO Where to find themO How to adapt them to fit your code

Page 20: First fare 2013   basic-labview

In Each Example There Is…

O Initialization of ports and channelsO Closing of ports and channelsO The stuff that makes everything

happenO Bonus blinking lights, pretty graphs,

and other switches and dials

Page 21: First fare 2013   basic-labview

What We Have To Do…O Recognize which part is whichO Figure out which part to put in our

codeO Decide which parts to omitO Replace inputs and outputs with

Joysticks and Motor blocks

Page 22: First fare 2013   basic-labview

Global VariablesO Robot Global Data.viO Store all sensor values, joystick

values, etc.O Can be used ANYWHERE in the codeO Can save a lot of time

O Instead of writing the code for buttons on a joystick each time you want to use one, use global variables written to in Periodic Tasks.vi

Page 23: First fare 2013   basic-labview

Let’s Program!!

Page 24: First fare 2013   basic-labview

By the end you will be able to…

O Program a 4 wheel tank or arcade drive by PWM

O Program another actuator motor using buttons

O Pass the name of your program to the DriverStation

Page 25: First fare 2013   basic-labview

Programming Drive Motors: Begin

Before

After

Highlight the code for one joystick and copy it by holding control and dragging. Change the USB constant by clicking it, and selecting USB 2.

To replace one block with another, select the block, right click, replace. To replace a “Open 2 Motor” with an “Open 4 Motor”, continue and go “Robot Drive Palette, Open 4 Motor”. Add constants to the open ports below the pre-existing ones by right clicking the hub, create, constant.

Don’t forget to change the name too!

Page 26: First fare 2013   basic-labview

Programming Drive Motors: Finish

Copy the Joystick close from below and change the name.

Page 27: First fare 2013   basic-labview

Programming Drive Motors

This is the basic program setup for a 2 Motor Drive chassis. However, it is setup to run two motors with one joystick.

Page 28: First fare 2013   basic-labview

Programming Drive Motors

Expand the “Unbundle” block.

Copy the code for Joystick 1 up, rename it, then wire into the “Unbundle” block.

(This is what the big red arrow on the last slide was pointing to)

Page 29: First fare 2013   basic-labview

Programming Drive Motors Tip: To expand a

while loop, hold control, click, and drag where you want more space.

Insert an “Unbundle” block from “Programming>Cluster, Class, and Variant>Unbundle” and wire the input to the pink pipe that runs through the while loop.

Page 30: First fare 2013   basic-labview

Programming Drive Motors

“Unbundle by Name” from Programming-Cluster, Class, and Variant wired to “axis”

“WPI Robotics Library-Robot Drive- Joysticks and get the “Get” block.

Page 31: First fare 2013   basic-labview

Programming Drive Motors

Get a “Tank Drive” block from WPI Robotics Library- Robot Drive- Tank Drive. Wire the outputs from the Y axis of the two Joysticks into the Right and Left motor ports.

Wire the pink pipe from the “Unbundle” to the Tank Drive in order to transfer the information from Begin to here.

Page 32: First fare 2013   basic-labview

Thank You For Listening!!

Questions?

[email protected]