FRC Robot Framework 11-6-12

Download Report

Transcript FRC Robot Framework 11-6-12

FRC Robot Framework

Labview Made Easy (er)

For FIRST Robotics

FRC Framework

 Base Code with Architecture  Pre-configured  Defines Interaction between code sections  Designated places to add functionality  Focus on robot functionality rather than program structure

Let's walk through this together

FRC Project

 Select FRC cRIO Robot Project  Dialogue box opens

Create Project

 Give Project a name  Choose where to save project  Give cRIO IP address – your team number goes in xx.yy

e.g 10.20.67.2

 Click “Finish”

Project Explorer

 Project Explorer appears  All code listed under “RT CompactRIO target 10.xx.yy.2”  Displays pre-written set of VI's to allow for an out of box solution  Top level VI is “Robot Main.vi”  Double click to open it

  

Robot Main.vi – Front Panel

Front Panel has controls and indicators Not much on this one   Click on “Window” Then Select “Show Block Diagram” Driver’s Station is main operator interface

Robot Main Block Diagram

 Select and modify sub-VI's from here  Or click on sub VI from Project Explorer Recommended not to make changes to “Robot Main.vi”

11/07/12

Robot Main Block Diagram

• We will focus on the main block VIs: • Begin • TeleOp • Autonomous X For now, never mind these 8

OPEN – SET/GET - CLOSE

Programming of devices in general follows the following protocol: 

Open

a Device , • Tell the code where it is plugged in • Give it a name

Get

info from a device, or

Set

a value to a device

Close

the Device Open a Joystick Open a motor 11/07/12 Get the Y Joystick Value Set the motor speed Close the Joystick Close the motor 9

Begin.vi

 Initializes the camera, motors, joysticks  “Opens” devices   Tells program where device is plugged into cRio Gives the device a “Refnum” name which can be recalled from other areas of the program (such as tele-op)  Initialize additional components desired to be added to the system here

Begin.vi

 Camera configuration – unlikely to need to change this, if use it at all - Discuss in later session.  Motor configuration set up for 2 motors drive.

 Tell which PWM port plugged into, give it a name  Why is one motor inverted?

 Set up for 1 joystick  Tell where plugged into DS  “refnum” i.e.name of devices  Device info stored by that name to be recalled when

Begin .vi Modify to Add Extra Motor

• •

Edit vi: Add an accessory motor:

Open function palette and select: WPI Robotics Library / Actuators / Motor Control • • Add Open Motor .vi • Identify where plugged in • What type of controller Add Refnum Set.vi

• Give it a name

Robot Main – Calling TeleOp or Autonomous.vi

 This section uses a “State Machine”  Case structure  Inside a while loop   “Robot Mode” controlled by Driver Station or by Field Management System (In Competitions) “Robot Mode” selects Case  Continues to loop until robot Disabled

Tele-op.VI

 Out of Box Code will drive 2 motor drive with Joystick axes 1 & 2  Gets Joystick Axis data  Cluster of data – uses the “Unbundle by Name” function block  Reads Refnums from Begin.vi

 Sets Drive Motor Speed  Arcade drive • X axis turns, Y axis fwd / reverse Use Context Help (CTRL H) to investigate blocks These are available but not required

 Modify Tele-op.VI for added Motor First: Modify Joystick axes for a  From WPI Robotics Library/ PS3 controller Actuators/ MotorControl    Right click on Axes elements Change Axes 1 & 2 to Axes 3 & 4 • Right thumb control on PS3 style controller Next access Joystick Buttons by connecting to a “Unbundle by name” function from the “cluster,“ palette  Bring the Refnum Get and provide name  Bring Motor Set Output vi and connect them  Now from the “Comparison” palette bring a “Select” Block   Button output is true or false Select function assigns a value if true and another if false  Create constant of 1 if true and 0 if false  Wire output to the Set Output block - Results in motor going full speed if trigger is pressed.

Next we will see if our code works!

Interfacing with the Robot

Driver Station Operation Tab

Battery Voltage Display Team Number (Make sure it is correct) Mode Selection

Teleoperated = Driver

• •

Autonomous = Computer Control Practice = Run like a match Elapsed time since start of robot communication PC Battery Communication Status

• •

Communication = a connection to the cRIO Robot Code = the user code is running Communication Status Enable/Disable Buttons Station Number for Competition Use User Messages (This area can be controlled by the robot program)

Driver Station Setup Tab

ID Team number to connect to robot Team Number Configuration: Make sure this is set correctly Choose NIC: Allows you select which network adapter is connected to the robot

Warning this will change your Computer TCP/IP properties to a static IP address vs.DHCP

Joystick Setup: Drag Joystick up and down to switch which connected joystick is 1, 2, 3 or 4 in the program Exit: Logs off the Driver Station Account on the classmate

IP Address • • • IP (Internet Protocal ) address is how devices address each other on the internet (public) or closed wi-fi network.

• Normally the IP address is temporary and created automatically (DHCP) But for a closed – local network we use a static IP address • Using 10.XX.YY.A where XX. YY is team number and A is a device number (2 for cRio), e. g.

10.20.67.2

IP Address To Change IP Address On Computer go to : Control Panel> Network and Internet > view network status > change adapter settings > Right Click on Wireless connection, select properties: When driver station opens it will set your computer IP address to this static value, To connect to internet this must be reset to the “Obtain address automatically” Be sure to say ok and get all the way out.

Homework Challenge Slides • Add a gyro device: 1.

2.

Begin – Open Tele-op – Read gyro and display reading on front panel

Begin .vi Updated for adding Gyro

• •

Edit vi: Add an accessory motor:

Open function palette and select: WPI Robotics Library / Sensors / Gyro • • Add Open Gyro .vi • Identify where plugged in Add Refnum Set.vi

• Give it a name

Modify

Tele-op.VI

for Reading Gyro  From WPI Robotics Library/ Sensors/ Gyro palette  Bring the Refnum Get and provide name it was given in the Begin.vi

 Bring Gyro Get Output vi and connect them  Put cursor on “angle” output, right click select create indicator Indicator shows up on Front Panel Digital indicator is default but can be replaced with a Dial or Linear Indicator

Modify Front Panel Indicator for Gyro reading  Put Cursor on indicator, right click and select “Replace”, then “Gauge”  Enlarge gauge by dragging diagonally  Click on the 10 and change to 360  Hover on the 360 until you see the rotation arrows – then drag the 360 around to the zero.

# 2 Modify Tele-op.VI for option for Tank Drive, selectable from DS Updated for PS3 Joystick control pad and selectable steering modes 1) 2) 3) 4) Add a “case structure” around the “arcade drive” Add a second case “Tank Drive” with a tank drive function block Use Driver station “Digital In 1” as case selector Update Joystick for PS3 controller

Extra slides for reference

Begin .vi updated for 4 motors

Use this if you put 2 CIMs in each of two gearboxes.

Edit vi: Set up for 4 motor drive:

Put cursor on open 2 wheel drive block > right click > replace > drive palette > 4 motor drive Update input parameters Why are 2 motors inverted?