WPI Robotics Library User's Guide

1y ago
10 Views
2 Downloads
1.42 MB
74 Pages
Last View : 30d ago
Last Download : 3m ago
Upload by : Lilly Andre
Transcription

WPI RoboticsLibrary User’s GuideWorcester Polytechnic Institute Robotics Resource CenterBrad Miller, Ken Streeter, Beth Finn, Jerry Morrison, Dan Jones, RyanO’Meara, Derek White, Stephanie HoagJanuary 7, 2010

JanBrad MillerNovember 2009Rev 1.0Stephanie Hoag December 2009Rev 2.0

ContentsStuff to do . 6Using the WPI Robotics Library. 7What is the WPI Robotics Library?. 7Using the WPI Robotics Library User’s Guide . 8Choosing Between C and Java . 11Language Differences . 11WPILib Differences . 12Our version of Java . 12Sensors. 14Types of supported sensors . 14Digital I/O Subsystem . 15Digital Inputs . 15Digital Outputs . 16Accelerometer (2009 part) . 17Accelerometer (2010 part) . 18Gyro . 19Using the Gyro class . 19Setting the gyro sensitivity. 19HiTechnicCompass . 22Ultrasonic rangefinder. 23Counter Subsystem. 25Counter Objects . 25Encoders . 25Gear Tooth Sensor . 26Encoders . 27Quadrature Encoders . 28Analog Inputs . 30Analog Triggers . 32Controlling Actuators . 33Motors . 33PWM . 34Victor. 34

Jaguar . 34Servo . 35RobotDrive . 35Relays. 38Using the serial port . 40Using I2C . 41Pneumatics . 42Compressor . 42C Object Life Span. 43Solenoid . 43Getting Feedback from the Driver Station . 45Getting Data from the Digital and Analog Ports . 45Other Driver Station Features . 46Joysticks . 46Enhanced I/O through the Cypress Module . 49Configuring the Enhanced I/O . 50Enhanced I/O data . 50Sending data to the dashboard . 51Adding dashboard data to your robot program . 512010 Camera and Image Processing . 53Using the camera . 53Working with images. 53Use of image memory . 54Image types . 54Common ColorImage operations . 55Threshold detection . 55Plane extraction and replacement . 57Ellipse detection . 57Miscellaneous . 59PID Programming . 59Multitasking (C ). 60Creating tasks . 60Synchronizing tasks . 61Timers . 62Notification . 62

System Architecture . 64Contributing to the WPI Robotics Library . 65Appendix A: 2009 Camera and Vision . 66Camera . 66Camera task management. 66Camera sensor property configuration . 66Sensor property configuration using a text file . 67Simple Camera initialization . 67Configurable Camera initialization . 68Image Acquisition . 68Camera Metrics . 69Images to PC . 69Vision / Image Processing . 69Color Tracking. 70Example 1: Using Defaults . 70Example 2: Using Specified Ranges . 71Example 3: Using Return Values . 71Example 4: Two Color Tracking . 72

Stuff to doTODO: redo Joe’s pictures and get some better explanations.TODO: make the serial and I2C sections about communications.TODO: Find the comments in the Java and C forums about the documentation

Using the WPI Robotics LibraryThe WPI Robotics library (WPILib) is a set of software classes that interfaces withthe hardware in your FRC robot’s control system. There are classes to handlesensors, motors, the driver station, and a number of other utility functions such astiming and field management.What is the WPI Robotics Library?The National Instruments compact RIO-9074 real-time controller or “cRIO” for shortis currently the robot controller provided by the FIRST Robotics Competition (FRC).It provides about five hundred times more memory than previous FRC controllers.Dedicated FPGA hardware capable of sampling across 16 channels replacespreviously cumbersome programming techniques necessary with previouscontrollers.The WPI Robotics library is designed to: Work with the cRIO controller. Handle low level interfacing of components. Allow users of all experience levels access to experience appropriate features.C and Java are the two choices of text-based languages available for use on thecRIO. These languages were chosen because they represent a better level ofabstraction for robot programs than previously used languages. The WPI RoboticsLibrary is designed for maximum extensibility and software reuse with theselanguages.The library contains classes which support the sensors, speed controllers, driverstation, and other hardware in the kit of parts. In addition, WPILib supports manycommonly used sensors which are not in the kit, such as ultrasonic rangefinders.WPILib has a generalized set of features, such as general-purpose counters, toprovide support for custom hardware and devices. The FPGA hardware also allowsfor interrupt processing to be dispatched at the task level, instead of as kernelinterrupt handlers, reducing many common real-time bug problems.The WPI Robotics library does not explicitly support the C exception handlingmechanism, though it is available to teams for their programs. Uncaught exceptionswill unwind the entire call stack and cause the whole robot program to quit,therefore, we caution teams on the use of this feature. In the Java version exceptionsare used with the following conventions:

