Log in

View Full Version : Programming FAQ


Astronouth7303
16-12-2004, 19:17
It seems like we get a lot of the same questions here. So, here's a repository of some of the most common ones. Feel free to post your own with answers.

If you have a question that is not answered here, please search first. I can almost guarantee that someone has asked a similar question before.

Q. MPLAB says that it can't find "xxx.h". What's up?
A. if it's a standard header (eg, #include <adc.h>) then odds are that MPLAB is misconfigured. Either set the include directory manually, or reinstall MCC18 and checking the check boxes.

Bharat Nain
16-12-2004, 19:46
I need help programming my autonomous?
Look here (http://www.chiefdelphi.com/forums/showthread.php?t=31678&highlight=autonomous), there (http://www.chiefdelphi.com/forums/showthread.php?t=31812&highlight=autonomous), here (http://www.chiefdelphi.com/forums/showthread.php?t=31812&highlight=autonomous), there (http://www.chiefdelphi.com/forums/showthread.php?t=31589&highlight=autonomous), here (http://www.chiefdelphi.com/forums/showthread.php?t=31543&highlight=autonomous) & in the programming white papers (http://www.chiefdelphi.com/forums/papers.php?s=&categoryid=6&perpage=10&direction=DESC&sort=date) & Search for more. There is more stuff than you can imagine.

//Brandon or any mod, Make this a sticky if you can...

Tom Bottiglieri
16-12-2004, 19:56
This one got me for a while when I first started using the RC.

Q: My robot isnt responding to controllers, wont download a new program, and is stuck in disabled mode. What do I do?

A: 1)hold down both the program and reset buttons.
2)Then, let go of the reset button. (The power light will be blinking green. )
3)Wait until the green light is solid.
4)Let go of the program button.

or see here (http://www.chiefdelphi.com/forums/showthread.php?t=25321&highlight=reset+button)

Astronouth7303
21-12-2004, 18:22
Q. I get an error when i try to compile:
Error - Source file 'C:\path\that's\too\long\for\the\compiler\ifi_util ities.c' name exceeds file format maximum of 62 characters.
How do I fix this?

A. Don't put the code on the Desktop or My Documents. Here's why:

MCC18, the compiler, can only handle paths that are less than 62 characters long. Here is a few paths to the Desktop and My Documents (with the first 62 in green and everything else in red):

C:\Documents and Settings\Kristin & Steve\Desktop\FIRST Code\Default code\ifi_utilities.c
D:\Documents and Settings\Astronouth7303\My Documents\Robotics stuff\codes\Default code\main.c

A better place to put it would be C:\Code\Default Code\.

Ryan M.
22-12-2004, 07:33
Similar to Tom's:

Q: My programming is running the way it should!

A: Amazingly, about a quarter of the time it isn't really your fault. Try pressing the reset button on the robot controller, then re-download. Sometimes things just get a little corrupted. If it still doesn't work, then start debugging your code...

Guest
22-12-2004, 23:29
Similar to Tom's:

Q: My programming is running the way it should!

A: Amazingly, about a quarter of the time it isn't really your fault. Try pressing the reset button on the robot controller, then re-download. Sometimes things just get a little corrupted. If it still doesn't work, then start debugging your code...
Q. My programming isn't running the way it should!

A. See above. But when it is running the way it should, about a quarter of the time it still isn't your fault ;)

randomperson
23-12-2004, 02:35
Q. I get an error when i try to compile:

How do I fix this?

A. Don't put the code on the Desktop or My Documents. Here's why:

MCC18, the compiler, can only handle paths that are less than 62 characters long. Here is a few paths to the Desktop and My Documents (with the first 62 in green and everything else in red):

C:\Documents and Settings\Kristin & Steve\Desktop\FIRST Code\Default code\ifi_utilities.c
D:\Documents and Settings\Astronouth7303\My Documents\Robotics stuff\codes\Default code\main.c

A better place to put it would be C:\Code\Default Code\.

You know... actually technically that isn't true. Sorta. It is true that it generates an error, but the problem with the 62-character limit is only with the COD file that the linker tries to generate, none of the other files. Correct me if I'm wrong, but I don't think that the COD file is actually used for anything, so you could use as big of a path as you would like if this file wasn't generated.

That being said, I am using MPLAB 7 (which you can download at www.microchip.com), so it may not be possible to disable this in MPLAB 6.x. I know a vast majority of you will be using 6.x because it was distributed with the C18 software last year... someone please correct me if this option isn't available in MPLAB 6.x. If you're using the C18 tools by the command line, then just add option /w and it shouldn't generate the file also... which, you can edit the command line in MPLAB 6.x, so you can just add the /w switch to the MPLINK command and not have a problem.

Here's the workaround for MPLAB 7.

In the MPLAB menu:

Project-> Build Options -> Project

Click on the tab "MPLINK Linker", and check the option "Supress COD-file generation".

Now it won't generate this file, and you can use a path as big as you would like to use. Well, within reason... :D


Apparently, the C-Bot CD that has the licensed version of C18 does not have the correct linker in its c:\mcc18\ directory... so if you use the /w option you will get "invalid option" and still have the problem. However, if you tell MPLAB to use the linker that it came with (located in c:\program files\Microchip\MPASM Suite\mplink.exe), then it should work with no problem

With all that said, if you don't feel like dealing with any problems, don't touch anything, use the default stuff, and make sure your path is under 62 characters :)

