Shop OBEX P1 Docs P2 Docs Learn Events
Multitasking Basic Stamp — Parallax Forums

Multitasking Basic Stamp

MrRedHairMrRedHair Posts: 9
edited 2012-06-15 12:01 in BASIC Stamp
Electronics, programming, and robotics is a hobby of mine that I enjoy. Recently, I made a program for my Boe-Bot that detects IR signals from an IR TV Remote using the rctime command, then, depending on the signal, moved or reacted however it was told. The program was successful but I did run into an inherent problem that goes with the basic stamp modules. They can only perform one task at a time. The stamp couldn't receive and analyze the signal at the same time as telling the servos what to do. I had to compromise with making movement subroutines that moved the servos for small set amounts of time, instead of my original idea of moving the bot while it received a signal from the IR TV remote. My question is: can you use a second stamp, stamp2, to look for the IR signal, analyze it, and have it send another signal to stamp1 with what to do? In effect, making a multitasking basic stamp that can run the servos while receiving the signal, instead of running the short subroutines every time the signal is detected.

If needed, I can post the code for the program.


  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-15 08:56
    You can do what you suggest, but the real bottleneck in your application is the need to produce a servo control pulse every 20ms. There's a better solution and that's the ServoPal which uses a small fixed-program microcontroller to produce the servo control pulses for up to two servos. The Stamp only has to interact with the ServoPal when it needs to change the width of the servo control pulses.

    If you specifically want to use two Stamps to handle this, make the IR remote handling Stamp the master and the servo controller the slave, partly because the servo controller would be on a fixed 20ms cycle and can check for new data from the IR remote handler every cycle.
  • MrRedHairMrRedHair Posts: 9
    edited 2012-06-15 09:12
    How would that be done? Both using the ServoPal and setting a master/slave stamp. What would code look like to communicate between two stamps, one receiving IR Signals, analyzing and interpreting it to send to stamp2 to control servos while stamp1 is still searching and processing the IR.

    I'm particularly interested in setting up the multi-stamp array because I plan on using sensors and servos I have around to expand this bot into something bigger and better, but powered by BASIC, and so the additional stamps would most definitely help in this task.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-15 09:34
    The code to receive IR signals wouldn't change. Your program doesn't change the servo direction or speed until complete valid information is received via IR, analyzed, and a new direction and speed is decided upon. At that point, your program would send a pair of new pulse widths to the ServoPal and the ServoPal would take over from there. There's sample code and documentation on controlling the ServoPal on the webstore page for it.

    You'd do something similar to this if you were using two Stamps instead. The IR Stamp would set an I/O pin high with the guarantee that the servo Stamp would see that within 20ms. The servo Stamp, instead of using a PAUSE 20 to create the 20ms servo control cycle, would use something like PAUSE 1 repeated 20 times with a test for this I/O pin being high. If high, the servo Stamp would set a 2nd I/O pin high as a signal back to the IR Stamp and immediately drop into a SERIN statement to wait for data from the IR Stamp which would then transmit data (using SEROUT) to the servo Stamp and both Stamps would change their I/O pins to low.

    If you want to do a multi-Stamp network, have a look at the Nuts and Volts Columns. There's a two column piece on networking several Stamps together.
  • MrRedHairMrRedHair Posts: 9
    edited 2012-06-15 09:53
    Do you have a link to the columns? I can't seem to find them.

    Another idea: With two stamps, instead of using the IR Remote to control the robot, can you use one stamp with a PING))) sensor to constantly pan back and forth to detect walls and such while the stamp2 has the servos moving? In effect: to make a maze-navigating robot that doesn't have to stop every time it wants to pan the PING))) around to detect surrounding walls. When the PING))) detects a wall, the servos change from forward to turn immediately, no need to stop.
  • ercoerco Posts: 20,235
    edited 2012-06-15 09:56
    Here's my solution, cheaper than 2 Stamps. But hey, I like soldering custom perfboards... :)
  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-15 10:01
    Nuts and Volts Columns Volume #2, Numbers 55 and 56. Go to the main Parallax webpage and click on the Resources tab.
  • MrRedHairMrRedHair Posts: 9
    edited 2012-06-15 10:34
    Awesome. So using serout/serin, I would communicate between a slave and master stamp. My question is on the hardware side. How would I attach two stamps so they could communicate?
  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-15 12:01
    The Nuts and Volts Columns show how to do that for two or more Stamps. Theoretically, you could just connect the I/O pins together. Practically speaking, you'd want to use a resistor between the pairs of I/O pins, usually a 330 Ohm resistor to limit the "fault" current if you were to accidentally program one Stamp to output high and the other Stamp to output low. The minimum number of I/O pins for the scheme I suggested is three. You might also want to put a pullup or pulldown resistor on each of the I/O pins, something like 10K would be fine. The idea is to set a default state for the I/O line. If the program on the side doing an output hasn't finished initializing itself, the I/O line still would have a known state that the input side could count on as a default.

    Again, look at the examples in the Nuts and Volts Columns and in the Stamp Manual chapters on the SERIN and SEROUT statements.
  • Bonjour, (Traduction Google) en espérant que vous pourrez le lire

    Pour créer une ou des applications multitâches avec un Basic Stamp 2p24 / 40, j'ai réalisé une applications utilisée en niveaux industrielle, c'est le partage temporelle avec un système de comptage effectué par une boucle sans fin (à chaque IF ou entre chaque IF, une application s'exécute).

    Un comptage rapide pour les appels rapides, un comptage lent pour les applications lentes.

    Il faut initialiser une variable (sûrement une déclaration Word, Byte étant trop court)

    bcl var word ' (65535 pas de comptage)

    ' Ayant déclarer la dite variable bcl, pas besoin de la mettre à zéro

    ' Puis,

    Start: ' étiquette de démarrage

    if bcl = 17 then .... fonction 1 choisie

    if bcl = 220 then .... fonction 2 choisie

    if bcl = 1000 then .... fonction 3 choisie

    if bcl > 20 and bcl < 50 then ...

    bcl = bcl + 1 ' incrémenter le pointeur

    ' soit on remet la variable bcl à zéro ( IF bcl > nmax then bcl = 0)
    ' ou on attend que le comptage dépasse la valeur Word (65535 pas)

    goto start: ' refaire un tour indéfiniment

    Cela ma permis de créer un feux de signalisation feux rouge (5 secondes), orange (2 secondes), vert (3 secondes) avec une fonction multitâche consistant à activer une led bleue qui clignote toute les secondes pendant 0.5 secondes sans utiliser une seules PAUSE n dans le programme, rien qu'avec le comptage d'un compteur en boucle, des IF pour activer toutes les fonctions. Le processeur travail au maximum dans une boucle, ce système permet d'ajouter des fonctions imprévues aux départ, il faut juste re-calibrer la valeur des IF pour compenser une nouvelle charge du à une perte de vitesse.

    Le processeur BS2p24 a une cadence de environ 12000 opérations par secondes

    Je peut vous fournir une petite vidéo si vous le désirer.

    Alain Pilloud, ing. industrielle
    Ce jour, 11.11.2023

  • Oui, that's the extent of my french

  • @DigitalBob said:
    Oui, that's the extent of my french

    Remember that's a French response to a complicated sequence of events from many years earlier. In fact, we still don't know if the opener to this difficult one was successful. Or where Mr. Green is today even.

    Reply created with the help of two mascots.

Sign In or Register to comment.