Let's Make Robots!

Tips for making a robot multi-task

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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

C on an Atmega is (in my humble opinion) even better, since you can use timers, interrupts and other magical stuff to make your robot "multitask".

I find it that BASIC in almost any form make me want to shower, but each to his own I guess.

The Arduino language(Based on Wiring) is a simplified version of C++, sort of. It's very simple to learn, I think that it's well worth the time to learn it. I haven't tried out ZBasic though, may it has some nifty features that I'm not aware of.

Computers have multitasked long before multicore chips arrived on the scene. Because they operate so fast it is just a matter of time management or "scheduling" as they say, to make the chip appear it is doing multple tasks simultaneously.

There are a number of ways to implement this but there is an interesting and simple method here with an avr. You could use an extra chip or 2 but I wonder whether this really simplifies things any further as you then need to add communications code when you could just use the space to write interrupt service routines and timer code.

I have been working with the multitasking in ZBasic and it is VERY stable and easy to work with (and it's fully preemptive). Using hardware PWM to drive servos and they don't 'glitch' at all with the multitasking. I am quite pleased and I think anyone would be if they would just give it a try.

Now put that in a 40 pin dip package, equally as fast, and charge $59.95 and you have a controller really worth exploring. (Its called the ZX-24su and is made by a ZBasic "helper" company named Oak Micro.)

With the programming being very easy, one can devote more time to some serious AI. That is what I am going to TRY to do.

I have heard rumor that an effort is being made to translate ZBasic to run on a PROPELLER!!! If that can be done (it sounds really hard) I couldn't resist finally buying a Propeller! (I think it would be on a board with an external memory for the ZBasic native boot code). If they do it right they won't put a VM - Virtal Machine on the chip but have ZBasic compile down to Propeller machine code. That could be incredibaly fast if done properly. I don't think they could keep them in stock! :-)

Don't expect ZBasic for the Propeller to be out any time soon... The "team" that is working on it is one person and he sounds like he doing it in his spare time as part of his hobby.

I myself see huge problems from both the Parallax and ZBasic companies. Who owns the thing ? What about licencing it?

IF he is doing so it as a Basic that runs somewhat like ZBasic (gets just the most important features running) without using any of the ZBasic originally engineered code, it may make for a awesome Open Source project! If it ran well (not even perfectly) I would be willing to buy a Propeller and help with finding bugs, I think it would be a really worthy effort, and then I would never have to think about learning Spin again! Yes, I hate Spin that much! :-)