IR board code

I’m am the programmer for team 1691 and I’m am currently working on programming the ir board. I think that the sort of thing that i want to do is have one button coorespond with just going around the track, one for knocking the trackball off of the left spot, one for knocking it off of the middle, and the last for knocking it off of the right spot. i was wondering if any one out that has done something along these lines could send me a sample of their program?
as you know the ship date is on tuesday, so the sooner you can respond the better off i will be.

Thank you for any help you can bring to the table.

just do
if((pick the digital io you want)==1)
// add code here

Actually, that will always run as the IR returns 1 unless the signal matches. You will need to have an equivalency check with 0, and probably code to avoid running without the IR connected. I’ll post an example once I get back to my code…

As for the actual autonomous mode… Are you basically looking for a complete code to base yours off or something specific you need an example of? If you’re looking for something in general, I can post an example of our team’s state machine stuff… Once again when I get the laptop back.

That is pretty much what i was thinking. we are short on time and we have one way or another fried our ir board, so we are making a code in hopes of getting it fixed with the help of other teams at our regional.

If the IR board’s gone, then that would significantly change the strategy… Maybe you’ll be able to purchase another before the actual regional, so in case you get one working, this is what we used for the IR board:

// IR Inputs
#define IR_DIG_1 		rc_dig_in04
#define IR_DIG_2 		rc_dig_in05
#define IR_DIG_3 		rc_dig_in06
#define IR_DIG_4 		rc_dig_in07
#define IR_DISCONNECTED	(IR_DIG_1 && IR_DIG_2 && IR_DIG_3 && IR_DIG_4)
#define IR_1 		(IR_DIG_1 && !IR_DISCONNECTED)
#define IR_2 		(IR_DIG_2 && !IR_DISCONNECTED)
#define IR_3 		(IR_DIG_3 && !IR_DISCONNECTED)
#define IR_4 		(IR_DIG_4 && !IR_DISCONNECTED)

That way the you can use if (IR_1) or the like to use your routines. If you want each to run a seperate routine, you’re better off setting a variable and then using a switch, something like this:

	static int routine = 0;
	switch (routine){
		case (1):
		case (2):
		case (3):
		case (4):

Even if you don’t get your IR board functional, you can still try a state machine sort of thing. You can get fancy with this sort of thing as well. You’d start by breaking whatever you want to do into a typedef, which looks something like this:

typedef enum{
} auto_state;

In case you’re not familiar with enumeration, this will make AUTO_DRIVE_1 a macro of 0, AUTO_TURN a macro of 1, etc. That way you can reference a switch statement with it. This would be the bulk of your case state machine:

usigned char do_half_lap (void){
    static unsigned char current_state = 0; //This is the current progress
    switch (current_state){
        case (AUTO_DRIVE_1):
        current_state += drive_x_dist(100);
        case (AUTO_TURN):
        current_state += turn_90_degrees();
        case (AUTO_DRIVE_2):
        current_state += drive_x_dist(50);
        case (AUTO_COMPLETE):
        return 1;
return 0;

All of the example functions would return an unsigned char, 1 or 0, based on completeness, like do_half_lap. This means the state is getting pushed up to the next level each time one of the steps is complete. Of course, this means you need to make the subfunctions. If you want, these can be state machines as well!

I’ll leave the subfunction implementation code up to you; but it should be pretty easy. Let me know if any of this is too complicated. Keep in mind these are all samples and haven’t been tested. I advise not copy/pasting anything and writing your own with this as a reference.