Exception typeChecked exceptionsHow they are usedUsed in cases where runtime errors should be caught bythe user program. Library methods that throw checkedexceptions must be wrapped in a try-catch block.Unchecked exceptions Used for cases like bad port numbers in initialization codethat should be caught during the most basic testing of theprogram. These don’t require try-catch blocks by the userprogram.Objects are dynamically allocated to represent each type of sensor. An internalreservation system for hardware is used to prevent reuse of the same ports fordifferent purposes (though there is a way around it if necessary).In the C version the source code for the library will be published on a server forteams to review and make comments. In the Java version the source code is includedwith each release. There will also be a repository for teams to develop and sharecommunity projects for any language including LabVIEW.Using the WPI Robotics Library User’s GuideThis document is designed to help you use WPILib to program your robot. Thegeneral architecture of the WPI Robotics Library documentation is shown below.WPI RoboticsLibraryProgrammingenvironmentC Hardware e 1: WPILib Structure FlowchartAs shown by the flowchart above, the WPI Robotics Library supports environmentsfor both the C and Java programming languages. These environments andprogramming languages are discussed and explained in the “Getting Started WithJava For FRC” and “Getting Started With C For FRC” documents. Both of thesedocuments, along with other supportive materials, can be found online athttp://first.wpi.edu in the FIRST Robotics Competition section.The WPI Robotics Library User’s Guide addresses the Hardware and Control branchof the WPILib structure. A more detailed view of what this involves is shown in theseries of charts below.The first primary section of the user’s guide is the sensors section. This sectiondiscusses how to use the sensors provided in the FRC kit of parts, as well as a few

other sensors commonly used on FRC robots. The structure of this section is shownin the chart below:SensorsVision odersImageprocessingFigure 2: WPILib Sensors section organizationAs shown in the sensors flowchart above, each sensor subsection includes basicinformation about the sensor, any necessary calibration or settings, as well as anexample of how to implement the sensors in your robot program. The camerasection also includes information about image processing and color tracking, bothcommonly used with FRC robots.The next primary section discusses actuators, such as motors and pneumatics, and isrepresented in the chart sSolenoidsRelaysFigure 3: WPILib Actuators section organizationThe actuator section describes different types of motor control and solenoid control,including the use of speed controllers, relays and solenoids.The next section, feedback, is outlined in the chart below:

FeedbackTo robotFrom robotRegular I/OJoysticksEnhanced I/ODigital andanalog inputsPWM chpadFigure 4: WPILib feedback section organizationThe second primary section of the user’s guide is the feedback section. This sectiontalks about two different aspects: user feedback and response. This coversfeedback/data that you can get from the driver station, including using buttons,lights, potentiometers and joysticks.The miscellaneous section primarily discusses more advanced programmingtechniques used for control, i.e. PID control, multitasking (in C ), and other selecttopics. The structure of the control section is shown in the chart below:MiscellaneousControl (PID)MultitaskingFigure 5: WPILib miscellaneous section organizationTiming