Bharat Nain
02-01-2005, 02:52
Question: What OS is on the robot? If there is none or its horrible can I put embedded Linux on it? I only run Linux myself, is it possible to program this robot on Linux? Is there some sort of emulator I can get so I don't have to be with the robot, or it dose not have to be fully built for me to test?
Or basically
I am a rookie, where do I start, I want to learn about the robot controller.


Answer: OK first, yes you can program this robot using Linux. Visit http://kevin.org/frc/ and you should find some more information. For starting off, I highly recommend the documents on http://www.innovationfirst.com/FIRS...cumentation.htm (http://www.innovationfirst.com/FIRSTRobotics/documentation.htm)
And then if you are advanced enough you can look at this (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010319) page, but only if you are a really core programmer. Otherwise innovation FIRST is the best place to start.

To answer another part of you question, there is no OS on the robot controller. It is a microchip which understands C and assembler. Search, Read documents and get a feel of what our robot controller(microchip product) is. Its might not be such a good idea to try to go as far and put Linux on there or something, Search, Read documents you can find and you will get a feel.

-Bharat

cabbagekid2
10-01-2005, 14:03
Question: Does everyone use the C18 compiler? Or do some of you use the Visual Studio C compiler?

If you use the Visual Studio C complier, how would you download the code to the RC?

Matt Leese
10-01-2005, 16:15
Question: Does everyone use the C18 compiler? Or do some of you use the Visual Studio C compiler?

If you use the Visual Studio C complier, how would you download the code to the RC?
You must use the C18 compiler. The Visual Studio C++ compiler does not target the Microchip microcontroller.

Matt

Astronouth7303
10-01-2005, 19:01
Q: Where can I find all this cool stuff that was talked about in the (2005) kickoff?

A: The Camera stuff, default code, (eventually) the new firmware (master code), and technical docs are on http://ifirobotics.com. The link to the new IDE and MCC18 compiler are on FIRST's website (http://www.usfirst.org/).

Q: I CAN'T FIND THE COMPILER!!! THE LINK IS MESSED UP!!! HELP!!!

A: Yes, we know you can't download the compiler right now. Asking again won't help. Just try again later (like tomarrow) and hope it works. We can't do anything about it no matter how much you pester us.

Astronouth7303
16-01-2005, 20:34
Q. Why won't my program link? (Generic Linking problems)

A. If you have any kind of linking problems, the first thing you should do is to tell it to Build All (Ctrl+F10, or Project > Build All). If this doesn't help, keep digging here.

djcapelis
17-01-2005, 20:43
To answer another part of you question, there is no OS on the robot controller. It is a microchip which understands C and assembler. Search, Read documents and get a feel of what our robot controller(microchip product) is. Its might not be such a good idea to try to go as far and put Linux on there or something, Search, Read documents you can find and you will get a feel.

-Bharat

Not quite. The controller doesn't understand C or ASM actually, the compiler and linker turns these languages into machine code which the controller can understand. It works just like any other processor in that way. :)

I believe another thread on this forum is porting RTOS to the microcontroller.

JBotAlan
06-02-2005, 17:44
Q: I CAN'T FIND THE COMPILER!!! THE LINK IS MESSED UP!!! HELP!!!

A: Yes, we know you can't download the compiler right now. Asking again won't help. Just try again later (like tomarrow) and hope it works. We can't do anything about it no matter how much you pester us.

