The Basics of programming


Published on

The basics of programming

Published in: Business, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

The Basics of programming

  1. 1. The Basics of Programming! By Christine Luu 11/28/06
  2. 2. Agenda <ul><li>What is programming? </li></ul><ul><li>Overview </li></ul><ul><li>What you need before you program </li></ul><ul><li>Familiarizing yourself with MPLAB </li></ul><ul><li>Programming in C </li></ul><ul><li>The Code </li></ul><ul><li>Associating things in the programming with things on the robot controller and the operator interface </li></ul><ul><li>Other programming features </li></ul><ul><li>Back up </li></ul>
  3. 3. What is programming? <ul><li>Creating a set of codes to control robot behavior. </li></ul><ul><li>The program will take the input from the operator interface (or the sensors, camera) and tell the robot to do what it’s supposed to do. </li></ul>
  4. 4. What you need before you program <ul><li>Robot Controller & RC Master Code (Processor Firmware) </li></ul><ul><li>Operator Interface & Joysticks </li></ul><ul><li>Software </li></ul><ul><ul><li>MPLAB IDE v.7.0+ (download from </li></ul></ul><ul><ul><li>IFI Loader v.1.0.10+ (download from </li></ul></ul><ul><ul><li>MPLAB C18 Compiler (available during build season at ) </li></ul></ul><ul><ul><li>Latest Default Code </li></ul></ul><ul><li>Computer with a serial port </li></ul><ul><li>An assembled, working electronics board </li></ul><ul><li>Other components (i.e. CMUcam, sensors) </li></ul>
  5. 5. Overview Operator Interface Robot controller Electronics board camera
  6. 6. Familiarizing yourself with MPLAB <ul><li>Workspace – where you edit your files </li></ul><ul><li>Build All – compiles your code into machine language </li></ul><ul><li>Get to know all the files you will use </li></ul><ul><ul><li>Critical files: </li></ul></ul><ul><ul><ul><li>user_routines.c </li></ul></ul></ul><ul><ul><ul><li>user_routines_fast.c </li></ul></ul></ul><ul><ul><ul><li>main.c </li></ul></ul></ul><ul><ul><ul><li>ifi_aliases.h </li></ul></ul></ul>
  7. 7. Programming in C <ul><li>C is a high-level programming language </li></ul><ul><li>Common commands: </li></ul><ul><ul><li>if, else, case, </li></ul></ul><ul><ul><li>while, loop </li></ul></ul><ul><ul><li><=, >=, !=, ==, &&, || </li></ul></ul><ul><li>Syntax: </li></ul><ul><ul><li>Semicolons – end of any command </li></ul></ul><ul><ul><li>Comments - /* blahblah */ </li></ul></ul><ul><ul><li>Brackets { } – used in commands </li></ul></ul>
  8. 8. Programming in C <ul><li>Variables – a name that you assign to a certain part of the electronics so you can control its value </li></ul><ul><ul><li>Example: pwm01 >= 240 </li></ul></ul><ul><li>Functions </li></ul><ul><ul><li>a small piece of code that performs a specific task </li></ul></ul><ul><ul><li>can be called from the main program </li></ul></ul><ul><li>Include – tells the program what files to use to control the different components of the hardware </li></ul><ul><ul><li>Example: #include “ifi_aliases.h” </li></ul></ul>
  9. 9. Example! <ul><li>if (pwm01>=240) </li></ul><ul><li>{ </li></ul><ul><li>pwm01=240; </li></ul><ul><li>} </li></ul><ul><li>else if (pwm01<=14) </li></ul><ul><li>{ </li></ul><ul><li>pwm01=14; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>pwm01=pwm01; </li></ul><ul><li>} </li></ul>This piece of code will limit the maximum speed of the wheels. Stopped = 127 Forward = above 127 up to 255 Reverse = below 127 down to 0 So this code is limiting the max forward speed of the wheel to 240, and the max reverse speed to 14. Otherwise, it will maintain the speed that is given by the joystick.
  10. 10. The Code <ul><li>The Default FRC Code gives you everything you need to get started. </li></ul><ul><li>The main files </li></ul><ul><ul><li>main.c – extremely important, but don’t mess with it. </li></ul></ul><ul><ul><li>user_routines.c – this is where you modify the code to make the robot do what you want it to do. </li></ul></ul><ul><ul><li>user_routines_fast.c – this is where you edit the autonomous mode (where the robot moves by itself). </li></ul></ul><ul><ul><li>ifi_aliases.h – defines all the names of the variables </li></ul></ul>
  11. 11. Associating things in programming w/ things on the robot controller 0-1024 10-bit Analog sensors Rc_ana_in01 - rc_ana_in18 Rc_ana_in## 0 or 1 Bit Digital sensors Rc_dig_in01 - rc_dig_in18 Rc_dig_in## 0 or 1 Bit SPIKE relays Relay1_fwd – relay8_fwd Relay1_rev – relay8_rev relay#_fwd relay#_rev 0-255 Unsigned char Victors (controls motors) Pwm01-pwm16 pwm## Poss. Values Data Type Object on Board Variables available of this type Variable
  12. 12. On Operator Interface 0 or 1 Bit Lights next to “Switch 1-3” Switch1_LED – Switch3_LED Switch#_LED 0-255 Unsigned char Joystick Wheel p1_wheel – p4_wheel p#_wheel 0-255 Unsigned char X and Y axis of joysticks p1_y – p4_y p1_x – p4_x p#_y p#_x 0 or 1 Bit Joystick top button p1_sw_top - p4_sw_top p#_sw_top 0 or 1 Bit Joystick Trigger p1_sw_trig – p4_sw_trig p#_sw_trig 0 or 1 Bit Lights next to “Relay 1” and “Relay 2” Relay1_red – relay2_red Relay1_green – relay8_green relay#_red relay#_green 0 or 1 Bit Lights next to “PWM 1” and “PWM 2” Pwm1_red – pwm2_red Pwn#_red Poss. Values Data Type Object on Board Variables available of this type Variable
  13. 13. Other Programming Features <ul><li>Autonomous </li></ul><ul><li>CMUcam </li></ul><ul><li>Sensors </li></ul>
  14. 14. Things to Keep in Mind <ul><li>Always make copies of the original code before making any modifications. </li></ul><ul><li>Anything you do to the code, no matter how minute it may seem, will have an effect on what the robot does. </li></ul><ul><li>Always know the data type you are manipulating (i.e. unsigned char, bit, etc.) </li></ul><ul><li>Remember the semicolons! </li></ul><ul><li>Never download the program to the robot if there is an error. </li></ul>
  15. 15. <ul><li>Let’s take a look at last year’s code! </li></ul>
  16. 16. HELFUL DOCUMENTS <ul><li>Helpful site : </li></ul><ul><li>CMUcam2_workbook.pdf </li></ul><ul><li>Everything you need to know about the care and feeding of your nifty CMUcam2 camera sensor is in this document. </li></ul><ul><li>CMUcam2_mount_assembly.pdf CMUcam2 pan and tilt mechanism assembly instructions. This information is also included in the workbook. </li></ul><ul><li>CMUcam2_commands.pdf CMUcam2 command dictionary. </li></ul><ul><li>CMUcam2_data_packets.pdf CMUcam2 data packet documentation. </li></ul><ul><li>OV7620_ds.pdf Data sheet for the OV7620 camera module used with the CMUcam2. </li></ul>