Choosing Between C and JavaC and Java are very similar languages; in fact Java has its roots in C . If youcan write WPILib C programs for your robot, then you can probably also writeWPILib Java programs. There are, however, reasons for choosing onprogramming language over the other.Language DifferencesThere is a detailed list of the differences between C and Java on Wikipediaavailable here: http://en.wikipedia.org/wiki/Comparison of Java and C . Below isa summary of the differences that will most likely effect robot programs createdwith WPILib.C JavaMemory allocated and freedmanually.Objects must be allocated manually,but are freed automatically when noreferences remain.References to objects instead ofpointers. All objects must be allocatedwith the new operator and arereferenced using the dot (.) operator.(e.g. gyro.getAngle() )Header files are not necessary andreferences are automatically resolvedas the program is built.Only single inheritance is supported,but interfaces are added to Java to getthe most benefits that multipleinheritance provides.Checks for array subscripts out ofbounds, uninitialized references toobjects and other runtime errors thatmight occur in program development.Compiles to byte code for a virtualmachine, and must be interpreted.Pointers, references, and localinstances of objects.Header files and preprocessor used forincluding declarations in necessaryparts of the program.Implements multiple inheritancewhere a class can be derived fromseveral other classes, combining thebehavior of all the base classes.Does not natively check for manycommon runtime errors.Highest performance on the platform,because it compiles directly tomachine code for the PowerPCprocessor in the cRIO.Table 1: Java/C Difference Summary

WPILib DifferencesIn order to streamline transitions between C and Java, all WPILib classes andmethods have the same names in both languages. There are some minordifferences between the language conventions and utility functions. Thesedifferences are detailed in the table below:ItemMethod namingconventionUtility functionsC Upper case first letter andcamel case after.e.g. GetDistance()Call function.e.g. Wait(1.0) will wait forone second.JavaLower case first letter andcamel case thereafter.e.g. getDistance()Library functions areimplemented as methods.e.g. Timer.delay(1.0) willwait for one second.Table 2: Java/C Differences within WPILibOur version of JavaThe Java virtual machine and implementation used with WPILib is the Squawkplatform based on the Java ME (micro edition) platform. Java ME is a simplifiedversion of Java designed for the limitations of embedded devices. As a result,there are no user interface classes or other classes that are not meaningful in thisenvironment. The most common Java platform is the Java Standard Edition (SE).Some of the SE features that are not included in our version of Java are describedin the list below. Dynamic class loading is not supported for class loading or unloading. Reflection, a way of manipulating classes while the program is running, isalso not supported. The Java compiler generates a series of byte codes for the virtual machine.When you create a program for the cRIO with Java ME, a step isautomatically run after the program compiles (called pre-verification).This pre-verification pass simplifies the program loading process andreduces the size of the Java virtual machine (JVM). Finalization is not implemented, meaning the system will notautomatically call the finalize() method of an unreferenced object. If youneed to be sure code runs when a class is no longer referenced, you mustexplicitly call a method that cleans up. Java Native Interface (JNI) is not supported. This is a method of calling Cprograms from Java using a standard technique. Serialization and Remote Method Invocation (RMI) are not supported.

The user interface APIs (Swing and AWT) are not implemented. Threads are supported, but thread groups are not. Java ME is based on an earlier version of Java SE (1.3), so it doesn’t includenewer Java features, such as generics, annotations and autoboxing.

SensorsThe WPI Robotics Library supports the sensors that are supplied in the FRC kit ofparts, as well as many other commonly used sensors available to FIRST teamsthrough industrial and hobby robotics outlets.The WPILib supported sensors are listed in the chart below. The supported sensorsinclude those that are provided in the FIRST kit of parts, as well as other commonlyused sensors.SensorsVision odersImageprocessingFigure 6: WPILib sensor sectionTypes of supported sensorsOn the cRIO, the FPGA implements all the high-speed measurements throughdedicated hardware ensuring accurate measurements no matter how many sensorsand motors are added to the robot. This is an improvement over previous systems,which required complex real-time software routines.The library natively supports sensors of the categories shown below.CategoryWheel/motorpositionmeasurementRobot orientationGeneric pulse outputSupported SensorsGear-tooth sensors, encoders, analog encoders, andpotentiometersCompass, gyro, accelerometer, ultrasonic rangefinderCountersTable 3: List of Supported SensorsThere are many features in the WPI Robotics Library that make it easy to implementsensors that don’t have prewritten classes. For example, general-purpose counterscan measure period and count from any device generating output pulses. Anotherexample is a generalized interrupt facility to catch high-speed events withoutpolling and potentially missing them.

