Multiple BS2 stamps
Chris LeFrois
Posts: 1
Hello,
Is there an article or has any one linked 2 or more BS2 stamps together?
Either serial processing or even parallel processing?
One BS2 would run main loop processing and the other would do peripheral processing for sensors, motor control, LCD keyboard and other devices.
And would it be fast enough for responding to sensor changes?
Thanks,
Chris
Comments
·
I have five Stamps linked in a star configuration operating my ‘bot, Ugly Buster, which is a tracked vehicle.
·
A single BS2p40 serves as the “master” and four OEM BS2s serve as “slaves.” Each slave is dedicated to a single task. (If I had it to do over again a I would not use the OEM versions of the BS2. It is a great board, but far larger than I require with no extra features that I need.)
·
Essentially, the master has five pins dedicated to each slave. It uses these 20 pins (5 pins for 4 slaves) to either send commands or receive data. The simple commands it sends are stop, 15 different speeds, forward, reverse, and make all pins inputs at the end of the run.
·
I do not use SERIN/SEROUT because of the built in delays involved. Now, they may work just fine in my environment, as might a single processor, it is just not the way I decided to do things. My machine is Stamp-heavy and code-lite. For example, in one operational mode, all that two slaves do is control two (one each) HB-25 which in turn control two gearmotors. In that same mode, the other two slaves are dedicated to counting pulses from those same gearmotor optical encoders and alerting the master of the current count. When the master receives the two counts, if they differ by four or more, the master makes a decision to correct the situation by halting or slowing the offending gear motor until the other one catches up. Since the tracks are 40 inches long, this means that the master keeps Ugly Buster running straight until it is 1.125” off true, then a correction occurs.
·
I mentioned that I do not use SERIN/SEROUT commands, although they may work fine in my application. I “invented” a five bit (hence five pins) instruction set that the master uses to order the slaves around. For example, if the master set its pins 5 through 9 to the pattern of 11001 the slave’s dedicated input pins would detect that pattern-and if it was different from the previously detected pattern—it would interpret it as Forward, speed 9 (9/15 of maximum speed; (a setting of 885 for the HB-25).
·
As you can see, this limits my speed settings severely. But, how many speeds do you really need? I believe that 15 speeds are more than enough. (If not or if I need to expand the instruction set, I could always use more pins . . . up to eight, anyway.) It is also my opinion (based on no facts whatsoever) that this method is much faster and more reliable than using SERIN/SEROUT commands.
·
The BS2 Stamps operate at 4,000 instructions per second: 4KIPS. The BS2p40 operates at 12KIPS, quite a bit faster. However, the SX chip operates at up to 50 million instructions per second; 50 MIPS.
·
When Ugly Buster grows up a little bit more, his Stamps will be replaced with SX modules. (The SX also has an interrupt structure lacking in the Stamps.) I will probably use fewer SX modules than the current number of Stamps I am now using. However, all my life I have programmed a single processor to do everything. It is a refreshing change to contemplate ways to program that entail employing multiple processors, each dedicated to a single task.
·
By the way, with the SX modules, I WILL use SERIN/SEROUT commands due to the far higher baud rates achievable with the SX.
·
I hope this helps and gives you a different take on ways to make your stuff do stuff. I am a newbie.
·
—Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
If I understand you correctly,each speed command in the slave's program is represented by a 5 bit binary number,yes? If so,how exactly are the commands executed? For example, you use " Forward,speed 9 ".·I assume,·" Forward, speed 9 " a Subroutine.·And you first have to make pins 5 through 9 inputs. Do you simply write: %11001 = GOSUB Forward_speed9 or is it just speed9 = %11001.
ken
This is the code that is currently running on the master. As you might be able to tell, I just decided to use five bits in my fixed-length instruction set. Five bits seemed to be enough to do everything I needed. Of course, the slaves must interpret and assemble the status of their input pins into something that makes sense as far as commands to their HB-25s are concerned. (If this does not bore you to tears, I will send you the slave code.)
I am not recommending this method of programming. It is fast, which gets around some limitations in the Stamp world (slow and no interrupts). However, it can be cumbersome, as you can easily tell.
If you decide to hook a pin from one Stamp to a pin on another Stamp to communicate Stamp to Stamp in this fashion, put a 1 megaohm resistor between them. Other values may work better, but that value works for me.
--Bill
'
[noparse][[/noparse] Compiler Directives ]
' {$STAMP BS2p}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Program Name ]
' Skid Steer Master v100.bpx
'
[noparse][[/noparse] Program Description ]
' PHYSICAL PROCESSOR: BS2p40 Module
·
' This is the code for the skid steer robot master processor, a BS2p40.bpx. It
' indicates whether it and by implication, the rest of the robot are alive by
' blinking an LED once per second. It also sends a five-bit command to an OEM-BS2
' slave processor to execute. Commands are sent by dedicated master output pins.
' The desired command is constructed in a byte-array and five bits of the array are
' assigned TO a seperate OUTPUT PIN. The possible commands are listed below.
'
' This program MUST come up before slave programs controlling HB-25 devices.
'
[noparse][[/noparse] I/O Definitions ]
' Master command definitions . . .
' 00000··· Stop
' 00001··· Command to slaves to set HB25 signal pin to input
' 10000··· No definition
' 10001··· Forward, speed 1 (1/15 of maximum speed)
' 10010··· Forward, speed 2 (2/15 of maximum speed)
' 10011··· Forward, speed 3 (3/15 of maximum speed)
' 10100··· Forward, speed 4 (4/15 of maximum speed)
' 10101··· Forward, speed 5 (5/15 of maximum speed)
' 10110··· Forward, speed 6 (6/15 of maximum speed)
' 10111··· Forward, speed 7 (7/15 of maximum speed)
' 11000··· Forward, speed 8 (8/15 of maximum speed)
' 11001··· Forward, speed 9 (9/15 of maximum speed)
' 11010··· Forward, speed 10 (10/15 of maximum speed)
' 11011··· Forward, speed 11 (11/15 of maximum speed)
' 11100··· Forward, speed 12 (12/15 of maximum speed)
' 11101··· Forward, speed 13 (13/15 of maximum speed)
' 11110··· Forward, speed 14 (14/15 of maximum speed)
' 11111··· Forward, speed 15 (15/15 of maximum speed)
·
' 00001··· Reverse, speed 1 (1/15 of maximum speed)
' 00010··· Reverse, speed 2 (2/15 of maximum speed)
' 00011··· Reverse, speed 3 (3/15 of maximum speed)
' 00100··· Reverse, speed 4 (4/15 of maximum speed)
' 00101··· Reverse, speed 5 (5/15 of maximum speed)
' 00110··· Reverse, speed 6 (6/15 of maximum speed)
' 00111··· Reverse, speed 7 (7/15 of maximum speed)
' 01000··· Reverse, speed 8 (8/15 of maximum speed)
' 01001··· Reverse, speed 9 (9/15 of maximum speed)
' 01010··· Reverse, speed 10 (10/15 of maximum speed)
' 01011··· Reverse, speed 11 (11/15 of maximum speed)
' 01100··· Reverse, speed 12 (12/15 of maximum speed)
' 01101··· Reverse, speed 13 (13/15 of maximum speed)
' 01110··· Reverse, speed 14 (14/15 of maximum speed)
' 01111··· Reverse, speed 15 (15/15 of maximum speed)
·
' Pin wiring notes . . .
' Right Encoder Slave uses Master pins 0 - 4.
' Right Gearmotor Slave uses Master pins 5 - 9.
' Left Encoder Slave uses Master pins 15 - (AUXIO) 19.
' Left Encoder Gearmotor uses Master pins 10 - 14.
·
'
[noparse][[/noparse] Constants ]
·
'
[noparse][[/noparse] Variables ]
Left_command_array·· VAR· Byte(1)······ ' Set up a one byte array for the processor
······································· ' that controls the left motor.
Right_command_array· VAR· Byte(1)······ ' Set up a one byte array for the processor
······································· ' that controls the right motor.
······································· ' The "command set" for the processors
··································· ····' controlling the HB-25s will use five of
······································· ' the eight bits. The HIGH-order bit will
······································· ' indicate forward (1) OR reverse (0). The
······································· ' LOW order bits will indicate one of 16
······································· ' speeds specified in the table above.
·
' The master's current command for the processor controlling the left motor . . .
Left_Command········ VAR· Left_command_array
' The master's current command for the processor controlling the right motor . . .
Right_Command······· VAR· Right_command_array
idx················· VAR· Word········· ' Loop index variable
Left_Track·········· VAR· Nib·········· ' Left track position nibble
Right_Track········· VAR· Nib·········· ' Right track position nibble
Right_Encoder······· PIN 0············· ' Right encoder event pin
Left_Encoder········ PIN 15············ ' Left enconder event pin
'
[noparse][[/noparse] Initialization ]
·
'Twelve_VDC··· PIN 15··················· ' Output Futurlec control pin
·
·
GOSUB Turn_On_12vdc_System············· ' Turn on the 12vdc system
·
·
MAINIO
INPUT Right_Encoder:INPUT Left_Encoder· ' Set both encoder pins to input
·
' Dedicate 9 pins (1-9) of the master for one-way communication to the left
' and right encoder slaves.
LOW 1:LOW 2:LOW 3:LOW 4:LOW 5: LOW 6: LOW 7: LOW 8: LOW 9:LOW 10:LOW 11:LOW 12:LOW 13:LOW 14
AUXIO······································ ' Toggle to the high-order BS2p40 I/O pins
' Set the Futurlec 12vdc control pin low . . .
LOW Twelve_VDC
MAINIO····································· ' Toggle to the low-order BS2p40 I/O pins
PAUSE 1000
'
[noparse][[/noparse] Program Code ]
·
Main:
' Turn on the 12vdc system . . .
GOSUB Turn_On_12vdc_System
MAINIO
·
' Forward for a bit . . .
FOR idx = 1 TO 1000
· Right_Command = %11000:Left_Command = %11000
· GOSUB Send_Right_Command:GOSUB Send_Left_Command
·
· DEBUG DEC Left_Encoder, " ",DEC Right_Encoder, CR
NEXT
·
' Stop for a short while between commands . . .
FOR idx = 1 TO 333
· Right_Command = %00000:Left_Command = %00000
· GOSUB Send_Right_Command:GOSUB Send_Left_Command
· DEBUG DEC Left_Encoder, " ",DEC Right_Encoder, CR
NEXT
·
' Reverse for the same amount as we went forward . . .
FOR idx = 1 TO 1000
· Right_Command = %01000:Left_Command = %01000
· GOSUB Send_Right_Command:GOSUB Send_Left_Command
· DEBUG DEC Left_Encoder, " ",DEC Right_Encoder, CR
NEXT
· GOSUB Turn_Off_12vdc_System··········· ' Turn off the 12vdc system
· GOSUB Set_All_Pins_To_Input··········· ' Set all pins to input for safe restart
·
· STOP
END
·
'
[noparse][[/noparse] Subroutines ]
Send_Left_Command:
··· OUT5 = Left_command_array.BIT4
··· OUT6 = Left_command_array.BIT3
··· OUT7 = Left_command_array.BIT2
··· OUT8 = Left_command_array.BIT1
··· OUT9 = Left_command_array.BIT0
··· RETURN
·
Send_Right_Command:
··· OUT10 = Right_command_array.BIT4
··· OUT11 = Right_command_array.BIT3
··· OUT12 = Right_command_array.BIT2
··· OUT13 = Right_command_array.BIT1
··· OUT14 = Right_command_array.BIT0
··· RETURN
·
Turn_On_12vdc_System:
' The following three lines turn on the 12vdc system . . .
· AUXIO······· ·························' Use I/O pins X0 - X15
· Twelve_VDC··· PIN 15················· ' Output Futurlec control pin
· HIGH Twelve_VDC······················ ' Set X15 high, this turns on the SSR
· MAINIO······························· ' Return to addressing I/O pins 0 - 15
· RETURN
·
Turn_Off_12vdc_System:
' The following three lines turn on the 12vdc system . . .
· AUXIO································ ' Use I/O pins X0 - X15
· LOW Twelve_VDC······················· ' Set X15 low, this turns off the SSR
· MAINIO······························· ' Return to addressing I/O pins 0 - 15
· PAUSE 20
' Command to slaves to set HB25 signal pins to input . . .
·
· Left_Command = 1:Right_Command = 1
' Send the command to the slaves . . .
'DEBUG BIN Left_Command,"· ", BIN Right_Command,CR
· GOSUB Send_Left_Command:GOSUB Send_Right_Command
· PAUSE 250···························· ' Pause a quarter second
· RETURN
·
Set_All_Pins_To_Input:················· ' Set all pins to input for safe restart
FOR idx = 0 TO 14:INPUT idx:NEXT
AUXIO
INPUT Twelve_VDC······················· ' Make the 12vdc control pin an input also
MAINIO
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Thanks Bill.The Master program is very interesting.This is just the type of scheme I'm looking for. I have used Scott Edward's mini-SSCII and Parallax's PSC to control the HB25 and the Victor 883 speed controllers and·have found that nothing beats the direct control of a Basic Stamp with its PULSOUT command for motor control .Don't get me wrong,I still plan to use the mini-SSCII and PSC for the servos I plan to use in this project. I just want to use direct control for my main motors and other critical systems in this project . Is the slave program is executed by the same set of commands?
Ken
Here is the program for the left slave. The right one is identical except in a few places which are obvious.
'
[noparse][[/noparse] Compiler Directives ]
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Program Name ]
' Skid-Steer Left HB-25 v103.bs2
'
[noparse][[/noparse] Program Description ]
' PHYSICAL PROCESSOR NUMBER 4
·
' This program receives commands from the master by reading five of the master's
' output pins on five of the slave's input pins. The commands are interpreted as
' shown below.
·
' This program MUST come up after the master program to prevent a spurious command
' from being executed by this program.
'
[noparse][[/noparse] I/O Definitions ]
' Master command definitions . . .
' 00000··· Stop (750)
' 00001··· Shut Down HB25; set HB25 signal pin to input status to prevent power drain
·
' 10000··· No definition
·
' 10010··· Forward, speed 2 (2/15 of maximum speed; 780)
' 10011··· Forward, speed 3 (3/15 of maximum speed; 795)
' 10100··· Forward, speed 4 (4/15 of maximum speed; 810)
' 10101··· Forward, speed 5 (5/15 of maximum speed; 825)
' 10110··· Forward, speed 6 (6/15 of maximum speed; 840)
' 10111··· Forward, speed 7 (7/15 of maximum speed; 855)
' 11000··· Forward, speed 8 (8/15 of maximum speed; 870)
' 11001··· Forward, speed 9 (9/15 of maximum speed; 885)
' 11010··· Forward, speed 10 (10/15 of maximum speed; 900)
' 11011··· Forward, speed 11 (11/15 of maximum speed; 915)
' 11100··· Forward, speed 12 (12/15 of maximum speed; 930)
' 11101··· Forward, speed 13 (13/15 of maximum speed; 945)
' 11110··· Forward, speed 14 (14/15 of maximum speed; 960)
' 11111··· Forward, speed 15 (15/15 of maximum speed; 975)
·
' 00001··· Shut Down HB25; set HB25 signal pin to input status to prevent power drain
·
' 00010··· Reverse, speed 2 (2/15 of maximum speed; 720)
' 00011··· Reverse, speed 3 (3/15 of maximum speed; 705)
' 00100··· Reverse, speed 4 (4/15 of maximum speed; 690)
' 00101··· Reverse, speed 5 (5/15 of maximum speed; 675)
' 00110··· Reverse, speed 6 (6/15 of maximum speed; 660)
' 00111··· Reverse, speed 7 (7/15 of maximum speed; 645)
' 01000··· Reverse, speed 8 (8/15 of maximum speed; 630)
' 01001··· Reverse, speed 9 (9/15 of maximum speed; 615)
' 01010··· Reverse, speed 10 (10/15 of maximum speed; 600)
' 01011··· Reverse, speed 11 (11/15 of maximum speed; 585)
' 01100··· Reverse, speed 12 (12/15 of maximum speed; 570)
' 01101··· Reverse, speed 13 (13/15 of maximum speed; 555)
' 01110 ···Reverse, speed 14 (14/15 of maximum speed; 540)
' 01111··· Reverse, speed 15 (15/15 of maximum speed; 525)
·
' Dedicate five Stamp pins as inputs to listen for the master's commands.
' This must be done after the master has powered the HB25(s) up . . .
INPUT 0: INPUT 1: INPUT 2: INPUT 3: INPUT 4
·
HB25················ PIN· 15
·
'
[noparse][[/noparse] Constants ]
'
[noparse][[/noparse] Variables ]
command_array······· VAR· Byte(1)······ ' Set up a one byte array of eight bits.
······································· ' The "command set" for the HB-25 will use
······································· ' five of the eight bits. The high-order
·········· ·····························' bit will indicate forward (1) or
······································· ' reverse (0). The low order bits will
······································· ' indicate one of 16 speeds specified in
······························· ········' the table above.
·
Command············· VAR· command_array ' The master's current command
oldCommand·········· VAR· Byte········· ' A byte to let us know when the master's
······································· ' command changes
·
'
[noparse][[/noparse] Initialization ]
·
' Wait for left HB-25 to power up . . .
DO : LOOP UNTIL HB25 = 1
LOW HB25······························· ' Make I/O Pins Output/Low
PAUSE 20······························· ' Wait For HB-25s To Initialize
PULSOUT HB25, 750······················ ' Stop the motor
·
'
[noparse][[/noparse] Main Program ]
PAUSE 20
·
DO
·
· ' The following five statements receive and re-construct the master's command in the
· ' command array . . .
· command_array.BIT0 = IN4
· command_array.BIT1 = IN3
· command_array.BIT2 = IN2
· command_array.BIT3 = IN1
· command_array.BIT4 = IN0
·
DEBUG BIN command, CR
·
· IF Command <> %10 THEN············ ' A binary 1 means set HB25 signal pin to
······································· ' input because master has shut 12vdc down
·
··· SELECT Command
····· CASE = %00000
····· PULSOUT HB25, 750················ ' Set HB-25 to 750 (stop)
··· ENDSELECT
·
··· SELECT Command
····· CASE %10010
······· PULSOUT HB25, 780·············· ' Set HB-25 to forward 780
····· CASE %10011
······· PULSOUT HB25, 795·············· ' Set HB-25 to forward 795
····· CASE %10100
······· PULSOUT HB25, 810·············· ' Set HB-25 to forward 810
····· CASE %10101
······· PULSOUT HB25, 825·············· ' Set HB-25 to forward 825
····· CASE %10110
······· PULSOUT HB25, 840·············· ' Set HB-25 to forward 840
····· CASE %10111
······· PULSOUT HB25, 855·············· ' Set HB-25 to forward 855
····· CASE %11000
······· PULSOUT HB25, 870·············· ' Set HB-25 to forward 870
····· CASE %11001
······· PULSOUT HB25, 885·············· ' Set HB-25 to forward 885
····· CASE %11010
······· PULSOUT HB25, 900·············· ' Set HB-25 to forward 900
····· CASE %11011
······· PULSOUT HB25, 915·············· ' Set HB-25 to forward 915
····· CASE %11100
······· PULSOUT HB25, 930·············· ' Set HB-25 to forward 930
····· CASE %11101
······· PULSOUT HB25, 945·············· ' Set HB-25 to forward 945
····· CASE %11110
······· PULSOUT HB25, 960·············· ' Set HB-25 to forward 960
····· CASE %11111
······· PULSOUT HB25, 975·············· ' Set HB-25 to forward 975
··· ENDSELECT
·
··· SELECT Command
····· CASE %00010
······· PULSOUT HB25, 720·············· ' Set HB-25 to reverse 720
····· CASE %00011
······· PULSOUT HB25, 705·············· ' Set HB-25 to reverse 705
····· CASE %00100
······· PULSOUT HB25, 690·············· ' Set HB-25 to reverse 690
····· CASE %00101
······· PULSOUT HB25, 675·············· ' Set HB-25 to reverse 675
····· CASE %00110
······· PULSOUT HB25, 660·············· ' Set HB-25 to reverse 660
····· CASE %00111
······· PULSOUT HB25, 645·············· ' Set HB-25 to reverse 645
····· CASE %01000
······· PULSOUT HB25, 630·············· ' Set HB-25 to reverse 630
····· CASE %01001
······· PULSOUT HB25, 615·············· ' Set HB-25 to reverse 615
····· CASE %01010
······· PULSOUT HB25, 600·············· ' Set HB-25 to reverse 600
····· CASE %01011
······· PULSOUT HB25, 585·············· ' Set HB-25 to reverse 585
····· CASE %01100
······· PULSOUT HB25, 570·············· ' Set HB-25 to reverse 570
····· CASE %01101
· ······PULSOUT HB25, 555·············· ' Set HB-25 to reverse 555
····· CASE %01110
······· PULSOUT HB25, 540·············· ' Set HB-25 to reverse 540
····· CASE %01111
······· PULSOUT HB25, 525·············· ' Set HB-25 to reverse 525
··· ENDSELECT
··· ELSE
····· INPUT HB25······················· ' Setting the HB25 output pin to input
····· GOTO terminate··················· ' prevents the logic power from being
······································· ' drained by the powered-down HB25
· ENDIF
LOOP
·
INPUT HB25····························· ' Set HB25 control pin to input for safe restart
terminate:
INPUT HB25····························· ' Set HB25 control pin to input for safe restart
END
·
'
[noparse][[/noparse] Sub-routines ]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Thanks a million. you have truly poined me in the right direction. With your permission I will use your scheme as a template·in a 4·bit command structure to take advantage of the Basic Stamp ·NIBBLE,variables. Unless I'm wrong I should be able to use : (INA,INB,INC,IND) , (OUTA,OUTB,OUTC,OUTD) and (DIRA,DIRB,DIRC,DIRD) for the BS2p40's pins 1-16. This scheme gives me control of four Stamps. In any event, I will keep you posted of my progress. Thanks Buddy.
Ken
It is an interesting concept and I hope you enjoy it!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.