reprogram during a competition

At the risk of poking at a delicate subject – could the robot legally reprogram itself during a competition?

With a normal match the UI and the RC are in constant communication, but until the 15 sec autonomous mode is up, none of the joystick inputs (read – any input that operators can control) are active. As we have covered in other threads, a switch set before the match started could be detected by the robot before the controls were nulled. However it is blatantly wrong to have the robot be reprogram itself based on, say, at the location of the vision tetras: although theoretically possible with a 16F84, a flash card, and some clever coding and a 6 way switch.

My question pertains to reprogramming of the robot, by the robot, at the end of the 15 second autonomous period. My team has had problems with limited memory of the PIC, and with camera tracking and accelerometer algorithms we are close to the maximum size, without any of the operator-assist code.

Consider this example: When the 15 seconds of self control time is up, the autonomous flag is cleared; the RC pulls a digital output high. A carefully programmed microcontroller would emulate the serial port of a PC, putting the RC into boot loader mode and handing it the second set of code from an external EEPROM or “flash drive”. After the 1.5 or so seconds that the process takes, the robot is reset with its new code and on its way for the 2 minutes of user control.

anyone have any comments? does this violates any FIRST rules?
Thanks – jsd

I am not a programmer but could you explain why you would need to do that after Auto mode is over the robot is in driver mode and the only programing that you would need is what is need to run from the controller to the robot, right?

Just remember that i am not a programmer, I would just like to know why that would be needed. so please be nice if I sound really dumb.

I would suggest a much simpler way of achieving the same results: optimize your code. It’s free, and much less likely to malfunction. I truely doubt that you actually are going to run out of memory, but if you do, come up with creative ways of doing things. Use fewer variables. For example, if you were trying to swap two variables, instead of doing:

int c;
c=a;
a=b;
b=c;

…do:

a+=b;
b=a-b;
a-=b;

The first law of programming is that there are always ways of doing things quicker and in less space than you already are. (The ternary operator will be your friend in this pursuit.) Everyone is going to face the same problems that you are, and I doubt that anyone is going to absolutely need one of these devices. Good luck.

I think what you’re trying to say that the driver code is not complex, or long, because it just takes the values from the joystick and sends them to the Victors.

Our driver code is both complex and long, and we go over it hours at a time trying to make it shorter, and it’s still huge. We use sensors to measure rotation and two direction acceleration, and make changes to the motor outputs based on where the robot is and where the operator wants the robot to be. And all of the arm controls, limits, etc take up space too.

The memory on the RC is limited to start with (a couple of KB). It doesn’t help that the chip was designed to run assembly and we compile C++ to it… C is a complicated high level language that uses lots of libraries that take space. Then IFs “default” code is a beast (its got to be compatible with every team), but you cant ditch it because they wont give you total control over the RC (it’s a boot loader, ugg). And some of our programming team members write crummy code. All and all, memory is precious, and the more the better.

I hope this answers your question, jsd

We work only on code every day for 6 weeks… we can do 80% of stuff with out a second program

I’m sorry if you doubt it, but I have run out of memory, and its not fun. Actually the first time it happened was in the pits, but I was writing sloppy code, so it is expected.

Incase it wasn’t clear – This was a theoretical question; the probability that I would implement it is very low. But when my team comes up with another page of stuff the robot is suppose to do by itself; I at least need a worst case scenario

Thanks though – jsd

I believe your effort would be much better spent optimizing your code to make it smaller as others suggested. There is a lot you can legally and safely strip out of the default code. Additionally, once you have your code debugged and in a stable stage, you can start rewriting stuff to sacrifice manageability and “good” programming practice for smaller size.

BTW, we are programming in C, not C++ and every robots code that I have seen uses very few extra libraries.

Bah, and here I tried to provide a practical answer.

Look at the Additional Parts flowchart in section 5 of the manual to determine if this device is legal or not. If you don’t get a satisfactory answer, try the FIRST Q&A.

One more note on the practicality of this: maybe our programming computer is different from yours (1.8GHz seems like enough), but it takes a bit longer than 1.5 seconds for me to send code to the RC with IFI Loader.

Ok now please bear with me, im a rookie programmer, but why would the above example save any memory space on the actual robot controller? when you build it, it just makes it assembly language (the .hex file), and both those (above) are the same. thats the whole goal.

in order to save memory, my team is using #define s for as much as possible, so when you compile/build it, as much as possible is already done. also, the same for some of the autonomous calculations–look up tables are faster and smaller than calculating something. (especially for trig functions, which you might need for autonomous–distance).
:confused:
plz tell me if im horribly wrong or something…
thanks,
~Stephanie

If you need a sufficiently small number of values, table lookup will
save space. It just depends on how many you need. In the general
case, an algorithm will save space and table lookup will optimize for speed.

The use of #define will not necessarily save space (except in your
source files, where you don’t care). It depends on how you are doing things.
To save space with constants, you want every reference to the value of the
constant to be to the same memory location. If you just use the define, you
will be storing the constant value everywhere it is used.

I might be totally missing something, but like jgannon says it takes (me at least) way more than 1.5 seconds to download a program to the RC. More like 1.5 minutes. And why dont you simply do the processing on something else (how much does a 386 cost?) and just use the RC for I/O?

Jacob,

At the risk of sounding condescending, I can’t believe that anyone is running out of space. If so, take a good hard look at what you are doing.

Programming an embedded system is absolutely nothing like programming a PC.

First rule: Never, never, ever use floating point arithmetic.

Second rule: Never, ever use dynamic allocation of memory.

Third: Avoid pointer manipulations unless you understand what it does in the machine (some dereferencing manipulations are murder).

Look at the assembly code being generated by the compiler. You can see it in the .lst file that is generated when you build your project.
Good Luck,