I e-mailed the support e-mail address on usfirst.org and the next day it worked. I don't know if this was just coincidence or if it was because of my e-mail, but there it is.

Astronouth7303
08-02-2005, 18:03
Q: I CAN'T FIND THE COMPILER!!! THE LINK IS MESSED UP!!! HELP!!!

A: Yes, we know you can't download the compiler right now. Asking again won't help. Just try again later (like tomarrow) and hope it works. We can't do anything about it no matter how much you pester us.

This is now outdated. At kick-off, Dave Lavery said that the compiler would be on Microchip's website for 2 weeks. The beggining of week number three was January 22, 2005. If you are still in need of a compiler, your best bet is to contact another FIRST member.

Joohoo
26-10-2005, 21:32
Right now for my team I am the only ""programmer"" so we are using the same code from last year to run the new one, but the computer that held it crashed and our back up is sitting on a college freshmen's desk.

Q. is there anyway to "uncompile" the code directly from the controller? or do i have to start from scratch?

Bharat Nain
26-10-2005, 21:38
Right now for my team I am the only ""programmer"" so we are using the same code from last year to run the new one, but the computer that held it crashed and our back up is sitting on a college freshmen's desk.

Q. is there anyway to "uncompile" the code directly from the controller? or do i have to start from scratch?

