I have been told that there are a number of students who need some help programming their robots. While I can not explain everything there is to know about C programming, I will attempt to explain some of the general ideas that you will need to program your robots and get them moving. The first goal that everyone should be working on right now can be considered "driver software." For example, if you have a drive motor on your robot, you want to have a function such as: motor(int SIDE, int SPEED); //A function to move your motors Where SIDE is an interger indicating which side (ie, LEFT or RIGHT) you want to move, and SPEED is an integer that tells it how fast to go. I know some of you may be saying ,"But we already have this from Doty's code..." Well, I didn't write the code so I don't know how it all works. There is a possibility that you can make a change to something and none of you code will work. It will be hard to debug because, like I said, I did't write it. I suggest that you write ALL of you own code so you know how to fix it if it ever breaks (and it WILL break). Back to the driver stuff... So, for those of you with any type of actuator, and you all have them, you need to think about how you can control it. Like mentioned above, if you have 2 drive motors on your robot, how would you want to control them in software? Well, you want a function like I just mentioned. For those of you that have stepper motors, you will want a function such as: motor_step(int MOTOR, int NUM_STEPS);//function to move a motor a specified number of degrees Where MOTOR is an index as to which stepper motor you want to drive(IF you have more than one) and NUM_STEPS is the number of steps to move. Also, for those of you that are using non-hacked servos, you will want a function that will allow your servos to move to a specified position: move_servo(int SERVO, int POSITION));//function to move a servo to a desired position Where SERVO is an index indicating which servo to move, and POSITION tells the servo where to go. As for sensors, you will want a function that will allow you to get usefull information. If you have one of the $10 black distance sensors, you should write a function like this: get_distance(int SENSOR);//Gets the distance in inches for the specified sensor So you would pass it an integer indicating which sensor you want to read from. I am sure most of you still are not sure how to write the above mentioned functions (if you do I apologize). I will attempt to explain... I have attached a small program that has a lot of examples. ////////////////////////////////////////////// //Program: imdl.c // //Description: Examples of interrupt service// // routines. This code displays// // a menu asking for a percent // // duty cycle. It then outputs // // PWM signals on OC2 and OC3. // //Programmer: Scott Nortman // //Date: October, 2001 // ////////////////////////////////////////////// #include //Standard includes #include #include extern void _start(void); //This MUST be placed here RIGHT after the includes, it is for the reset vector #define DUMMY_ENTRY (void (*)(void))0xFFFF //This is a void function declaration for the interrupt vector table #define PERIOD 30000 //User defines #pragma interrupt_handler TOC2_isr, TOC3_isr; //This is where interrupt service routines are specified void init_pwm(void); //Function Prototypes void TOC2_isr(void); void TOC3_isr(void); int duty2; //Global variables int duty3; void main (void){ //Beginning of main routine char clear[]= "\x1b\x5B\x32\x4A\x04"; init_pwm(); duty2 = 0; duty3 = 0; while(1){ printf("%s", clear); printf("What duty cycle do you want for TOC2?\n"); duty2 = (getchar() & 0x0F); duty2 *= 10; printf("What duty cycle do you want for TOC3?\n"); duty3 = (getchar() & 0x0F); duty3 *= 10; }//End while(1) }//End main void init_pwm(void){ //Initialization function INTR_OFF(); //Turns off interrupts SET_BIT(TMSK1, 0x40); //Set up TOC SET_BIT(TCTL1, 0x80); CLEAR_BIT(TCTL1, 0x40); SET_BIT(TMSK1, 0x20); //Set up TOC SET_BIT(TCTL1, 0x10); CLEAR_BIT(TCTL1, 0x20); INTR_ON(); }//End init_pwm void TOC2_isr(void){ //This is the interrupt service routine int temp = 0; CLEAR_FLAG(TFLG1, 0x40); temp = (duty2 / 100.0) * PERIOD; if(temp < 500){ CLEAR_BIT(TCTL1, 0x40); SET_BIT(CFORC, 0x40); } else if(temp > (PERIOD - 500)){ SET_BIT(TCTL1, 0x40); SET_BIT(CFORC, 0x40); } else if(TCTL1 & 0x40){ CLEAR_BIT(TCTL1, 0x40); TOC2 += temp; } else { SET_BIT(TCTL1, 0x40); TOC2 += (PERIOD - temp); } }//End TOC2 void TOC3_isr(void){ //I didn't finish this function } #pragma abs_address:0xffd6 /* change the above address if your vector starts elsewhere */ void (*interrupt_vectors[])(void) = { DUMMY_ENTRY, /* SCI, RS232 protocol */ DUMMY_ENTRY, /* SPI, high speed synchronous serial*/ DUMMY_ENTRY, /* Pulse accumulator input edge */ DUMMY_ENTRY, /* Pulse accumulator overflow */ DUMMY_ENTRY, /* Timer overflow */ DUMMY_ENTRY, /* TOC5 */ DUMMY_ENTRY, /* TOC4 */ TOC3_isr, /* TOC3 */ TOC2_isr, /* TOC2 */ DUMMY_ENTRY, /* TOC1 */ DUMMY_ENTRY, /* TIC3 */ DUMMY_ENTRY, /* TIC2 */ DUMMY_ENTRY, /* TIC1 */ DUMMY_ENTRY, /* RTI */ DUMMY_ENTRY, /* IRQ */ DUMMY_ENTRY, /* XIRQ */ DUMMY_ENTRY, /* SWI */ DUMMY_ENTRY, /* ILLOP */ DUMMY_ENTRY, /* COP */ DUMMY_ENTRY, /* CLMON */ _start /* RESET */ }; #pragma end_abs_address If you have questions, PLEASE SEE ME IN LAB!!!!! I am here to help!!!!! ************************************************* Scott Nortman Teaching Assistant Machine Intelligence Lab University of Florida (352) 846-3993 *************************************************