Hey.
I’m new to the forums and new to programming. Our lead/only programmer isn’t going to be with us this year and I’m trying to figure stuff out using the eduBot. Our team had no auton code last year so I’ve got no experience with it. I’m curious, where is it inserted in the default c-code? How is it controlled? If you use a dead reckoning system is everything just timed with for/while loops? I’d love to see some basic examples of dead reckoning/sensor driven autonomous code.
peace.
bill rosemurgy
team857
superior roboworks
At the moment, IFI is not providing any autonomous code. I would suggest you do a few things to make up for the lack of this…
The short answer: RTFM(s)!
The long answer:
a) Get yourself a book on C. very useful.
b) Print out the 366 page datasheet on the PIC18Fxx20 (availible from MicroChip). Then, sit down and read all of it. Yes, I know… you won’t ever use 90% of it. Most likely, you won’t understand 95% of it either. BUT… you might understand a lil bit. And the more you know the better…
c) Scour the delphi forums… especially the archived stuff from last year. Even though the comments are for PBASIC, the same principles still apply.
d) Don’t ask generalized questions… you most likely won’t get them answered. Be specific. I think this applies to any online forum really…
These are complicated issues, and there’s really no simple answer. I can tell you for sure that reading the specs on the PIC will be about as useful as reading those of the BS2sx (ie not very). Those datasheets are intended for use by people like InnovationFirst who do the actually embedded development. What you should read, however, is http://www.innovationfirst.com/FIRSTRobotics/pdfs/2004_Programming_Reference_Guide_10-29-2003.pdf.
Pretty much all of your code should go where is says “Add your own code here” in user_routines.c. The Process_Data_From_Master_uP() function is called everytime the RC has new data, so you can think of it as being just like the old PBASIC code that was between the SERIN and SEROUT (if this analogy doesn’t help, just ignore it). Once you’re comfortable with that, you should look at the Process_Data_From_Local_IO() routine and see if it fits your purposes any better.
You probably won’t be using any for/while loops to do the timing, but will instead be doing some small bit of work each time the Process_Data_From_Master_uP() function gets called, much like autonomous code from last year.
As for actual example code, I unfortunately don’t have any. I can try to whip some up, but without an RC (my team no longer exists), I can’t really try it out.
Keep asking questions, and chances are someone around here will be able to answer.
I’ve done a small amount of programming in PBASIC but no auton. My reasoning is this: the autonomous code needs some sort of control feature (timing for a dead reckoner or sensors and a bunch of ‘if-statements’ for sensor driven). Is this correct? Thanks for the help so far. I haven’t yet but plan to spend some time in the archived forums.
Peace.
It looks like you have the right general idea. Basically, what you’re going to want to do is create a finite state machine to keep track of where in your autonomous program you are. In pseudocode, this would look something like:
auto_mode(){
static int state = 0;
updateState();
switch(state){
case 0:
//do something, like drive forward, or turn left, etc
break;
case 1:
//do a different something
break;
case 2:
//dito
break;
...etc...etc
}
}
The key here is the updateState() part. Each time through the program loop, you’ll want to check and see if some condition has been met that will make you want to change states. For example, let’s say state 0 corresponds to driving forward, and you want to keep doing that until rc_sw1 gets triggered. You could then do something like this:
if(state == 0 && rc_sw1 == 1)
state++;
Then, you could make state 1 turn left (or anything else) for some number of seconds by doing something like:
if(state == 1 && (currLoopCount - startLoopCount) >= 20)
state++;
The easiest way to time is by counting how many times process_data_from_master_up() has been called, as it is called once every 17ms for the eduRC (it’s something like 24ms for the full RC, but I don’t remember exactly). You could do this with a global variable called currLoopCount that gets incremented at the start of every process_data_from_master_up() call, and then a static variable called startLoopCount inside your autonomous function that gets set to currLoopCount every time you transition from one state to another. Thus, currLoopCount - startLoopCount will give you the number of loops that you’ve been in the current state.
I’m sure that was about as clear as mud, so please feel free to ask questions about it and I’d be happy to answer.
Actually that is about as clear as anything that is really clear.
I think I’ve finally got a good idea of how this thing works.
this rocks.
You might be interested in this thread. The clock demo code can easilly be extended to create what you’re looking for (see the comments in clockdemo.c). Let me know if you have any questions.
-Kevin
Hi guys,
Ummm… what do you suggest for newbies such as myself?? I’m from a rookie team, and we are completely lost when it comes to programming. I’ve read the 2004 programming guide, printed out an EduCode demo, but I am still completely lost. I suppose that’s what you get when you sit down to look all this over by yourself and have no experience whatsoever… at least when you’re me .
Thanks a bunch,
~Vienny
Think of a light switch, it either emits light or it doesn’t. That’s how programming digital outputs are. You can turn a light switch on by flipping it up lets say, right? Now lets give the on position (state) of the light the value 1, and when it’s off its zero.
rc_dig_out01
rc_dig_out02
rc_dig_out03…
rc_dig_out16 are all variables that act like these switch, but if you are going to use one of these, you must set the corresponding IO pin to Input or output
to use rc_dig_out01
do
IO(x) : x (pin)
IO1= OUTPUT; // so you can OUTPUT data using rc_dig_out01
Remember to put OUTPUT/INPUT declarations in the initialization or whereever all of the OTHER similar statements are.
void Process_Data_From_Master_uP(void)
{
Getdata(&rxdata); /* Get fresh data from the master microprocessor. /
/… then somewhere in here you can do check statements and set statements */
rc_dig_out01 = 1; // This will turn on output 1,
Putdata(&txdata);
}
// To use this on the actual controller, there are three pins, you would simply hook up a LED (it’s a diode so it only goes one way remember) to ground and signal, that would turn on an LED. If your utterly confused, this should help a little, if you can get this working then read some sample code, that’s always a good way to go.
GPS (Ground Positive Signal)
1XoX
2ooo
3ooo
Vienny,
Check out the FIRST web site and lookup the other teams in your area. There are several in the Houston area. Contact them and asked if they will menotor your team in the programming area. All of the FIRST teams are very helpful to rookie teams.
Good luck,
Tim Tedrow
I am also from a rookie team, but I have had experience in Java so C is not as hard to understand. One thing you need to do is read the comments and reread them until you understand them or they are etched in you memory forever. Then the ones you still don’t understand look up in a C programming book. Also, if you want, I am from Sterling HighSchool in the Houston area. You could come to one of our meetings if you wanted to see some programming and how it is done PM me and I will tell you how to get there.
Argoth
P.S. Print out the poster of the user routines, it tells you what all can be modified and its colorcoded for dummies like me!!!
If you want many examples of different types of autonomous code, there are some here: http://www.rec.ri.cmu.edu/education/edubot/2004_content/index.htm
They also have general explanations of everything in the programming system, and how to use them.
–Damian Manda