Tips for making a robot multi-task
June 14, 2010
I have a robot, and my robot has a brain. However, my robot's brain can only think about one thing at a time. I can set I/O pins high or low, and they will stay there until I change them, but that isn't going to work. Here's the deal:
- I have an OOPIC with firmware version B.3.something+ (whatever the newest is)
- The OOPIC is a 40-pin pic with custom firmware. It is a development board
- It can be programmed in C, Visual Basic, Or Java
- It only does one thing at a time due to the nature of those programming languages (I use visual basic)
- I need to proccess 3-5 things at once
My robot has a light-bar with 8 LEDs that I want to scroll back and forth like KITT. I could use a decade counter for this, but I want the rate and sequence to change based on the robot's activity. This is something that needs to run in the background.
My robot has two tank tread and a turret to control. The driving can be done with one proccess.
My robot has sensors and outputs to manage (ultrasonic, infrared, bumpers, speakers, etc.)
My robot has an LCD that needs to display its mode, speed, activity, etc.
So here is my problem: I need to do all of this at once. The KITT LED bar thing needs to be constantly going, the sensors need to be constantly sensing, and the drivetrain needs to be responding accordingly, etc. Each of these bits are super-easy to program because of the object-oriented programming environment with a few lines of code. The only problem is that it is a PIC, and it only executes one line of code at a time. Now, taking in mind that this is after all, just a PIC with some shiny firmware, how can I make it run multiple lines of code simultaneously? I can't have it sense, then drive, then update LCD, then stop and do the KITT LED Thing, then drive again, then beep, etc. I am not familiar with programming in C, but the logic still applies. So if you know anything about making a robot do multiple things at once, please leave a comment.
P.S. - If this seems badly worded/typed/confusing, well I typed it late at night and I can't think perfectly straight.