Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Programming - Getting Started (http://www.chiefdelphi.com/forums/showthread.php?t=30976)

Mark McLeod 28-10-2004 15:02

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

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
  1. Beginners need the following to program the FIRST robot:
    • FRC (Full-size Robot Controller) RC Default Code
    • Microchip MPLAB & C compiler
    • IFI_Loader
    • A standard serial cable
    • A Windows PC with a serial port or USB-to-serial converter
  2. 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.
  3. 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.
  4. 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.
  5. Check the IFI website periodically for updates to the software that corrects issues fixes problems.
  6. 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.,
  7. 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.
  8. 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:
    • IFI Programming Reference Guide – basic how to program and download to the RC, hookup switches and sensors and do normal robot operations.
    • IFI RC Default Code Reference Guide – description of how the default code is structured and where users can add their own custom code.
    • MPLAB v6.xx Getting Started – basic how to use MPLAB and set options.
    • 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.
    • MPLAB C18 Libraries – details on timers, interrupts, and various other utility functions available to the programmer.
    • 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.
  9. Programming limits to the 2004 RC:
    • 30,720 bytes program space is available to the user, after 2004 IFI code.
    • 1,343 bytes of ram available to the user, after 2004 code overhead.
    • 256 bytes of global variables available within any one MPLAB file.
    • 120 bytes of variables within a single routine.
    • 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.
  10. 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.
  11. Visit the ChiefDelphi Programming forum for discussions on all programming topics, problems, and issues http://www.chiefdelphi.com/forums.

Noah 28-10-2004 17:06

Re: Programming - Getting Started
 
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!

Jaine Perotti 28-10-2004 17:23

Re: Programming - Getting Started
 
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?

Bharat Nain 28-10-2004 17:43

Re: Programming - Getting Started
 
Quote:

Originally Posted by Noah
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!

1) The dangers of killing people and dangerous situations etc can be avoided by using/making/building a dongle .Trust me its worth building that.

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

3) 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.

4) 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....

5) Will think up more and post later...

av11d 28-10-2004 19:11

Re: Programming - Getting Started
 
Download PowerPoint Module A:

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

It has a great overview of the programming process.

scitobor 617 28-10-2004 22:37

Re: Programming - Getting Started
 
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.

Astronouth7303 29-10-2004 14:07

Re: Programming - Getting Started
 
  • 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]

IMDWalrus 29-10-2004 16:31

Re: Programming - Getting Started
 
Quote:

Originally Posted by BurningQuestion
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?

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. :)

JoeXIII'007 29-10-2004 19:19

Re: Programming - Getting Started
 
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. :D Have fun!

CrashZero 31-10-2004 00:48

Re: Programming - Getting Started
 
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. :D

phrontist 31-10-2004 15:34

Re: Programming - Getting Started
 
  • 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 ;)

EricS-Team180 31-10-2004 18:35

Re: Programming - Getting Started
 
Quote:

Originally Posted by BurningQuestion
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?


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

fred 31-10-2004 18:41

Re: Programming - Getting Started
 
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.

Mark McLeod 31-10-2004 21:16

Re: Programming - Getting Started
 
Quote:

Originally Posted by phrontist
  • You are gods amongst sniveling wretches!!!

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.

nehalita 15-01-2005 18:41

Re: Programming - Getting Started
 
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) :(

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


All times are GMT -5. The time now is 00:26.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi