Presentation is loading. Please wait.

Presentation is loading. Please wait.

VAFIRST LabVIEW Workshop 11/19/11 Presenters: Marin Kobin & Patrick Foley.

Similar presentations


Presentation on theme: "VAFIRST LabVIEW Workshop 11/19/11 Presenters: Marin Kobin & Patrick Foley."— Presentation transcript:

1 VAFIRST LabVIEW Workshop 11/19/11 Presenters: Marin Kobin & Patrick Foley

2 Objectives What is LabVIEW? Give an overview of the LabVIEW environment Create a sample drive code for a 2 Drive Motor Robot Create a sample Autonomous program.

3 Assumptions Have a basic understanding of

4 The LabVIEW Language LabVIEW program consists of one or more Virtual Instruments (VIs) A VI is like a function or a procedure or a subroutine – except that it has a richer interface

5 Each VI has 2 Windows Front Panel User Interface (UI) – Controls = Inputs – Indicators = Outputs Block Diagram Graphical Code – Data travels on wires from controls through functions to indicators – Blocks execute by Dataflow LabVIEW Programs Are Called Virtual Instruments (VIs) 5

6 Functions (and Structures) Palette 6 (Place items on the Block Diagram Window) Structure: While Loop

7 LabVIEW Nodes While loop For loop Boolean logic PID Control Arrays Signal processing Mathematics Timing

8 LabVIEW Types Floating point Integer Boolean String Array – note wire thickness Cluster

9 LabVIEW Tasks Multiple tasks in parallel Data flow still applies Loops 1, 2, and 3 will run Loop 4 runs after 3 stops

10 Creating a new FRC cRIO Project Select New: FRC cRIO Robot Project Create a Project name: – VARFIRST Workshop 11.19.11 cRio IP address: Replace xx.yy with your team number – 10.24.02.02 Choose Robot Framework with Game Code. Press Finish when done.

11 Project Explorer Expand the “Team Code” Folder. This is where you will find the 3 sub.vi’s that you will have to use to create a proper working robot. – Begin.vi – Autonomous Independent. Vi – Teleop.vi

12 3 Sub.vi’s that are used to create a working robot code Begin.vi – Open all your devices here, and create refnum names to uniquely identify each of them. This is called only once at the very start. – The Framework is setup here in Begin.vi to automatically call the Autonomous Independent.vi at the start of Autonomous Mode and to automatically kill it when Autonomous Mode ends. Autonomous Independent.vi – Do NOT add an explict call to this vi in your code. It is set to be automatically called and adding your own calls will disrupt that background process and can cause your robot to be inoperable during teleop. – This is called only once, so put everything you want done during Autonomous Mode here. You don't leave this, so waits and delays can be used as desired here. Teleop.vi – Typical driver controls. This is called 50 times each second as the Driver Station control packets arrive. Do NOT write code in here that waits or takes more than a few milliseconds to execute. If this vi takes too long to execute, then your driver controls will respond sluggishly, sporadically, or not at all. That means no While loops, no wait timers, no Watchdog Feed & Delay. – Normal driver operating code will usually be split between Teleop.vi and Periodic Tasks.vi – Teleop.vi gets the flow-through actions, such as driving via the joysticks, that don't require delays to give a mechanical mechanism time to complete operation. – Periodic Tasks.vi gets the complex time-consuming actions that need much time to complete, like a catapult that needs to be released and cocked again as part of a single joystick button press. Compared to computer speed it takes a very long time to physically pull back a mechanism, latch it, and release it again. Anything that makes you want to add a time delay or have to wait for a sensor to tell you it's ready can more easily be done in Periodic Tasks.vi than anywhere else.

13 Begin.vi – Default Code Access the back panel Erase everything except the “Camera Code” and “Error out” to start from scratch. Leave the “Camera Code” so you still can have the camera send back a video stream to the Driver Station.

14 Begin.vi - Joystick Activation Place “WPI_Joystick Open” Add constant to JoystickDevice (USB 1) Place “WPI_JoystickRefNumRegistrySet.vi” – Connect with a wire “JoystickDevRef between the two.vi’s Refnum name – Create a constant and give this joystick an identity. – Call it “joystick1 *When naming.vi’s it is best not to use capitals letters and spaces. You will have to refer back to the names later. **You will need to activate 2 separate Joysticks. – Label each joystick – joystick1 and joystick2 WPI Functions Pallet

15 Completed Begin.vi

16 Tank Drive 2 Motors – Begin.vi Place Drive Open 2 Motor – Choose your speed controllers (Jaguar, CAN Jaguar or Victors). Don’t mix speed controllers in your drive train. – Create a constant for the left and right motor. Select PWM Channel for the left and right motor Place RobotDriveRefNumRegistrySet.vi – Connect the RobotDriveDevRef between the two.vi’s with a wire Refnum name – Create a constant and give this drivetrain an identity. – Call it leftandrightmotors

17 Tank Drive 2 Motors – Begin.vi Invert motors – Create a constant on the DriveOpen2Motor.vi – Choose True to invert that motor. – False will not invert a motor

18 Tank Drive – Teleop.vi Erase everything in the box. This is not what we are going to use. We have already created different drive motors and joystick.vi’s This is where we will create all of your robot actions. We will first look at creating 2 Motor tank drive Erase

19 2 Motor Drive – Teleop.vi Place the following.vi’s – RobotDriveRefNumRegis teryGet.vi – RobotDriveTankDrive.vi Using a wire connect the RobotDriveDevRef Create a constant to recall the Refnum name – leftandrightmotors

20 2 Motor Drive – Teleop.vi Place the following.vi’s – JoystickRefNumRegistryGet.vi (2 needed) – Left and Right Joysticks) – JoystickGet.vi (2 needed) Using a wire connect the JoystickDevRef Create a constant to recall the Refnum name – joystick1 – Left joystick = Left Motor – Joystick2 – Right joystick = Right motor

21 2 Motor Drive – Teleop.vi JoystickGet.vi – Create a Unbundled by Name (Located in Class, Cluster, & Variant Palette) – Do this for each Joystick. Connect one Unbundled by Name to each axis on the JoystickGet.vi. Each Unbundled by Name should be set to the y-axis Joystick1 Unbundled by Name connect to Left Axis on TankDrive.vi Joystick2 Unbundled by Name connect to Right Axis on TankDrive.vi.

22 Completed Teleop.vi

23 What about the Finish.vi? You do not need to place any thing into the Finish.vi. By doing so this will stop your program. We do not have to worry about stopping our robot because the Field Management System does this for us. The FMS disables all communications with the robot and by default the robot will not complete any tasks if there is no communication with the driver station.

24 What is an Autonomous Independet.vi Autonomous Independent.vi can be multiple parallel tasks. For example, the following two samples can co-exist quite comfortably in the same vi. Two independent sequences operating at the same time, one driving the robot while the other blinks a solenoid status light. This case is quite simple, however, it illustrates that much more complicated parallel independent tasking such as this is possible. Maybe a robot juggling while navigating a maze.

25 Types of Autonomous Programs Flat Sequence Probably the simplest method of programming a fixed sequence of autonomous moves. Everything within a frame must complete before the next frame will start. It has the look of movie film. This assumes the User Watchdog is not used or is handled elsewhere (2010): Loop If there's an action or set of actions you just want to keep repeating as long as Autonomous Mode lasts you might do something like this. This example just works a solenoid, opening and closing it over and over. If no solenoid is actually attached then you'll still get a blinking light on the solenoid module. This assumes the User Watchdog is not used or is handled elsewhere (2010):

26 Autonomous.vi - Starting from Scratch You can erase everything here. Start from scratch is the best way to achieve what you want. Also we changed a lot of the Refnums and they are no longer linked to anything in this.vi Best way to create an Autonomous program is to create a timeline.

27 Creating a Flat Sequence Create a Flat Sequence Structure located under Programs-Structures Right click on the edge of the Flat Sequence Structure to add or delete a frame. *Looks kind of like a film strip

28 Flat Sequence – Reference Motors Add RobotDriveNumRegisteryGet.vi outside the flat sequence. Refnum your leftandrightmotors. With one click create a wire from RobotDrivedefRev across all 3 frames. – This will allow us to use these motors at anytime during the autonomous period

29 Flat Sequence – Activate Drive Motors Place a DriveTankDrive.vi in each frame Connect RobotDriveDevRef from DriveTankDrive.vi to the pink wire going across each frame.

30 Flat Sequence – Motor Values Create a constant for each left and right axis. Give a numerical value for each axis – Values can be between -1 to +1 – +1 full power forward, -1 full power reverse – *Do not worry about having to invert the motor. This was done already in the Begin.vi

31 Flat Sequence – Structure Timing Add a timer to tell each frame how long to run. – Use Wait(ms).vi located under Programing – Timing. Create a constant for each Wait(ms).vi Add a numerical value to tell each frame how long to run. – (ms) stands for milliseconds. When you enter the time make sure you convert it into milliseconds. Example : 1000 milliseconds = 1 second 500 milliseconds =.5 seconds

32 Flat Structure – Non-Drive Motor Actions You can add other motors and actuators in your autonomous code. Stretch each Flat Structure frame so you have room to add other.vi’s. Make sure you place them into the appropriate frame. Check your timing sequence of when you want to start that particular action.

33 Building Your Code In the Project Explorer expand “Build Specifications” You should now see “FRC Robot Boot-up Deployment” Right Click on “FRC Robot Boot-up Deployment” and select “Build” This will compile your code and prepare it for deployment to the cRIO

34 Preparing for Deployment to the cRIO Connect an Ethernet cable from your computer to Port 1 on the cRIO. Power up the cRIO and wait for a few seconds for them to connect. Use the “FRC cRIO Imaging Tool” that was installed with LabVIEW. Format the cRIO with “FRC_2011_v28” image. Select LabVIEW and check Always run deployed code at startup. Enter your Team ID Press “Apply” and to complete the format.

35 Deploying code to the cRIO In the Project Explorer Window right click on “FRC Robot Boot-up Deployment” and select “Run as startup” This will begin the download of your code to the cRIO. This process may take a couple of minutes to complete. Setup your driver station with 2 Joysticks and have fun.

36 Compressor Example

37 Single Solenoid Example

38 Double Solenoid Examples 2 Examples

39 Additional Resources http://team358.org/files/programming/Contr olSystem2009-/LabVIEW/ - Team 358 has put together in a single area a great collection of resources for LabVIEW. They have also put together resources for many other areas of robotics. http://team358.org/files/programming/Contr olSystem2009-/LabVIEW/ https://decibel.ni.com/content/docs/DOC- 8923 – NI’s LabVIEW training page. Contains how to videos. https://decibel.ni.com/content/docs/DOC- 8923


Download ppt "VAFIRST LabVIEW Workshop 11/19/11 Presenters: Marin Kobin & Patrick Foley."

Similar presentations


Ads by Google