Programming - Getting Started

With the advent of a new season and the influx of new programmers-to-be I decided to do a 1 or 2 page write-up on just how a programmer new to FIRST can get started. [font=Verdana]I wrote this up to bootstrap rookie team programmers. Sort of a how does one get started when they know absolutely nothing about where to even start programming the FIRST controller. It’s not intended to replace the IFI documentation, it’s more to direct new programmers to it. I tried to stay away from most “how to program” type stuff and more advanced topics like the Linux/Windows debate and configuration management. This is just to get newbies rolling. Anyone have suggestions, additions, corrections. Everything is up for debate. [/font]

P.S. I have enough tips now to continue the recent trend in “lists”, but I’ve created three lists: One for programming tips, another for tips specific to just the control system, and the third for quick starting new FIRST programmers.

Programming Quick Start
[ol]
[li]Beginners need the following to program the FIRST robot:[/li][ul]
[li]FRC (Full-size Robot Controller) RC Default Code[/li][li]Microchip MPLAB & C compiler[/li][li]IFI_Loader[/li][li]A standard serial cable[/li][li]A Windows PC with a serial port or USB-to-serial converter[/li][/ul]
[li]All default code, updates, documentation, and support information is available at http://innovationfirst.com/FIRSTRobotics/documentation.htm, the Innovation FIRST (IFI) website, The default code “FRC RC Default Code” comes ready for basic driving and with a variety of sample I/O usages.[/li][li]MPLAB is the FIRST supplied Windows based development environment (edit, compile, debug) that runs on your desktop computer and is usually provided to each team on a compact disk in the Robovation kit. MPLAB is free on-line at the Microchip website http://www.microchip.com/, but the C compiler is not free except via the Robovation CD and is only available online as a time-limited trial copy or for purchase. Manuals for using MPLAB come on the FIRST CD.[/li][li]IFI_Loader (from the CD or IFI website above) is used to download the compiled code into the RC via a serial cable from your desktop or laptop computer.[/li][li]Check the IFI website periodically for updates to the software that corrects issues fixes problems.[/li][li]The programming language used is “C” or PIC assembly. Tutorials in C can be found on the web, in your local bookstore or on the FIRST website, e.g.,[/li]
[ul]
[li]C Programming Resource Library [http://www.usfirst.org/robotics/C_help.htm[/li][li]Learn C Programming - Developed by Carnegie Mellon and the National Robotics Engineering Consortium specifically for FIRST, this interactive website will get your team prepared for the upcoming FIRST Robotics Competition season. [url=“http://www.rec.ri.cmu.edu/education/robot_builder/”]http://www.rec.ri.cmu.edu/education/robot_builder/](http://www.usfirst.org/robotics/C_help.htm)[/li][li]FIRST Robovation - A Primer for Success Learning Modules http://www.usfirst.org/robotics/robovation/primer/index.html[/li][/ul]
[li]Newer laptops no longer come with serial ports. If you have this problem one solution is to use a USB/Serial converter. Various models are available at Radio Shack, CompUSA, or online.[/li][li]Documentation is your friend. Take the time to at least leaf through each manual, so you have an idea of where information can be found. Most of the basic information beginners require can be found in the IFI documents or MPLAB documents: [/li]
[ul]
[li]IFI Programming Reference Guide – basic how to program and download to the RC, hookup switches and sensors and do normal robot operations.[/li][li]IFI RC Default Code Reference Guide – description of how the default code is structured and where users can add their own custom code.[/li][li]MPLAB v6.xx Getting Started – basic how to use MPLAB and set options.[/li][li]MPLAB C18 Users Guide – table of max numbers each variable type will store, compiler options, error messages, detailed descriptions of pragmas and some other advanced topics.[/li][li]MPLAB C18 Libraries – details on timers, interrupts, and various other utility functions available to the programmer.[/li][/ul]
[ul]
[li]More advanced documents are also available, e.g., 18Fxx20 Data Sheet (& Errata)– PIC assembly instruction set and details on EEPROM and other chip specific topics, and several others.[/li][/ul]
[li]Programming limits to the 2004 RC: [/li]
[ul]
[li]30,720 bytes program space is available to the user, after 2004 IFI code.[/li][li]1,343 bytes of ram available to the user, after 2004 code overhead.[/li][li]256 bytes of global variables available within any one MPLAB file.[/li][li]120 bytes of variables within a single routine.[/li][/ul]
[ul]
[li]The program and data space your code has used can be checked either by the status line at the bottom of the IFI_Loader window or via the optional .map file that MPLAB will generate for you.[/li][/ul]
[li]Common beginner problems include improper MPLAB project setup, trying to pack too much code into the controller, printf misunderstands, using too small a variable type to hold the largest possible intermediate as well as the largest final value of a calculation, and lack of proper variable typecasting.[/li][li]Visit the ChiefDelphi Programming forum for discussions on all programming topics, problems, and issues http://www.chiefdelphi.com/forums.[/li][/ol]

  1. Programming will take more time than you expect, especially if you want autonomous to work. Tell the team that the robot needs to be driving and in your (the programmer’s) hands with at least three days before shipping.

  2. Rookies: Don’t program without sleep. Sure, you’ll hear the experienced programmers bragging about a 36-hour code marathon, but all that means is that they are good at procrastinating. And working without sleep.

  3. Don’t forget to initialize a variable you are using as a PWM output to 127.

  4. Increment your counters! (One year my robot span around in a circle for about three minutes…)

  5. If at all possible, make sure the code works before dumping it into your robot

  6. When testing your robot, lift it off the ground. Prop it up somehow. This can save lives! (well, shins, anyways)

Good Luck!

you might want to add that sometimes serial to usb converters are really tempermental. Alot of people have trouble with them.
Maybe recommend a certain kind that is known to be more reliable than others?

1) The dangers of killing people and dangerous situations etc can be avoided by using/making/building a dongle](http://www.innovationfirst.com/FIRSTRobotics/pdfs/Competition_Port_Pinout_Guide.PDF) .Trust me its worth building that.

  1. Things in theory are not always right practically. You can calculate how far your robot will go in a certain time, but when you do it practically you might find different reasons. For that reason everyone tells you to reserve a lot of time for programming autonomous.

  2. Most of the time if you find a problem, look Though a C guide for syntax, or the Innovation FIRST programming guide, simple mistakes can cause you to go crazy. I agree to Noah, sleep is important, it helps you take it easy and not go bonkers programming.

  3. Step by step: Don’t write the whole robot code in one shot and expect it to work, do it step by step i.e. part by part, drives first, then arm, then other stuff…

  4. Will think up more and post later…

Download PowerPoint Module A:

http://www.usfirst.org/robotics/C_help.htm

It has a great overview of the programming process.

  1. Kill Switches: It’s always a good idea to add drive/device kill switches.(If you have the time)

  2. Limit switches can prevent an appendage from destroying itself. Last year my team constructed a poorly designed arm with the ability to destroy it self, limit switches are the only reason while that robot is still in one piece.

  • Don’t make everything inline! It is a lot easier to maintain, expand, etc. if all the code that actually interacts with stuff is buried, because you only need to change it once.
  • The compiler is extremely weird. If you get syntax errors for no apparent reasons (after checking for things like parens, semi-colons, etc.), type the line again, including the line breaks on each side.
  • If you really can’t figure it out, sleep on it. Meaning: Leave it be and come back tomarrow.
  • [edit]Use #define for I/O port references. Same as reason the first: If you change which port it’s on, you don’t have to go through all your code.[/edit]

If at all possible, get an actual serial port. USB to serial connections are usually not fun to deal with.

Comments are your friends. Use them, use them frequently, and use them intelligently. Try to document the code well enough so that someone who’s never seen it before could understand it. There are certain things that you DON’T want to do - like, say, leaving excessive amounts of old code in the program but commented out, or copying and pasting PBASIC (!) into the comment sections - but it can’t hurt to use them in most cases.

Try to understand the basic framework of the code ahead of time. It would be nice to have your programming team know how to map the controls to the robot fuctions, or how to set up a basic autonomous mode.

Be prepared to deal with time constraints. My team gets the robot with less than two weeks to go most years, and it can be hard to do what you want before you ship. Even if other teams are more efficient in getting the robot to the programmers, you’ll still have to worry about making sure that your code works and that you’ll have enough time to fix what doesn’t.

Most importantly…have fun. The programmers tend to get less credit than they deserve, but the robot wouldn’t run if we weren’t there. :slight_smile:

This is an excellent overview, I’ll have to make a copy for myself and the rest of the programmers on my team.

As far as programming is concerned, I have these few suggestions:

1.) LEARN BASIC or at least take a quick look. It will give you the basics of programming like logical, arithmetic, and relational operators, plus simple counter builds and other good basics.