Digital I/O SubsystemBelow is a visual representation of the digital sidecar, and the digital I/Osubsystem.Figure 7: Digital I/O Subsystem DiagramThe NI 9401 digital I/O module provided in the kit has 32 GPIO lines. Through thecircuits in the digital breakout board, these lines map into 10 PWM outputs, 8 Relayoutputs for driving Spike relays, the signal light output, an I2C port, and 14bidirectional GPIO lines.The basic update rate of the PWM lines is a multiple of approximately 5 ms. Jaguarspeed controllers update at slightly over 5ms, Victors update at slightly over 10ms,and servos update at slightly over 20ms. Higher update rates may be possible usingthe CAN bus and a community developed software available fromhttp://firstforge.wpi.edu.Digital InputsDigital inputs are generally used for controlling switches. The WPILib DigitalInputobject is typically used to get the current state of the corresponding hardware line: 0or 1. More complex uses of digital inputs, such as encoders or counters, are handledby using the appropriate classes. Using these other supported device types(encoder, ultrasonic rangefinder, gear tooth sensor, etc.) doesn’t require a digitalinput object to be created.The digital input lines are shared from the 14 GPIO lines on each Digital BreakoutBoard. Creating an instance of a DigitalInput object will automatically set thedirection of the line to input.Digital input lines have pull-up resistors so an unconnected input will naturally behigh. If a switch is connected to the digital input it should connect to ground whenclosed. The open state of the switch will be 1 and the closed state will be 0.In Java, digital input values are true and false. So an open switch is true and a closedswitch is false.

Digital OutputsDigital outputs are typically used to run indicators or to interface with otherelectronics. The digital outputs share the 14 GPIO lines on each Digital BreakoutBoard. Creating an instance of a DigitalOutput object will automatically set thedirection of the GPIO line to output. In C , digital output values are 0 and 1representing high (5V) and low (0V) signals. In Java, the digital output values aretrue (5V) and false (0V).

Accelerometer (2009 part)The two-axis accelerometer provided in the kit of parts (shown in the picturebelow) is a two-axis accelerometer. This device can provide acceleration data in theX and Y axes relative to the circuit board. In the WPI Robotics Library you treat it astwo separate devices, one for the X axis and the other for the Y axis. This providesbetter performance if your application only needs to use one axis. Theaccelerometer can be used as a tilt sensor – actually measuring the acceleration ofgravity. In this case, turning the device on the side would indicate 1000 milliGs orone G.Figure 8: FRC supplied 2 -axis accelerometer board connected to a robot

Accelerometer (2010 part)The 2010 accelerometer is not currently available as a built-in class, but we expect itwill be available shortly after the kickoff. It will operate using the I2C interface tothe robot controller. Teams are free to interface it themselves using the I2C classalready built into WPILib.

