Author Topic: Best method for multiple tasks?  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

Offline Ro-Bot-XTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Best method for multiple tasks?
« on: January 13, 2008, 06:07:03 AM »
I have some questions for the software gurus.

What is the best way to do all of the following tasks:
- count encoders without missing a step
- PID controll
- calculate acceleration and deceleration for smooth movement
- calculate position based on encoders count (distance travelled)
- read distance sensors
- calculate position based on distance measurements (triangulation)
- update map
- process image data to find the target
- calculate the destination target
- monitor battery level
- other decision tasks

1. The easier way to do it will be using a multitasking language.
2. Another approach would be to use several microcontrollers and divide the tasks.
3. The usual approach, that uses only one MCU, and uses a complicated timed scheme to do these tasks, perhaps using interrups.

I have worked with NQC to program the Lego RCX brick. Easy to work with, able to set up 10 parallel tasks, start and stop any task at any moment, 32 global variables, some (don't remember the number) local variables... But I didn't find anything similar for PIC or AVR. There is RTOS but it seems too complicated.

I have read a few tutorials on using interrupts, but all at a verry simple level, like say for encoders. Ok, using that, I can make a motor controller module. But how is it possible to do all in one MCU and keep track of each task so that they will not slow down the others, to keep the timing good?  I am willing to divide the total processing speed of say 16MHz to the say 8 tasks. That will be 2MHz for each task. How can I calculate all the timings to run in each task in it's own 2MHz slice?

Can someone point me to some documentation and samples on how to do something like this? Or to write some sample code I can further develop to my needs? I just don't know enough programming to do it on my own...

Thanks in advance.
Check out the uBotino robot controller!

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Best method for multiple tasks?
« Reply #1 on: January 13, 2008, 03:04:49 PM »
there is a new tutorial at http://www.microchipc.com which is showing how to use a simple threading interface with C. You can set priorities etc... so 1 task can operate at 2mhz and another at 4mhz etc... (if you set it up right)

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Best method for multiple tasks?
« Reply #2 on: January 13, 2008, 06:52:37 PM »
yes you can as long as you use differential frequences ;D anyway good luck hope it works out.
Howdy

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: Best method for multiple tasks?
« Reply #3 on: January 13, 2008, 08:59:06 PM »
Here's how I got started: http://www.freertos.org/

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 638
  • Helpful? 0
  • It's called the future ... We like it here
Re: Best method for multiple tasks?
« Reply #4 on: January 14, 2008, 07:45:11 AM »
is it possible to program this (everything Ro-Bot-X said) in C++ and program it on a PIC ?
What compiler should I use ?
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Best method for multiple tasks?
« Reply #5 on: January 14, 2008, 10:04:06 AM »
you could do most of it...... although very slowly

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 638
  • Helpful? 0
  • It's called the future ... We like it here
Re: Best method for multiple tasks?
« Reply #6 on: January 14, 2008, 02:59:31 PM »
you could do most of it...... although very slowly

So I better don't use it?
I know Java pretty thoroughly, C++ superficial (but I could learn it very fast, because of it's similarity to Java). And that's about it :/

Is C the most powerfull language for these tasks?
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: Best method for multiple tasks?
« Reply #7 on: January 14, 2008, 03:19:22 PM »
Its not how powerful the language is but how powerful the processor is.

The process of slam (map updating and calculating position) aswell as image processing would make the most up to date pc struggle let alone a little thing like a PIC.

I'm not saying that it isnt possible to do slam with PIC's (because I intend to try myself), but you would have to find a different way of solving the problem in software.

As to the choice of language, C is probably the most useful because it is at a semi high level but you can easily use assembly where necessarry and feel a bit closer to the hardware that you are working on (if you can do java/c++ then you can do C without a problem).

C++ is probably a bit too high level and c++ compilers for mcu's arent as common.

There are a few mcu's now that run a java platform, I use java quite often these days on pc's, but my personal opinion is that it is far too high level for mcu's- infact requiring a standardised pre-compiled class file and then platform dependant on the fly compilers to actually run the intermediary class file.(means you actually lose a lot of time cycles while the intermediary file compiles on the fly and then runs)

C is a simple language without all the flying bells, why use c++ when you dont need and wont use the flying bells on a PIC

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 638
  • Helpful? 0
  • It's called the future ... We like it here
Re: Best method for multiple tasks?
« Reply #8 on: January 14, 2008, 03:54:29 PM »
Thanks for clarifying that for me!

For people searching the forum with the same question as me:
c++ vs C
Java c++ better C best
meh... that should be enough search terms :p
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

Offline Asellith

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: Best method for multiple tasks?
« Reply #9 on: January 15, 2008, 04:38:15 PM »
http://www.embedded.com/design/multicore/204300364?_requestid=7397

This might interest some people here. I found this before Christmas and was about to post it when the forum went down. I just found it again today. It talks about multitasking with a pic. Interesting article don't miss the discussion at the bottom and part 2. Enjoy
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Best method for multiple tasks?
« Reply #10 on: January 24, 2008, 02:33:56 PM »
To take the other position, I'll offer suggestions on methods to solve this in hardware . . .

Quote
- count encoders without missing a step
- calculate position based on encoders count (distance travelled)
counter IC, with output being read by mcu only when needed. simple logic counting IC's can do all this.

Quote
- PID controll
- calculate acceleration and deceleration for smooth movement
add shocks to your robot, lower the mass, add power suppression capacitors near batteries, do regenerative breaking, etc. so that your control system can be less accurate (requires less processing time) without doing harm to the robot durning jerky movements. Who needs PID if your robot can stop on a dime without falling apart? :P

Quote
- process image data to find the target
Get CMUcam/AVRcam to do it for you. Camera vision is highly processor intensive so only use a dedicated processor for this . . .

Quote
- monitor battery level
just a quick 50us ADC reading . . .

 


Get Your Ad Here