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