1 / 56

Coding for the FIRST Tech Challenge: RobotC

Coding for the FIRST Tech Challenge: RobotC. Presented by : Audrey Yeoh Acknowledgements: Team Unlimited FTC 0001. Why RobotC ?. Speed RobotC runs quicker on the NXT Differences in speed are small until larger code is written Control

nerita
Download Presentation

Coding for the FIRST Tech Challenge: RobotC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Coding for the FIRST Tech Challenge:RobotC Presented by: Audrey Yeoh Acknowledgements: Team Unlimited FTC 0001

  2. 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 RobotC

  3. Hardware Review • Servo • Can only go 180 degrees • In code, it is from 0 to 255 • DC Motor • Continuous • Controlled by power rather than degree (+100 forward to -100 backward) 180° 0 255 RobotC

  4. Plan the Code • Get a diagram of the field • Draw the general routine w/ arrows and numbers • Make side notes noting what happens at each time interval • Start your first draft of the code RobotC

  5. Coding Basics Comments: • “//” is used as a line comment • “/*” is the beginning of a group comment • “*/” ends a group comment • Comments never affect the function of code • Always comment code so your team members understand it! Example: RobotC

  6. 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 RobotC

  7. Reacting 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! RobotC

  8. Flow 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? RobotC

  9. Commenting • 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 RobotC

  10. RobotC Home Screen RobotC

  11. RobotC Basics • Make sure you are on version 3.00 • 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 RobotC

  12. Connect NXT RobotC

  13. Select NXT Brick RobotC

  14. Selecting the Firmware RobotC

  15. Download and Complete • Make sure this message appears before exiting RobotC

  16. Rename NXT RobotC

  17. Name Your NXT • Type in the name for your NXT (default is NXT) • Recommended name is your team number to four digits (i.e FTC #0001 is 0001 • If you have more than one NXT, place an A, B, etc. after the number RobotC

  18. Connecting to Bluetooth 1. Go to Robot > NXT Brick > Link Setup RobotC

  19. Connecting to Bluetooth 2. Make sure that this box is checked to perform a bluetooth search 2. Select here to make a pair between the NXT and your laptop RobotC

  20. Bluetooth at the Competition • Take from the Field Preparation Guide (you can find it here) • Remember to always do these steps at the Playing Field RobotC

  21. Bluetooth at the Competition RobotC

  22. RobotC Menu • 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

  23. RobotC Menu • 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

  24. RobotC Debugger • Allows for program control wirelessly • Allows to view where the code is currently • Allows to view errors in your code while running RobotC

  25. RobotC Debugger Buttons • 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

  26. RobotC Debugger Joystick Control • “FTC Controller Station” • Allows control over Teleoperator and Autonomous • Views controller data RobotC

  27. RobotC “Loops” • While statement • Performs code as long as the statement is true • 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 RobotC

  28. RobotCPunctuation • Brackets { } • Used to control flow of code • Semicolons ; • Used after lines to denote an end • Square Brackets [ ] • Used for sensors and motor declarations • Parenthesis () • Used for time and math functions RobotC

  29. RobotC Operators • == (test a condition) • i.e. while(sensorValue[Touch]==0) • = (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) RobotC

  30. RobotC Commenting • // TEXT • Comments out a single line of text • /* TEXT */ • Comments out all text within the /* and */ • /* • Comments out all text after RobotC

  31. RobotC Simple Program RobotC

  32. 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 RobotC

  33. Teleop Template RobotC

  34. Autonomous Template RobotC

  35. Joystick Control Sample RobotC

  36. DC Motor Sample RobotC

  37. NXT Motor Sample RobotC

  38. Servo Sample RobotC

  39. Touch Center Sample RobotC

  40. Light Sensor Sample RobotC

  41. Light Sensor Sample RobotC

  42. Ultrasonic Sensor Sample RobotC

  43. Compass Sensor Sample RobotC

  44. Field Diagram RobotC

  45. 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 RobotC

  46. RobotC Resources • RobotC Sample code • Program files > Robotics Academy > RobotC for Mindstorms > Sample Programs > NXT • File > Open Sample Programs (if RobotC is open) RobotC

  47. Coding for the FIRST Tech Challenge:RobotC Questions?

  48. Programming Structures • Clean code • Readable to humans • Comment and Methods • Reiteration RobotC

  49. Variables • What are variables? • They are things you store in the program that you may want to use • How are they made? • They are made according to their ‘types’ eg. Integer (int) • Example Structure:int apple = 0; • If they occur outside { } of any methods, they are instance variables RobotC

  50. Variables Continued… • Variables are ‘alive’ only in the highest method they are in • ‘Dead’ Variables can be used again • Eg. Void appleCount {int apple = 3;}Void pearCount{int apple = 4} RobotC

More Related