pptx - Home of Team Unlimited

Report
NXT/G, LabVIEW & RobotC compared, and a Crash
Course in RobotC
Presented by Team Unlimited, FTC #1
http://unlimited.syraweb.org/
2008 – 2009 Team Unlimited (FTC # 1)
Coding for the FIRST Tech Challenge
Presentation Overview
Coding Environment Comparisons
Why RobotC?
NXT Overview
Sensor overview
Motor & Servo Overview
Coding Basics
RobotC Overview & Basics
Sample code
Code in RobotC
2008 – 2009 Team Unlimited (FTC # 1)









Coding Comparison
LabVIE
W
• Graphics Based
• Learning Curve : Moderate
RobotC
• Text Based
• Learning Curve : Hardest
2008 – 2009 Team Unlimited (FTC # 1)
NXT-G
• Graphics Based
• Learning Curve : Easiest
NXT-G Overview
Graphics based coding environment
Similar to RoboLab (from RCX)
Layer over LabVIEW
Learning Curve : Easiest
2008 – 2009 Team Unlimited (FTC # 1)




NXT-G : Advantages and
Disadvantages
2008 – 2009 Team Unlimited (FTC # 1)
+ 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
NXT-G Home Screen
2008 – 2009 Team Unlimited (FTC # 1)
NXT-G Side Bars
2008 – 2009 Team Unlimited (FTC # 1)
LabVIEW Overview
2008 – 2009 Team Unlimited (FTC # 1)
 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
2008 – 2009 Team Unlimited (FTC # 1)
+ 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
Labview Home Screen
2008 – 2009 Team Unlimited (FTC # 1)
RobotC : Advantages and
Disadvantages
2008 – 2009 Team Unlimited (FTC # 1)
+ 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
2008 – 2009 Team Unlimited (FTC # 1)
 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
RobotC Home Screen
2008 – 2009 Team Unlimited (FTC # 1)
Why RobotC?
 Speed
 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
2008 – 2009 Team Unlimited (FTC # 1)
 RobotC runs quicker on the NXT
NXT Controller
 Loudspeaker - program
with real sound output
 Attachment points – for
LEGO Technic pins,
connect to chassis.
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
2008 – 2009 Team Unlimited (FTC # 1)
 Sensor ports - four
input ports for
attaching sensors Ports 1, 2, 3 and 4.
NXT Controller Continued
 USB port - USB cable to
the USB port,
download programs
from computer to NXT.
Also can use the
wireless Bluetooth
connection.
2008 – 2009 Team Unlimited (FTC # 1)
 Motor ports - 3 output
ports for attaching
motors - Ports A, B & C
Recommend Sensors
Touch sensor
Light sensor
Ultrasonic sensor
Compass sensor
Rotation sensors
2008 – 2009 Team Unlimited (FTC # 1)





Touch Sensor
 Senses COLLISIONS
 Simple binary switch “on” or “off
2008 – 2009 Team Unlimited (FTC # 1)
 Useful for sensing a wall or robot
Light Sensor
 Senses LIGHT (not color)
 Two types
 Reflected – Shines a light
 Ambient – Uses available light
 With a filter, can detect a color
2008 – 2009 Team Unlimited (FTC # 1)
 Useful for line following
Ultrasonic Sensor
 Senses PROXIMITY
 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
2008 – 2009 Team Unlimited (FTC # 1)
 Useful for sensing distance
Compass Sensor
 Senses RELATIVE HEADING
 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)
2008 – 2009 Team Unlimited (FTC # 1)
 Useful for alignment
Rotation Sensor (NXT)
Counts ROTATIONS
Built into every NXT Motor
Detects nearest 1°
Useful for precision manipulation of arms,
grippers, etc.
2008 – 2009 Team Unlimited (FTC # 1)




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
2008 – 2009 Team Unlimited (FTC # 1)





Propulsion and Manipulation
 12V DC Motors
 NXT Motors
 3 Motors allowed for use
 HS-475B Servos
 6 Servos allowed for use
2008 – 2009 Team Unlimited (FTC # 1)
 4 Motors allowed for use
12V DC Motor
 Can use up to 4
 Continuous rotation
 Useful for drive motors
 Consider a second DC
controller (arms &
mechanisms)
 External Shaft Encoder
2008 – 2009 Team Unlimited (FTC # 1)
 Turning speed is from 0 152 rpm, PID loop
controlled
NXT Motor
 Can use up to 3
 Continuous rotation
 Integrated rotation
sensor
 Useful for non-loading
bearing mechanisms
(I.e. Intakes)
2008 – 2009 Team Unlimited (FTC # 1)
 Turning speed is from
100-170 rpm
HS-475B Servo Motor
 Can use up to 6
 Position controlled (127
is center, 0 is full left,
255 is full right)
 Useful load bearing
mechanisms (I.e. arms)
2008 – 2009 Team Unlimited (FTC # 1)
 Limited motion ( ~ 190°)
Coding Basics
Draft Out the Code
 i.e. 1) Servo’s raise
 Start your first code draft
2008 – 2009 Team Unlimited (FTC # 1)
 Get a diagram of the field
 Draw the general routine w/ arrows and
numbers
 Make side notes noting what happens at
each number
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
2008 – 2009 Team Unlimited (FTC # 1)




Coding Basics
Time 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
2008 – 2009 Team Unlimited (FTC # 1)




Coding Basics
Reacting to the environment
 Sense the world and react to it
 Useful to be able to change course
 Code “thinks” for itself
 Only as smart as YOU code it!
2008 – 2009 Team Unlimited (FTC # 1)
 Touch switch is pressed, against something
 Ultrasonic rapidly changes, something crossed
paths
 Light sensor spikes, on a line or off a line
Coding Basics
Flow of the code
 Flow from place to place
 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?
2008 – 2009 Team Unlimited (FTC # 1)
 DON’T JUMP ALL OVER THE PLACE!
 Structure the code ahead of time, plan it out
Coding Basics
Commenting
 Use comments to remind yourself
 “Checks for a touch sensor being pressed, if not,
continue”
 Use them LIBERALLY
2008 – 2009 Team Unlimited (FTC # 1)
 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
Coding Basics
Test! Test! Test!
 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!
2008 – 2009 Team Unlimited (FTC # 1)
 You can never over test the code
 Remember! Other robots will be on the field!
 Codes can sometimes be “random”
Exercise time
 As a group we will “write” a coding outline
2008 – 2009 Team Unlimited (FTC # 1)
 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
 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
2008 – 2009 Team Unlimited (FTC # 1)
 If not, uninstall RobotC COMPLETELY before
installing the newest version
Starting up RobotC
 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)
2008 – 2009 Team Unlimited (FTC # 1)
 Open RobotC
 Change Menu Level to Expert
Installing Firmware :
Connect NXT
2008 – 2009 Team Unlimited (FTC # 1)
Installing Firmware :
Select NXT Brick
2008 – 2009 Team Unlimited (FTC # 1)
Installing Firmware :
Select the firmware
2008 – 2009 Team Unlimited (FTC # 1)
Installing Firmware :
Download and Complete
2008 – 2009 Team Unlimited (FTC # 1)
 Make sure that this message appears
before exiting
Rename NXT
2008 – 2009 Team Unlimited (FTC # 1)
Name you NXT
2008 – 2009 Team Unlimited (FTC # 1)
 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
2008 – 2009 Team Unlimited (FTC # 1)
 Go to Robot > NXT Brick >
Link Setup
Connection with
Bluetooth – 2 & 3
2 ) Make sure that this box is
checked to perform a
bluetooth search
2008 – 2009 Team Unlimited (FTC # 1)
3) Select here to make a pair
between the NXT and your
Laptop
Bluetooth @ The
Competition – 1
2008 – 2009 Team Unlimited (FTC # 1)
 Take from the Field Preperation Guide
(you can find it here)
 Remember to always do these steps at
the Playing Field
Bluetooth @ The
Competition – 2
2008 – 2009 Team Unlimited (FTC # 1)
RobotC Menu
Robot
 Compile and Download
 Compile Program
 Compiles locally
 Debugger
 Scans code for errors
 Motor & Sensor Setup
 Set up Motor and Sensors
 Download firmware
 Download firmware to
NXT
2008 – 2009 Team Unlimited (FTC # 1)
 Compiles and downloads
RobotC Menu
Robot > NXT Brick
 Link Setup
 Poll Brick
 “Online Window”
 File Management
 Manage files on the NXT
 Joystick Control
 “FTC Controller Station”
2008 – 2009 Team Unlimited (FTC # 1)
 Used to establish a link
between NXT and
Computer
RobotC Debugger
2008 – 2009 Team Unlimited (FTC # 1)
 Allows for
program control
wirelessly
 Allows to view
where the code is
currently
 Allows to view
errors in your
code while
running
RobotC Debugger
Button usages
2008 – 2009 Team Unlimited (FTC # 1)
Start/Stop – Starts or Aborts Program
Suspend – Pauses code
Step Into – Pauses code and proceeds to next line
Step Over – Pauses code and skips over next
procedure
 Step Out - Pauses code and exits procedure
 Clear All – Resets all values to default
 Refresh Rate
 Once – Refreshes values manually
 Continuous/Stop – Switch between continuous
and stop updating




RobotC Debugger
Joystick Control
2008 – 2009 Team Unlimited (FTC # 1)
 “FTC Controller
Station”
 Allows control
over Teleoperator
and Autonomous
 Views controller
data
RobotC “Loops”
 While statement
 I.e. while (ServoValue[Servo1] < 255)
 If statement
 Performs entirety of code if statement is true
 I.e. if (sensorValue[Touch] == 0)
 Else statement
 Performs entirety of code if “If Statement” is
false
 I.e. else
2008 – 2009 Team Unlimited (FTC # 1)
 Performs code as long as the statement is true
RobotC Puncuation
 Brackets { }
 Semicolons ;
 Used after lines to denote an end
 Square Brackets [ ]
 Used for sensors and motor declarations
 Parenthesis ()
 Used for time and math functions
2008 – 2009 Team Unlimited (FTC # 1)
 Used to control flow of code
RobotC Operators
 == (Test a condition)
 = (equals)
 I.e. motor[motorD] = 0;
 < , > (less than, greater than)
 I.e. if ( -10 < joystick.joy1_y1 < 10 )
 || (or)
 I.e. if ( joy1Btn(1) || joystick.joy2_TopHat == 0 )
2008 – 2009 Team Unlimited (FTC # 1)
 I.e. while (sensorValue[Touch] == 0)
RobotC Commenting
 // TEXT
 /* TEXT */
 Comments out all text within the /* and */
 /*
 Comments out all text after
2008 – 2009 Team Unlimited (FTC # 1)
 Comments out a single line of text
RobotC Simple Program
2008 – 2009 Team Unlimited (FTC # 1)
Sample Code
FTC Template
Joystick Control
DC Drive Motor sample
NXT Motor sample
Servo sample
Touch Sensor sample
Light Sensor sample
Ultrasonic Sensor sample
Compass Sensor sample
2008 – 2009 Team Unlimited (FTC # 1)









Using the FTC Template
–1
 Using the Template (take from here)
2008 – 2009 Team Unlimited (FTC # 1)
Using the FTC Template
–2
2008 – 2009 Team Unlimited (FTC # 1)
Using the FTC Template
–3
2008 – 2009 Team Unlimited (FTC # 1)
Tele-Op Template
2008 – 2009 Team Unlimited (FTC # 1)
Autonomous Template
2008 – 2009 Team Unlimited (FTC # 1)
Joystick Control sample
2008 – 2009 Team Unlimited (FTC # 1)
DC Motor sample
2008 – 2009 Team Unlimited (FTC # 1)
NXT Motor sample
2008 – 2009 Team Unlimited (FTC # 1)
Servo sample
2008 – 2009 Team Unlimited (FTC # 1)
Touch Sensor sample
2008 – 2009 Team Unlimited (FTC # 1)
Light Sensor sample
2008 – 2009 Team Unlimited (FTC # 1)
Ultrasonic Sensor sample
2008 – 2009 Team Unlimited (FTC # 1)
Compass Sensor sample
2008 – 2009 Team Unlimited (FTC # 1)
Field Diagram
2008 – 2009 Team Unlimited (FTC # 1)
RobotC Resources
RobotC
RobotC Forums
Robotics Academy
FTC Function Guide (From Robotics Academy)
Setting up Dual Template Mode
Field Procedures for Bluetooth
Software Information (Links at our website)
Code and Software Presentation
2008 – 2009 Team Unlimited (FTC # 1)








RobotC Resources
 RobotC Sample code
2008 – 2009 Team Unlimited (FTC # 1)
 Program files > Robotics Academy > RobotC for
Mindstorms > Sample Programs > NXT
 File > Open Sample Programs (if RobotC is open)
Questions?
 http://unlimited.syraweb.org/
 Feel free to send us an email:
 [email protected]
2008 – 2009 Team Unlimited (FTC # 1)
 Questions?
 Download this presentation and the sample
codes from our website:

similar documents