2.) Then goto About.com’s C Tutorial to learn the basics of C. How it’s structured, done, etc. Try and find a simple compiler other than MPLAB while you’re at it. I have Pacific C, but the site I got it from isn’t working.

3.) Don’t let all the script make you think it’s difficult. Yes, there’s a few difficult parts to get passed like the declaration of variables, knowing what they are, etc. The rest, however, is quite logical.

Otherwise, just remember that you ARE the most important group of people within your team, for it is the programming that makes it a robot and not just a highly modified RC car. :smiley: Have fun!

This is a good overview. But all you people talking about having programming “teams” i ask you : how is it that you get a team, for my team its always just me. And new programmers out there don’t be discuraged when you get blamed for every problem the robot has. And don’t think that you will get any fame out of the robot even if it does work. Everyone else in the team gets that. But hey us programmers get to have all the fun so i soppose it’s a fair trade. :smiley:

  • It’s not ANSI C! It’s funk-a-delic emaciated C!
  • Kill switches are not the way to go, IMO, “Live” switches are. Add some code such that if the trigger on your joystick is not depressed, the bot doesn’t move. This way your driver just has to let go. How did I learn this? When Robots Attaaaaaack!
  • Remember: That piteous mass of metal that the build team insists on fawning over is little more than a glorified RC car without you. You are gods amongst sniveling wretches!!!
  • Err… Um… Don’t let programming go to your head :wink:

Dr Joe has recommended a Bafo Technologies BF-810 if I recall correctly. From last year’s experience, I have to concur that some are VERY tempermental.

Thanks everyone…this is a really good thread

Eric

KISS- Keep It Simple Stupid

Example:

2003: Our robot, Miss Daisy II won the Galileo Division at Nats. Number of Speed Controllers: 3

2004: Our robot, Miss Daisy III didn’t work at Chesapeake, didn’t work very well at Drexel or Nats, and only started working in the offseason.
Number of Speed Controllers: 10-12 (too many)

Don’t let the mechanics bully you into trying to add way too much stuff. Simple stuff can work quite well and it also gives time to write a nice autonomous program.

I knew there was a reason I get up every morning;)

I’ll post the programming and control systems list later on in the week.
I almost pulled a gwross and have a sprained wrist, so typing is slower. It’s hard to post fast enough to beat the time-out.

this helped me soooo much. thank you all. this is our second yr competing and this is my first year in FIRST. i have a java background and a simple C background from 8th grade…but it was so long ago. :eek:

I’m the only one in charge of programming so when i was handed all these Cd’s and codes and links and websites, i was pretty overwhelmed. i just learned about this today and I’ve spend the majority of the day looking through posts to answer my Q’s

**is there anyone here that i can directly e-mail or talk to if i have questions? ** (warning: I’m like a pet, i demand a lot of attn: i have questions everyday…or close to it) :frowning:

also, everyone speaks about a “dongle” and i saw the picture and everything. but what exactly IS it? :confused:

The Operator Interface (OI) has a 15-pin Competition Port connector in the middle of the top. Pins on that connector are used when running on a competition field to enable or disable the robot, select the radio modem frequency, and control autonomous mode. The field also supplies power to the OI through that port.

Teams are permitted to connect to four specific pins on the Competition Port, in order to 1) enable additional frequencies for practicing with multiple robots, 2) activate autonomous mode for testing, and 3) disable the robot. Most teams build a box with two or three switches that connects to the port. That box is called a dongle. The Competition Port Pinout Guide shows how to construct one.

Here’s an updated version for this year with 2005 links included.

Programming Quick Start
[ul]
[li]Beginners need the following to program the FIRST robot:[/li][/ul]

[font=Wingdings][size=3]v FRC (Full-size Robot Controller) RC Default Code[/size][/font]

[font=Wingdings][size=3]v Microchip MPLAB & C compiler

v IFI_Loader
v A standard serial cable
v A Windows PC with a serial port or USB-to-serial converter[/size][/font]

[ul]
[li]All default code, updates, documentation, and support information is available at http://www.ifirobotics.com/rc.shtml and http://www.ifirobotics.com/oi.shtml , the Innovation FIRST (IFI) website, The 2005 default code http://www.ifirobotics.com/docs/frc-code-1-12-2005v2.2.zip comes ready for basic driving and with a variety of sample I/O usages. Optional 2005 default code is also available for use with the CMU camera http://www.ifirobotics.com/docs/frc-code-1-12-2005v2.4.zip. Consult the CMU documentation for other requirements. Useful software examples and documentation, as well as the demonstration code used at kickoff can be found at Kevin Watson’s website http://kevin.org/frc/ .[/li][/ul]
[ul]
[li]MPLAB is the FIRST supplied Windows based development environment (edit, compile, debug) that runs on your desktop computer and is usually provided to each team on a compact disk in the Robovation kit. MPLAB v7.0 is also free on-line at the Microchip website http://microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 , but the C compiler is not free except via the Robovation CD and is normally only available online as a time-limited trial copy or for purchase. For a limited time the latest compiler is available from a link on http://www.usfirst.org/ (bottom left of the page where it says “Microchip Software downloads”). After the link is removed the latest compiler must be obtained through FIRST.Manuals for using MPLAB come on the FIRST CD.[/li][/ul]
[ul]
[li]IFI_Loader (from the CD or IFI website http://www.ifirobotics.com/docs/ifi-loader-v1-0-10.zip) is used to download the compiled code into the RC via a serial cable from your desktop or laptop computer.[/li][/ul]
[ul]
[li]Check the IFI website periodically for updates to the software that corrects issues and fixes problems. For instance, the first update that must be performed is the downloading of a new Master Controller “patch” http://www.ifirobotics.com/docs/master-software-ver10.zip . Follow directions included with the download.[/li][/ul]
[ul]
[li]The programming language used is “C” or PIC assembly. Tutorials in C can be found on the web, in your local bookstore or on the FIRST website, e.g.,[/li][/ul]

v C Programming Resource Library http://www.usfirst.org/robotics/C_help.htm has a great overview of the programming process.
v Learn C Programming - Developed by Carnegie Mellon and the National Robotics Engineering Consortium specifically for FIRST, this interactive website will get your team prepared for the FIRST Robotics Competition. http://www.rec.ri.cmu.edu/education/robot_builder/

v FIRST Robovation - A Primer for Success Learning Modules http://www.usfirst.org/robotics/robovation/primer/index.html

[ul]
[li]Newer laptops no longer come with serial ports. If you have this problem one solution is to use a USB/Serial converter. Various models are available at Radio Shack, CompUSA, or online, however, some models can be temperamental and they generally take longer to download than a built-in serial port (60sec vs 10 sec). Good results have been reported using: Bafo Technologies BF-810 (~$15) and a Radio Shack USB-to-Serial port cable[font=Times New Roman] #26-183 ($42).[/font][/li][/ul]
[ul]
[li]Documentation is your friend. Take the time to at least leaf through each manual, so you have an idea of where information can be found. Most of the basic information beginners require can be found in the IFI documents or MPLAB documents available from the websites:[/li][list]
[li]IFI Quick Start and Overview documents, the 2004 versions apply to 2005 as well http://www.ifirobotics.com/docs/frc_system_quick_start_2004-1-14.pdfhttp://www.ifirobotics.com/docs/control-system-overview-2004-01-07.pdf[/li][li]IFI Programming Reference Guide – basic how to hookup, program and download to the RC, hookup switches and sensors and do normal robot operations. http://www.ifirobotics.com/docs/rc-ref-guide-2005-revnc2.pdf[/li][li]Useful programming and compiler documents come with the tool installations or are available from the Microchip website. http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014 or http://microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002[/li][/ul]
[/list]v c18_getting_started_2.4.pdf http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_C18_Getting_Started_51295d.pdf
v c18_libraries_2.4.pdf – details on timers, interrupts, and various other utility functions available to the programmer. http://ww1.microchip.com/downloads/en/DeviceDoc/C18_Lib_51297d.pdf

v c18_users_guide_2.4.pdf - table of max numbers each variable type will store, compiler options, error messages, detailed descriptions of pragmas and some other advanced topics. http://ww1.microchip.com/downloads/en/DeviceDoc/C18_UG__51288e.pdf

v Microchip pic18f8520 data sheet - PIC assembly instruction set and details on EEPROM and other chip specific topics, and several others. http://ww1.microchip.com/downloads/en/DeviceDoc/39609b.pdf and mistakes in the datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/80157d.pdf

v Microchip PICmicro 18C MCU Family Reference Manual – all things great and small (in excruciating detail) about the processor we use. http://ww1.microchip.com/downloads/en/DeviceDoc/39500a.pdf

v MPLAB Quick Start Guide.pdf - basic how to use MPLAB and set options. http://ww1.microchip.com/downloads/en/DeviceDoc/51281d.pdf

v MPLAB Users Guide.pdf http://ww1.microchip.com/downloads/en/DeviceDoc/51519a.pdf

[ul]
[li]Programming limits to the 2004 RC:[/li][list]
[li]30,720 bytes of program space is available to the user, after 2004 IFI code.[/li][li]1,343 bytes of ram available to the user, after 2004 code overhead.[/li][li]256 bytes of global variables available within any one MPLAB project file, such as user_routines.c[/li][li]120 bytes of variables can be declared within any single routine.[/li][/ul]
[li]The program and data space your code has used can be checked either by the status line at the bottom of the IFI_Loader window or via the optional .map file that you can set MPLAB to generate for you. Note: the .map file lists % of program space used, but the user will have only 90% available to him or her. The .hex is ASCII and file size is no indication of code size.[/li][/list]Visit the ChiefDelphi Programming forum for discussions on all programming topics, problems, and issues http://www.chiefdelphi.com/forums

waves hand hi… I’m another of the newbies with little (read, none) experience working with C. I am also the only one on my team doing the programming dance. At the moment I’m teaching myself from whatever tutorials I can find, but if anyone can spare a moment or ten through e-mail or IM to answer my questions, I would be muchly indebted to you.

AIM- daemonlvr856
e-mail- [email protected]

THANK YOU!!!

~kat

I’m another newbie, with probably less experience than the other two and just as hopeful maybe someone could give me some time cause i’m running into problems i don’t know how to solve. Any help is welcome via im or e-mail or anything.

Team 695

I have another one i forgot about, when I try to build the error is that it can’t locate the build tool, any insight?