He brings up a very good point. I believe that in 2003 the Wildstang 111 robot had a Motorola processor on it to do all of the calculations and processing, and the RC itself would be used for only a little bit of the program and the I/O. Go to the Wildstang website and click on “Stang PS” for a bit more information.

Significant processing between operator input and motor action.
Navigation (and all the trigonometry it requires).
Multiple independently-tuned PID controls.
Adaptive autonomy.

Finally, lots and lots of text for communicating with the camera.

I can easily understand someone running out of space. Last year’s robot only did about half of what we have planned for this year, and it’s using about 65 percent of the space.

I have to agree with Alan that if you try to dump everything possible this year into the program it can grow large.
Maybe not what you are looking for, but have you tried using the built-in compiler optimization to reduce your program bulk?

In MPLAB

  • Project -> Build Options… -> Project
  • MPLAB C18 tab
  • pulldown categories and select Optimization
  • click “enable all”

I tend not to use the compiler optimization unless necessary, because we’ve all had problems with optmizers in the past. Just test afterwards to make sure everything is working properly.

You have gotten rid of the IFI printf code, right?

There are only about 1300 bytes (1200? I forget the exact number.) of variable space available to the user. My first example requires three ints, for a total of six bytes. The second example requires two ints, for a total of four bytes. I understand that variable allocation is not the only concern with respect to memory, but teams will discover that if they start wildly instantiating global variables, they’ll start getting a lot of weird compiler errors, indicating that they’ve run out of space.

Faster, maybe, but definitely not smaller. I’ve been seeing all of these lookup tables that teams are using for desensitizing their joysticks, when all they really need is a simple quadratic equation, which I’m certain will take up significantly less space on the bot.

Hm… no I haven’t. I didn’t even know that existed. That may very well come in handy for all of us. Thanks.

im sorry if you misunderstood my question. i was wondering if reprograming the robot was legal durring the compitition.

again, thanks – ive been programming MCUs since i was 9 and got my first BOE-BOT kit… 7 years later i think i can tell the difference between a IBM platform PC and a PIC microprocessor :wink:

i don’t like the thought of using chars, ints are pushing it…

external EEPROM is better then internal memory if you want to map data, but i generally use algorithms anyway (DMA isnt my cup of tea)

this i most hardly agree with

I used to write assembly for fun, thank you very much - thus my habits of not using as few IFs as possible; i much prefer boolean algebra.

Im not a “newbie” programmer, ive have been the head of our programming team since my freshman year. I have taken collage level CS in JAVA and C, as well as many, many courses on programming in just about every other modern high level language.

However, i have been doing this for a relatively short period of time – there are people that are much better at this then i will ever be, and many of them participate in FIRST. i never pretend to know everything, so i respect everyone on the forums, and assume they know more then me, and in turn I hope they respect me

also i try very hard to keep delphi threads to the point… but stuff like

is unnecessary. i am sorry that you dont believe me :frowning: , i never thought that i would have to take a screnie for something like that.

external processing is what our team has planned thus far. and i will be sure to try Marks optimization process… i wasnt looking for a lecture on how to optimize code (read the thread title!) i was looking for the legal implications of reprogramming the robot during a match. Thanks anyway – jsd

With all the text strings and all the interrupts and associated volatile variables floating around in this year’s code, I wouldn’t expect a whole lot of extra optimization. It’s my guess that most “reduced bulk” will still have to come from effective algorithms and efficient implementations rather than compiler tricks.

Fortunately, I have something of a knack for efficient implementations. :]

Made me look.:slight_smile:

The default FRC 2.4 version of the code comes in at 18,927 bytes or 55%.
Optimizing gets you down to 14,743 bytes or 43%

Sorry for the thread hijack Jacob. Us old folks tend to ramble on sometimes.:wink:

I don’t know of any rule that prohibits the downloading of new code as long as it’s occurring within the custom circuit rules, and I can’t think of any harm that might do from a safety or IFI control perspective.

P.S. My wife was a warhawk. Just had a reunion in Vienna this past summer.

Can you explain this one a little more? I’m used to UNIX programming where I never have to worry about this being a problem, so we used pointers quite a bit last year and plan on the same this year.

You’ve very close. In 2003 & 2004 the Custom Circuit kept track of our position on the field and every loop of autonomous the RC would ask the CC for the robot’s position & heading. Then the RC would determine the path to get to the target, do the driving & arm moving, and recognize when we got to our target. The presentation on our site doesn’t show the interface between the RC & CC. For this year we’re planning to offload almost all of the positioning & guidance to the CC and have the RC focus on determining what to do based on the strategy, and vision tetra positions.

How do you guys connect the RC and the CC? If you used the ttl port then you are going to have to (actually you probably already did) find a way to hook two things to it at once assuming you are using the camera.

Back on topic however, It seems to be legal to reprogram in a match, but you might have a lot of explaining to do. The thing that will worry the judges the most is the possibility of you screwing with their master code. I would stay away from it for this reason, not to mention all of the reasons already mentioned. You are asking for trouble with both the technical and “legal” aspects of it, when it seems like you could accomplish something the same or better more easily, without the concerns over the rules. Thats just what I think.

thanks for the answer

as for

serial communication is over digital IO lines. you can copy IFIs buffers, or write your own. you end up with 16 some odd serial ports (of course, you need to make your own connectors)

the chip by itself runs TTL levels (+5v) for the signal. with serial comunication, most things will cope just fine with +5, (rs232 spec goes to +15v, but we would use +12v), but some things are just pickey. so if you want to be “fully” compatable with all devices, your going to need a RS232 converter chip. any electrionics provider will sell them… you can get 4 converters in one IC for a buck or two