Shop OBEX P1 Docs P2 Docs Learn Events
Two-Stamp communication - Will this work? — Parallax Forums

Two-Stamp communication - Will this work?

The DoctorThe Doctor Posts: 37
edited 2009-07-15 20:00 in BASIC Stamp
A little background.· I have a bot that uses IR detectors to sense the tabletop.· It also has touch whiskers and a ping for forward/side detection.· It uses a BS2-IC for the brains with a Parallax Servo Controller (Serial) for all the servo commands.

Basically, the code does this:
Do while all sensors are "GO"
·· 1)· Check ground IR
·· 2)· Check whiskers
·· 3)· Check Ping distance
Loop

Everything worked fine until I added the Ping.· Testing the distance with Ping added just enough of a delay to allow the bot to sometimes fall off the table, depending on speed and distance from the edge when the ground IR was checked.

To solve this problem, I thought about switching to a Propeller and dedicating a single cog to just the surface detectors, but that would have it's own drawbacks.

I have two BS2-IC units, so I am thinking of using a second BS2-IC to just handle the surface detectors.

My theory is this:
Hardware:
Pin 15 of both the Master and·Slave Stamps would be connected to the Servo Controller, which raises my first question below.
Pins 12-14 of·the Master Stamp would be connected through 220 ohm resistors to the same pins on the Slave Stamp.

The Slave Stamp would handle just the surface detectors.· It's code would be:

Do while all sensors are "GO"
·· Check surface detectors
·· If all sensors are "GO"
·· ·· hold pins 13 and 14 high
·· If any sensor fails
····· drop pins 13 and 14 low
····· send "HALT" command to Servo Controller
····· raise pin 13·high
Loop

Use SERIN on pin 12 to wait for instructions from the Master Stamp
Use SEROUT·on pin 12 to send·which detector has failed
Use SERIN on pin 12 to wait for Master Stamp to report it has moved
Check sensors
Use SEROUT on pin 12 to inform Master Stamp if movement was successful.· If not, run this section again
Return to detection loop
(End Slave Stamp Code)

The Master Stamp's code would be:

Do while pin 14 is high
·· Check Whiskers
·· Check Ping
·· If Whiskers or Ping fail, move accordingly
Loop

If pin 14 drops low, the Slave cannot detect a surface.· The Slave should have·already halted movement, which resolves the delay problems.
Use SEROUT on pin 12 to query Slave Stamp.
Use SERIN on pin 12 to get failed sensors
Move Accordingly
Use SEROUT on pin 12 to have Slave recheck sensors
Use SERIN on pin 12 to verify movement was successful.··If failed, run this section again
Resume movement and return to loop.
(End Master Stamp Code)

Pin 13 would simply be used as a CTS, making sure the Master Stamp does not try to send data to the Servo Controller at the same time the Slave Stamp is sending.· The Master Stamp will check pin 13 to insure it is high (Slave not sending to Servo Controller) before it sends any command.

This setup would also allow me to simply leave the Slave Stamp off if the bot is on the floor, saving precious battery power.

My questions are as follows:
1)· Is there any problems with having two Stamps connected to the Servo controller, as long as I use the above to insure they don't both send at the same time?
2)· Is 220 ohm sufficient for pins 13-14?
3)· If I decide to leave the Slave Stamp off, I will need pull-up connections on pins 13-14.· Is a 1K to +5v a good way to do this?· Can they be left connected even when the Slave is on, or will I need jumpers/dip switches?
4)· Would reversing my logic on pins 13-14 and using pull-downs have any advantages?· Again, would I use a 1K to Vss for this, and can they be left connected when the Slave is on?
5)· Is the resistor necessary on pin 12 (The serial connection), or can they be wired directly?

Any ideas/thoughts/comments/suggestions would be welcome, and greatly appreciated.· I don't want to burn up either of my Stamps, nor do·I want to waste a lot of time setting this up if my logic is flawed.
·

Comments

  • EmilyPEmilyP Posts: 21
    edited 2009-07-15 13:43
    Hello,

    Is there a reason that your are using pin 12 of the slave for both serin and serout instead of a two way bus for rx and tx. It seems to me a harder timing problem if you use only one bi-directional line for master/slave communication.

    I have built a similar system with a master basic stamp and a slave javelin. My serial connections to the master - slave do not use any resistors so perhaps that can help with your inquiry about pin 12. Reversing the logic for pins 13 and 14 (ie, pulling low instead of high, also should have no affect. But if you have already written code for high it might be easier to stick with it. Also, if pins 13 and 14 are pulled high, from my experience, it shouldn't matter if the slave sends a signal to the master. It will be read high no matter what. 1k resistors are also fine to use for pulling high). Since your project seems to be a control problem, there is no real solution other than testing everything ... a lot. One thing to consider, if you use two processors to control the same servo, it can work, as long as they are sending signals at different times. The signal that is not controlling at the given time must be always low. If you cannot work out the timing for this precisely, you can always add mosfets for the signal line going to the servos. This, however, would require another signal that would essentially decide who was operating the servos.

    And lastly, before you really change your design, have you tried positioning the sensors at different angles / positions. For me, I got ping to work only after I built a leverage arm to give the sensor a little lift. Ping of course works better farther from the ground.

    Emily
  • The DoctorThe Doctor Posts: 37
    edited 2009-07-15 14:06
    EmilyP, thanks for the response. I was planning on only using 1 pin for the SERIN/OUT just to save a pin. I don't think timing will be an issue, since each Stamp will wait for the other one.

    The two stamps will not be directly controlling the servos, so no problems there. The servos are controlled by a Parallax Servo Controller, which uses a single serial command to set speed/direction of up to 16 servos.

    The Ping works fine, it's just that checking it inserted too long a delay in the program execution.

    Thanks again!
  • stamptrolstamptrol Posts: 1,731
    edited 2009-07-15 14:11
    The sample connection between 2 stamps as shown in the editor help file for SERIN/SEROUT is a good reliable method which will allow the communication cycle to be as short as possible (but not too short) by use of a flow control pin. Highly recommended.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • EmilyPEmilyP Posts: 21
    edited 2009-07-15 20:00
    Nice catch with the Ping. I was wondering why you only had one pin controlling the servos. I guess I should have guessed servo controller. Good luck.
Sign In or Register to comment.