Shop OBEX P1 Docs P2 Docs Learn Events
Newbie question on multitasking — Parallax Forums

Newbie question on multitasking

Jack OfallJack Ofall Posts: 2
edited 2010-11-02 09:10 in Robotics
Hi,
Thanks for taking time to read.
I bought Boe-bot kit last week
( http://www.parallax.com/Store/Robots/AllRobots/tabid/128/ProductID/302/List/1/Default.aspx?SortField=ProductName,ProductName)
and I started with the activities in the book 'Robotics with Boe-Bot. It is fun.
I thought of doing the following. I have 3 continuous rotational servos.
I want to run Servo1 for 60 seconds.
while it is running, I want to start servo2 and servo3 to run from 15 seconds to 25 seconds during the servos 60 second rotation.
Th examples I have worked with seems to be single task oriented.
I presume the problem I am solving is a multi-tasking.
Could someone point me or help me in the right direction of how I can accomplish the above task.

Thanks
-Jack

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-10-30 11:47
    There is no multi tasking with the Basic Stamps, it always can only do one thing at a time. You can still accomplish what you want though.

    Here is one way to do it;
    for i = 1 to 60
    
    for x = 1 to 50
     pulsout servo1, 1000
     if i > 14 AND i < 26 then
       pulsout servo2, 1000
       pulsout servo3, 1000
       pause 14
     else
       pause 18
     endif
    next
    
    next
    

    Rich H
  • Martin_HMartin_H Posts: 4,051
    edited 2010-10-30 11:56
    What you could do is write a player piano style program. Break the time up into segments say ten seconds long or so. For each segment determine which servos should be on or off and encode them as follows: 0 means all servos off, 1 means A servo on, 2 means servos A and B on, 3 means servos A, B, and C on.

    In your program you create an array of nibbles to hold these values. Your program consists of an outer loop which indexes though the array, and reads the value. The inner loop pulses the servos indicated in a loop for the amount of time in a segment. The program loops back to the array reading label.

    With coordinated arrays you can do things like have the time segments be variable, as well as the speed and direction of the servos.
  • Jack OfallJack Ofall Posts: 2
    edited 2010-10-31 19:19
    Thank you very much W9GFO, for the very neat idea and the simple example code. My Thanks also goes to Martin for what appears to be a complex solution for my simple head. I hope to read on arrays and see how Martin's idea will work.
    warm regards
    -Jack
  • AImanAIman Posts: 531
    edited 2010-10-31 19:52
    The other thing you can do is run an embedded loop. I will try to explain this in simple english because its not hard to due but can be confusing to read.

    Start your loop for the first servo and inside that loop set up a condition to trigger a second or third servo. So you are using your pause time from the first servo to trigger a second or third servo.

    It would look something like this -

    Start servo one loop
    Move servo one
    Move servo two
    Move servo three
    End loop

    You could do if statments, case statements, while statments or any number of statments to use the pause time in the loop of the first servo to get things to work.

    In short, the theory of what you showed in your code but by utulizing the pause times instead.

    Warning, if you put to much into the loop code it will slow down your servo speed.
  • Martin_HMartin_H Posts: 4,051
    edited 2010-11-01 17:11
    Jack, sorry if I wasn't clear as it is hard to tell how much detail to go into sometimes. In programming an array is a collection of values in an ordered sequence. You can select a value at any point in the sequence using its numeric index. By using a loop variable to get these values they can give your program a sequence of commands. In programming a byte is eight bits and can hold numbers up to 255. A nibble is half a byte and can hold values up to 15.

    If you think of a player piano or music box, there's a roll of paper or metal which moves past the reader. A value is encoded at that spot which the mechanism reads and this value either moves keys or tines. So the analogy is to think of the array like the paper and your servos like tines. The presence of a value can turn them on and off.

    So I was talking about was a program like the one attached. A more complex program could not only lookup the servos to activate, but their speed and direction. What you would have at that point is a data driven program where you can change behaviors by changes of data.

    Disclaimer, I wrote this to show what I mean and I haven't tested it.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-11-02 09:10
    You can run several servos at the same time using a Parallax ServoPal.

    http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/servopal/List/0/SortField/4/ProductID/481/Default.aspx

    In the case of Boe-Bot, one servo and two others on the ServoPal can run independently.

    The ServoPAL is a tiny module that plugs in between your BASIC Stamp and two servo motors to pulse the motors so your PBASIC program doesn't have to. In addition, it provides an “alarm clock” function to perform timing in the background while the BASIC Stamp is busy with other tasks.


    Features:
    • Plugs in between servo headers and servos: no wiring necessary.
    • Simplifies PBASIC programming for both standard and continuous-rotation servos.
    • Pulses two servos continuously based on single pulses received from the BASIC Stamp.
    • Provides an alarm output (200mS to 30 min delay), which can be set by a single pulse.
    • All interfacing is done by pulsing: no serial protocols to learn.
    • Runs from the servo's power (up to 6.5VDC): no additional power source needed.
    Key Specifications:
    • Power requirements: 5 to 6.5v
    • Communication: Pulsing
    • Dimensions: 3/4 x 3/4 x 3/16 in (20 x 20 x 5 mm)
    • Operating temp range: -32 to +158 °F (-0 to +70 °C)
    28824-M.jpg
Sign In or Register to comment.