Coding for the FIRST Tech ChallengeNXT/G, LabVIEW & RobotC compared, and a Crash Course in RobotC Presented by Team Unlimited, FTC #1 http://unlimited.syraweb.org/
Presentation Overview • Coding Environment Comparisons • Why RobotC? • NXT Overview • Sensor overview • Motor & Servo Overview • Coding Basics • RobotC Overview & Basics • Sample code • Code in RobotC
NXT-G Overview • Graphics based coding environment • Similar to RoboLab (from RCX) • Layer over LabVIEW • Learning Curve : Easiest
NXT-G : Advantages and Disadvantages + Easy to learn + Simple user environment + FLL teams will have experience + Can use LabVIEW as a “My Block” creator - Less power than the other languages - Programs can take up a lot of room for long programs - Power hungry on low power machines - Lack of complicated math functions
LabVIEW Overview • Graphics based coding environment • Professional coding environment • Has many advanced features that were removed from NXT-G (i.e. Trigonometric functions) • Learning Curve : Moderate
LabVIEW : Advantages and Disadvantages + Professional programming language + Code will flow automatically from left to right + Can export “My Blocks” to NXT-G + Has advanced math functions - Can lag the processing power of the NTX - Lots and lots of opinions - Small text that can’t be magnified
RobotC : Advantages and Disadvantages + Extreme control of the code + Text is similar to the EasyC code (text) + Included joystick controller + Real time data updates (Sensors, motors, etc.) + Tons of online resources + Real Time Debugger - Steep learning curve - Can be frustrating to code - A lot of “trial and error” at the beginning
Robot C Overview • Text based coding environment • A “C” based coding environment created by Carnegie Mellon University • FTC and Vex legal • Inexpensive for extra license ($50) • “Complete control” over the code • Learning curve : Hardest
Why RobotC? • Speed • RobotC runs quicker on the NXT • Differences in speed are small until larger code is written • Control • In RobotC you have control over almost everything • Real Time Debugger to allow viewing of code line by line while running • Personal Preference • Text base control • Advanced math functions • Team Decision
Sensor ports - four input ports for attaching sensors - Ports 1, 2, 3 and 4. Loudspeaker - program with real sound output Attachment points – for LEGO Technic pins, connect to chassis. NXT Controller Specifications 32-bit ARM7 microcontroller 256 Kbytes FLASH, 64 Kbytes RAM 8-bit AVR microcontroller 4 Kbytes FLASH, 512 Byte RAM Bluetooth wireless communication (Class II V2.0) USB full speed port (12 Mbit/s) 4 input ports, 6-wire cable digital platform 3 output ports, 6-wire cable digital platform 100 x 64 pixel LCD graphical display Loudspeaker - 8 kHz sound quality. Power source: 6 AA batteries
Motor ports - 3 output ports for attaching motors - Ports A, B & C USB port - USB cable to the USB port, download programs from computer to NXT. Also can use the wireless Bluetooth connection. NXT Controller Continued
Recommend Sensors • Touch sensor • Light sensor • Ultrasonic sensor • Compass sensor • Rotation sensors
Touch Sensor • Senses COLLISIONS • Useful for sensing a wall or robot • Simple binary switch “on” or “off
Light Sensor • Senses LIGHT (not color) • Useful for line following • Two types • Reflected – Shines a light • Ambient – Uses available light • With a filter, can detect a color
Ultrasonic Sensor • Senses PROXIMITY • Useful for sensing distance • Detects whole inch distances • At extreme proximity, distances can be wrong • I.e. below 2”, often can still get 2” as a response • Useful if you don’t want to touch the object with the robot
Compass Sensor • Senses RELATIVE HEADING • Useful for alignment • Detects nearest 1° • Will detect headings relative to the Earth’s magnetic field. • Built in calibration to minimize interference • Does not get headings relative to the field • Set an Initial Value (will act as a zeroing for the program)
Rotation Sensor (NXT) • Counts ROTATIONS • Built into every NXT Motor • Detects nearest 1° • Useful for precision manipulation of arms, grippers, etc.
Rotation Sensor (external) • Counts ROTATIONS • Used on the DC Drive motors • Needed to use the PID Control of the kit • Useful for driving a distance (autonomous) • If you have four drive motors • 1 DC Motor Control : Place one rotation sensor on each side • 2 DC Motor Control : Place one rotation sensor on each motor
Propulsion and Manipulation • 12V DC Motors • 4 Motors allowed for use • NXT Motors • 3 Motors allowed for use • HS-475B Servos • 6 Servos allowed for use
Can use up to 4 Turning speed is from 0 - 152 rpm, PID loop controlled Continuous rotation Useful for drive motors Consider a second DC controller (arms & mechanisms) External Shaft Encoder 12V DC Motor
Can use up to 3 Turning speed is from 100-170 rpm Continuous rotation Integrated rotation sensor Useful for non-loading bearing mechanisms (I.e. Intakes) NXT Motor
Can use up to 6 Limited motion ( ~ 190°) Position controlled (127 is center, 0 is full left, 255 is full right) Useful load bearing mechanisms (I.e. arms) HS-475B Servo Motor
Coding BasicsDraft Out the Code • Get a diagram of the field • Draw the general routine w/ arrows and numbers • Make side notes noting what happens at each number • i.e. 1) Servo’s raise • Start your first code draft
Coding Basics Dead Reckoning vs. Sensing • Dead Reckoning • A prewritten routine • Code flows A to B to C • If interrupted, will only try to continue • Easier to write • Sensing • Routine that can adapt • Code flows, but can respond • If interrupted, can attempt to correct • More complicated
Coding BasicsTime vs. Rotations • Time • Dependant on battery life • Useful for squaring on a wall • Can be imprecise • Used often for manipulators • Rotations • Independent of battery life • Useful for replicating a routine repeatedly • Very precise, always the same rotations • Used often for movement
Coding BasicsReacting to the environment • Sense the world and react to it • Touch switch is pressed, against something • Ultrasonic rapidly changes, something crossed paths • Light sensor spikes, on a line or off a line • Useful to be able to change course • Code “thinks” for itself • Only as smart as YOU code it!
Coding BasicsFlow of the code • Flow from place to place • DON’T JUMP ALL OVER THE PLACE! • Structure the code ahead of time, plan it out • Make things easy to fix • Make your code neat and clean • Plan the code out ahead of time • Don’t haphazardly place code in • Order your code • Do you want an interrupt? • Is there an importance to the steps?
Coding BasicsCommenting • Use comments to remind yourself • Often you will forget why something is in the code • Explains to the JUDGES what you were thinking • Allows for easy corrections • Write complete thoughts • “Checks for a touch sensor being pressed, if not, continue” • Use them LIBERALLY
Coding BasicsTest! Test! Test! • You can never over test the code • Remember! Other robots will be on the field! • Codes can sometimes be “random” • No matter how great your code is, there is are random chances • Not all fields are the same • Just because it worked once, doesn’t mean it will later… • TEST! TEST! TEST!
Exercise time • As a group we will “write” a coding outline • You are in the kitchen and you want to make a bowl of cereal. What steps do you need to take in order to get a bowl, milk…..?
RobotC Basics • Make sure you are on version 1.46 • If not, uninstall RobotC COMPLETELY before installing the newest version • Use the Sample codes included in RobotC • Access by File > Open Sample Programs • Save RobotC files in separate location on Hard Drive • Download and watch coding presentations at Robotics Academy
Starting up RobotC • Open RobotC • Change Menu Level to Expert • Window > Menu Level > Expert • Change Platform to FTC • Robot > Platform Type > FIRST Tech Challenge (NXT) • Close RobotC and Reopen • Open a blank file • File > New • Ctrl + N • Download Firmware to NXT • Robot > Download Firmware (more to come later) • Rename NXT • Robot > Download Firmware (more to come later)
Installing Firmware : Download and Complete • Make sure that this message appears before exiting
Name you NXT • Type in the name for your NXT (default is NXT). Recommended name is your team number out to 4 places ( I.e. FTC # 1 is 0001 ). If you have more than one NXT place an A, B, etc. after the number.
Connecting with Bluetooth – 1 • Go to Robot > NXT Brick > Link Setup
Connection with Bluetooth – 2 & 3 • 3) Select here to make a pair between the NXT and your Laptop • 2 ) Make sure that this box is checked to perform a bluetooth search
Bluetooth @ The Competition – 1 • Take from the Field Preperation Guide (you can find it here) • Remember to always do these steps at the Playing Field
Compile and Download Compiles and downloads Compile Program Compiles locally Debugger Scans code for errors Motor & Sensor Setup Set up Motor and Sensors Download firmware Download firmware to NXT RobotC MenuRobot
Link Setup Used to establish a link between NXT and Computer Poll Brick “Online Window” File Management Manage files on the NXT Joystick Control “FTC Controller Station” RobotC MenuRobot > NXT Brick
RobotC Debugger • Allows for program control wirelessly • Allows to view where the code is currently • Allows to view errors in your code while running