You cannot exactly "uncompile" a code. What you can do is recover what is already in the robot. Check out IFIs website (http://www.ifirobotics.com/rc.shtml#Programming) for the software and details.

Greg Marra
26-10-2005, 21:51
You cannot exactly "uncompile" a code. What you can do is recover what is already in the robot. Check out IFIs website (http://www.ifirobotics.com/rc.shtml#Programming) for the software and details.

"Device Reader (zip, 2-1-2005) for reading and restoring Code in a RC (can not modify the code), instructions included."

Once the code is compiled (which is the state the downloaded code is in), it's stuck that way. There are few ways to decompile it back to the original C code it was compiled from.

I'm afraid you're stuck.

Joohoo
27-10-2005, 14:57
"Device Reader (zip, 2-1-2005) for reading and restoring Code in a RC (can not modify the code), instructions included."

Once the code is compiled (which is the state the downloaded code is in), it's stuck that way. There are few ways to decompile it back to the original C code it was compiled from.

I'm afraid you're stuck.

thanks i geuss i'll have just rebuild it

aamodsams
25-12-2005, 12:32
I just have a quick question. How do you load a program into an old robot controller that does not have the "prog"ram button? :confused:

Mark McLeod
25-12-2005, 14:33
I just have a quick question. How do you load a program into an old robot controller that does not have the "prog"ram button? :confused:
Sounds like you have a pre-2004 Robot Controller.
Those were programmed in PBasic from Parallax not C and used an entirely different editor/compiler/downloader. It worked without the need for a "program" download button.

Let me find some references for you...

Most of what you need can be found here:
http://www.ifirobotics.com/first-legacy.shtml
under Documentation for 2001 - 2003

The default code with drive capability and the Editor that also downloads the code is available there, as well as documentation that describes what you need to know to get started.
Another useful site is:
http://www.parallax.com (http://www.parallax.com/)
In particular:
http://www.parallax.com/html_pages/...basic_stamp.asp (http://www.parallax.com/html_pages/downloads/software/software_basic_stamp.asp)
for the latest Editor
and
http://www.parallax.com/html_pages/...basic_stamp.asp (http://www.parallax.com/html_pages/downloads/basicstamps/documentation_basic_stamp.asp)
for in-depth PBasic user guides.

__________________

aamodsams
25-12-2005, 20:39
Thank you very much. I will try those links and see what I can get.

b_mallerd
25-12-2005, 21:15
Isn't asm the same thing as machine code? The only difference is your mov or w/e is replaced with a number.

Ryan M.
26-12-2005, 08:29
Isn't asm the same thing as machine code? The only difference is your mov or w/e is replaced with a number.Yes, asembly is pretty much just a straight substitution of hex for a mnemonic.

MaddyW
16-01-2007, 14:25
Our team tried to load code from last years robot it doesn't work for some reason. One of leaders thought he saw something about not being able to use previous code on the 2007 controller. Anyone seen that rule/had problems/ideas?

Mike Betts
16-01-2007, 15:51
Our team tried to load code from last years robot it doesn't work for some reason. One of leaders thought he saw something about not being able to use previous code on the 2007 controller. Anyone seen that rule/had problems/ideas?

Someone correct me if I am mistaken...

For debugging purposes, the 2006 code can be loaded into the 2007 controller. However, <R76> prohibits you from reusing code from 2006 in your 2007 competition robot.

Regards,

Mike

Astronouth7303
17-01-2007, 13:26
Someone correct me if I am mistaken...

For debugging purposes, the 2006 code can be loaded into the 2007 controller. However, <R76> prohibits you from reusing code from 2006 in your 2007 competition robot.

Regards,

Mike

The general opinion of the rule is that it somewhat akin to the bolt-on grabber. You may use code from previous years, just as you can use a design from previous years. But you should shy away from "bolt-on" black box libraries.

mormannoob
21-01-2007, 21:39
hi
i need help on getting started on the drive code, i was on the team last but wasn't in charge of drive code and im a little lost on how to design it.Our main programmer and mentors have been busy recently and unable to help me. if some one could give me some help on at least some sort of outline of the code i should be able to figure it out from there i dont need anything crazy just so the robot can move and turn
thanks
confused programmer

Mark McLeod
21-01-2007, 22:10
Try going through the default code description in the Programming Reference Guide (http://www.ifirobotics.com/docs/legacy/2004-programming-reference-guide-12-apr-2004.pdf). It's from 2004 but everything still holds true.

monkeyleader
01-02-2007, 23:47
It seems like we get a lot of the same questions here. So, here's a repository of some of the most common ones. Feel free to post your own with answers.

If you have a question that is not answered here, please search first. I can almost guarantee that someone has asked a similar question before.

Q. MPLAB says that it can't find "xxx.h". What's up?
A. if it's a standard header (eg, #include <adc.h>) then odds are that MPLAB is misconfigured. Either set the include directory manually, or reinstall MCC18 and checking the check boxes.

I would rather not reinstall MCC18 at the moment because i'm in miami for the superbowl and dont have the disk n stuff with me. How do i set the include directory manually, mine can't find stdio.h but only in one of the files, there's at least 1 file prior to it that has #include <stdio.h> and it can find it there, just not in this one and i don't understand why. Please help.

paulcd2000
10-02-2007, 14:44
Here's one that i've been seeing a lot recently:
Q. How do i add kevin's [insert extra hardware name(e.g. camera, encoder, etc.)] code?
A. Look at the readme in the files that come with it. they tell you exactly how to do it.

vivek16
02-04-2007, 16:18
do i need to learn unix before i learn C? my mom has been telling me to do this before i attempt to learn c although i have gone through some of the tutorials and it does not seem to get mentioned anywhere.

bear24rw
02-04-2007, 16:47
do i need to learn unix before i learn C? my mom has been telling me to do this before i attempt to learn c although i have gone through some of the tutorials and it does not seem to get mentioned anywhere.

Not at all.. if you don't know any C I would suggest following some tutorials at www.cprogramming.com and looking through the default code. I started with TI-BASIC (calculator) in 8th grade and have moved into maybe different languages. Once you learn the basics its really easy going from one to another

Neil [Coconuts]
25-01-2008, 17:45
Where can I find the default code for MPLabs?
The Link: http://innovationfirst.com/FIRSTRobotics/documentation.htm
seems to be broken (or at least it won't load for me).
Can I get the code anywhere else?

program1
25-01-2008, 21:41
im have a bit of a problem, i've loaded the 2007 default code and now the controller moves the moters in reverse. did something happen to the program?

lukevanoort
25-01-2008, 21:47
Your motors are probably wired in reverse. Without additional sensors, your robot has no way of knowing which way the motors are actually turning (and even if it did, it doesn't know what you want as forward and backward until you add that). Try doing something like this:pwm02 = 254 - p2_y; instead of the usual pwm02 = p2_y; and see if that fixes the issue. You could also swap the position of the + and - motor wires on the Victor output. WARNING: Don't swap + and - wires on the Victor's power input; if you do that, the Victor will be destroyed.

program1
26-01-2008, 14:30
ok, thanks. now i have another question. is there a manual or a guide that teaches you how to program the hybrid mode?

jacobhurwitz
26-01-2008, 14:44
ok, thanks. now i have another question. is there a manual or a guide that teaches you how to program the hybrid mode?

http://www.chiefdelphi.com/media/papers/1590

It says autonomous mode, but hybrid is the same thing (just with IR inputs).

Guardrail
25-02-2008, 15:17
I am new to C programming, and I was wondering if it is possible to program to buttons instead of joystick. I learned a lot in the short time I was programming and i hope to learn more.

SL8
25-02-2008, 15:30
I am new to C programming, and I was wondering if it is possible to program to buttons instead of joystick. I learned a lot in the short time I was programming and i hope to learn more.
What environment are you using? Regardless, it would depend on what kind of input the button causes to tell you the actual code.

JamesBrown
25-02-2008, 15:41
I am new to C programming, and I was wondering if it is possible to program to buttons instead of joystick. I learned a lot in the short time I was programming and i hope to learn more.

Hey, you can absolutely us buttons instead of joysticks. If you want help with the code you are going to have to be a little more specific about how you want it to work.

Guardrail
25-02-2008, 15:51
Well the claw is sopposed to pick up pvc rings, the strategy we used is the claw goes in the middle of the ring and opens up to put pressure on the sides of the ring to pick it up. The problem is, I dont know how to make a code to use the buttons instead of joysticks to make that happen. ( it is a 2 pronged gripper that opens and closes using a servo module)

Mark McLeod
25-02-2008, 15:54
Is this for the VEX platform?
And do you want to use the buttons on the back of the VEX transmitter?

Guardrail
25-02-2008, 16:07
Yes this is ofr the VEX platform and I would like to use the buttons of the back of the transmitter

Mark McLeod
25-02-2008, 16:26
If you are using EasyC what version are you using? V2, EasyC Pro?
The function calls are different between the versions.

If you are using MPLAB to program, the default VEX code has an example of using the buttons. The following is a variation on that. The two buttons on one side are seen in the code as PWM_in5 and the two buttons on the other side arrive as PWM_in6. This code starts the claw in the middle (joystick rest) and moves it to one extreme when the down button is pushed and the other way when the up button is pushed. It holds the last position after a button is pressed.

// Claw servo
#define BUTTON_REV_THRESH 100
#define BUTTON_FWD_THRESH 154

// Servo values for open and closed positions
#define CLAW_OPEN 200
#define CLAW_CLOSED 10

if (PWM_in5 < BUTTON_REV_THRESH)
{
pwm05 = CLAW_CLOSED; //The down button moves the servo plugged into PWM 5 one way
}
else if (PWM_in5 > BUTTON_FWD_THRESH)
{
pwm05 = CLAW_OPEN; //The up button moves the servo plugged into PWM 5 the other way
}

The values 10 and 200 would be replaced with the proper position on your particular servo. You can use a printf and the existing joystick setup to find out what servo value on the claw is open and what value is closed. The servo positions range from 0 at one extreme to 254 at the other. To avoid overstressing your servo only use the value you figure out that you need to hold the game piece.

hipsterjr
06-03-2008, 22:42
Q: What is the main difference between robotc and MPLAB? We have used MPLAB in the past but I thought I'd try robotc on our new programing computer.

hipsterjr
05-08-2008, 21:50
Q. Using MPLAB, I keep getting:
user_routines.c:128:Error [1105] symbol 'ADC_16ANA' has not been defined

I get this error with some of our older code and the 2007 FRC default code I'm changing.

I thought it was defined in ifi_aliases.h:
#define SIXTEEN_ANALOG ADC_16ANA /* All analog */

and yes, it is included in user_routines.c
yet it still reads "undefined"

anyone have a fix for this?

Pat Fairbank
05-08-2008, 22:49
Actually, #define SIXTEEN_ANALOG ADC_16ANA /* All analog */ assigns SIXTEEN_ANALOG_ADC the value of ADC_16ANA, not the other way arround. ADC_16ANA itself is defined in [your mcc18 folder]\h\adc.h.

I have #include <adc.h> on line 18 of my ifi_aliases.h. Make sure you have it too, and that the file exists in your mcc18 tree.

hipsterjr
13-08-2008, 15:16
MCC 18/h/adc exist and I have

#include <adc.h> on line 18 of ifi_aliases.h.

But I still get user_routines.c:128:Error [1105] symbol 'ADC_16ANA' has not been defined

what else could it be?

edit: I'm using MPLAB C18 v3.16

Joe Ross
13-08-2008, 15:51
MCC 18/h/adc exist and I have

on line 18 of ifi_aliases.h.

But I still get

what else could it be?

What compiler version are you using?