GyroGyros typically in the FIRST kit of parts are provided by Analog Devices, and areactually angular rate sensors. The output voltage is proportional to the rate ofrotation of the axis normal to the top package surface of the gyro chip. The value isexpressed in mV/ /second (degrees/second or rotation expressed as a voltage). Byintegrating (summing) the rate output over time, the system can derive the relativeheading of the robot.Another important specification for the gyro is its full-scale range. Gyros with highfull-scale ranges can measure fast rotation without “pinning” the output. The scale ismuch larger so faster rotation rates can be read, but there is less resolution due to amuch larger range of values spread over the same number of bits of digital to analoginput. In selecting a gyro, you would ideally pick the one that had a full-scale rangethat matched the fastest rate of rotation your robot would experience. This wouldyield the highest accuracy possible, provided the robot never exceeded that range.Using the Gyro classThe Gyro object should be created in the constructor of the RobotBase derivedobject. When the Gyro object is used, it will go through a calibration period tomeasure the offset of the rate output while the robot is at rest. This requires that therobot be stationary and the gyro is unusable until the calibration is complete.Once initialized, the GetAngle()(or getAngle() in Java) method of the Gyroobject will return the number of degrees of rotation (heading) as a positive ornegative number relative to the robot’s position during the calibration period. Thezero heading can be reset at any time by calling the Reset() (reset() in Java)method on the Gyro object.Setting the gyro sensitivityThe Gyro class defaults to the settings required for the 80 /sec gyro that wasdelivered by FIRST in the 2008 kit of parts.To change gyro types call the SetSensitivity(float sensitivity) method(or setSensitivity(double sensitivity) in Java) and pass it the sensitivity involts/ /sec. Take note that the units are typically specified in mV (volts / 1000) inthe spec sheets. For example, a sensitivity of 12.5 mV/ /sec would require aSetSensitivity() (setSensitivity() in Java) parameter value of 0.0125.The following example programs cause the robot to drive in a straight line using thegyro sensor in combination with the RobotDrive class. The RobotDrive.Drivemethod takes the speed and the turn rate as ar

Using the WPI Robotics Library The WPI Robotics library (WPILib) is a set of software classes that interfaces with the hardware in your FRC robots control system. There are classes to handle sensors, motors, the driver station, and a number of other utility functions such as timing and field management. What is the WPI Robotics Library?

Related Documents:

The Future of Robotics 269 22.1 Space Robotics 273 22.2 Surgical Robotics 274 22.3 Self-Reconfigurable Robotics 276 22.4 Humanoid Robotics 277 22.5 Social Robotics and Human-Robot Interaction 278 22.6 Service, Assistive and Rehabilitation Robotics 280 22.7 Educational Robotics 283

Iron Angel Force back the invading enemy using a customizable mech-suit. by Brainstorm Productions: Eric Benson erbenson@wpi.edu Keenan Gray krgray@wpi.edu Connor Porell cgporell@wpi.edu . 2!! Game Summary Iron Angel is an exciting action-based shooter. The player is put in control of a powerful mech-

7 Terminology WPI: Worcester Polytechnic Institute, a four-year private university in Worcester, Massachusetts, USA MQP: Major Qualifying Project, a project done at WPI, usually completed in a student's senior year. It is in the student's major field, and must be completed prior to graduating. [WPI, 2014] CS: Computer Science HTML: Hypertext Markup Language, a markup language that is used .

The VEX Robotics Game Design Committee, comprised of members from the Robotics Education & Competition Foundation, Robomatter, DWAB Technolog y , and VEX Robotics. VEX Robotics Competition Turning Point: A Primer VEX Robotics Competition Turning Point is played on a 12 ft x 12 ft foam-mat, surrounded by a sheet-metal and polycarbonate perimeter.

The VEX Robotics Game Design Committee, comprised of members from the Robotics Education & Competition Foundation, Robomatter, DWAB Technologi es, and VEX Robotics. VEX Robotics Competition In the Zone: A Primer VEX Robotics Competition In the Zone is played on a 12 ft x 12 ft foam-mat, surrounded by a sheet-metal and lexan perimeter.

WPI Laser Cutter User Guide The laser cutter is capable of cutting and engraving two-dimensional drawings in various materials including wood and plastic. The laser cutter owned by the WPI Department of Mechanical Engineering is a Versalaser VLS-4.60 by Universal Laser Systems. It has a 60-watt laser and a 24" x 18" cutting platform.

(AS OF CLASS OF 2022) WPI was founded on the principle that students learn most effectively by applying theory to practice. WPI has 50 years of experience integrating projects into our undergraduate curriculum. . Phy

reading is to read each day for at minimum 30 minutes. Please turn in all assignments to your child’s teacher in the fall. May you have a blessed, restful, relaxing, enjoyable and fun-filled summer! Sincerely, Thomas Schroeder & Vicki Flournoy Second Grade Summer Learning Packet. DEAR FAMILY, As many of you are planning for your summer activities for your children, we want you to remember .