Bouncing railway(railroad) signals project

I’d appreciate comments on whether this idea is ‘a goer’

Railway semaphore signals were typically controlled via a long cable and so, particularly when returning to ‘danger’ tended to bounce. (In the UK the signal arm was raised to 45 degrees for clear and then back the horizontal for danger).

I’d like to replicate this motion by using a servo and the Pololu Micro Maestro 6-Channel USB Servo Controller looks like a good plan. I think I could attach my model signal box lever frame so the lever opens/closes a switch on one of the channels and then code a sequence of movements on server to raise or lower the signal arm with the appropriate movements to make it appear to bounce.

Reading through the user guide this sounds reasonable trivial but am I missing something? I guess I’d have three signals on a single controller and need to loop around the inputs to see the state of the switch and then run the sequence of movements if the servo position didn’t match the desired state.

(please be gentle on the Newbie!)

David Barham

Don’t worry, everyone is a newbie on the Maestro - it has only been out for a month and a half!

But yes, I think this application would be trivial. You can set up the two motions as separate sequences, then save them to subroutines in your script with a button click. Say they are called UP and DOWN, and suppose your switch is connected to channel 3. Then your script could be as simple as:

begin
  up
  begin
    3 get_position 512 less_than
    while repeat # wait for switch to open
  down
  begin
    3 get_position 512 greater_than
    while repeat # wait for switch to close
repeat

Of course, I have not tested this, but something like it should work!

thanks Paul, I actually understand that code (which must be a good sign!), more used to things like Perl.

I’m a little unclear as to the best way to monitor 3 inputs and control 3 outputs. I can’t quite get my brain around how to deal with the fact I want to check the state of three different inputs and switch the outputs accordingly. I’m happy with effectively not being able to monitor one switch while one of the servos is going through the sequence of bounces.

Is there a best practice?

David

Unfortunately, there is no “best practice” when it comes to doing a bunch of stuff in parallel on a system like this. I would personally try to keep the both the state of the buttons and the frame number within each sequence on the stack; something like this:

5: frame for servo 2
4: state of button 2
3: frame for servo 1
2: state of button 1
1: frame for servo 0
0: state of button 0

I would deal with one servo at a time - do whatever I needed to do for that servo, then use the ROLL command twice after each to permute the data so that I could check on the next one. In that way I think you could get things to be somewhat in parallel, but it would take some careful thinking and debugging.

If it gets too complicated, you can always go for an external processor like a Baby Orangutan and program your sequences in C.

-Paul

Thanks Paul
that makes sense.

Can i have some advise about the circuit for connecting a switch to the servo input? The user guide makes reference to a pull-up resistor. I know I’m being dim but where does this go relative to the switch? is there a simple diagram somewhere?

The other thought I had was that if I could arrange a pair of switches to generate an input voltage which could have four steps I could have two switches on one input and then make the unit control 4 servos not 3.

Something like

switch position
off off 1v
off on 2v
on off 2.5v
on on 5v

I guess this would be possible with a few simple pairs of resistors.

David

The pull-up resistor should go to the 5V line of the Maestro, like this (pardon the ASCII art):

5V
|
R
+---Maestro port
SW
|
GND

10k would be a reasonable value. You could actually put multiple switches on a line, but I could imagine it being a bit of a pain to write the software to handle that. Here’s a circuit that should give you a good set of voltages with two switches:

   5V
  /  \
SW0  2.2k
 |    |
10k  SW1
  \  /
   ++--- port
   |
  4.7k
   |
  GND

I have not tested this, but I think you will get 0, 1.6V, 3.4V, and 5V with the various combinations of switches. Maybe you could put even more switches on the same line? If you get something like that working reliably, I would definitely like to see your code!

-Paul

I received my Maestro in the mail yesterday, what an excellent Gismo!

After the pain of waiting for .NET 3.5 to install (can’t blame Pololu for that Bl**dy Microsmurf, should rebuild home PC to linux but the family won’t let me!) it worked immediately with the servos I had purchased.

I’ve scripted a ‘continuous bounce’ and can get a really nice movement. Next step is to play with an input switch.

Fun for all the family!

David

I think so… :slight_smile:

Well Paul said he’d be interested in the code.
Please be gentle with me!

Still to do:-
1- Make a version with 2 inputs and 4 servos
2- Parametrize the servo settings for up and down so each servo can have different settings
3- Buy a fourth servo as one of the four I purchased stopped working.

thanks
David Barham

# use input to set position of two signals
# 
#   +5---------------
#       |        |
#      10K      2.2K
#       |        |
#       o        o
#        /        /
#       o        o
#       |        |
#       ------------------- input
#            |
#            4.2K
#            |
#   GND-------
#
# set both servos position signals DOWN

0 down
1 down

begin 
   # continually loop reading switch state and then processing
   5 get_position
   # read value on input channel and compare to ranges
   # push onto stack the values for the switches and range
   # ranges must include all possible numbers and appear to overlap 
   # by 1 so that the value on the range boundary is included in 
   # higher range
   # e.g 10 is not in the first range as test is <10 but included 
   # in the second as test is >9
   1 0 0 10 check
   1 1 9 435 check
   0 0 434 800 check
   0 1 799 1000 check
   # remove switch position voltage
   drop
   # stack should just have the position of switches
   0 process_state
   1 process_state
repeat

sub process_state
    # compare desired state for a servo with actual state and move 
    # Signal UP or DOWN as required
    # enter with 2 items on stack - servo#:switch state
  dup
    # 3 items - servo#:#servo#:switch state
  get_position
    # 3 items - position:servo#:switch state
  2200 less_than 
    # <2200 means signal is UP, > 2200 means signal is DOWN 
    # 3 items - 1 = UP 0 = down:servo#:switch state
  rot
    # 3 items - switch state:1 = UP 0=down:servo#
  over
    # 4 items - 1 = UP 0=down:switch state:1 = UP 0=down:servo#
  not_equals
    # 3 items - 1 = needs changing 0 = doesn't need changing:
    # 1 = UP 0 = down:servo#
  if
    # 2 items - 1 = UP 0 = down:servo#
    50 delay
     if
    # 1 item - servo#
        down
     else
        up
     endif
  else
    # signal already set correctly
    # clear switch state and servo# from stack
    drop drop
  endif
return

sub up
    # stack contains servo#
    # signal rises and then falls back to final position
    #delay and position
    300 2000 frame
    200 2100 frame
    drop
return

sub down
    # stack contains servo#
    # signal falls and bounces twice
    # delay and position
    200 3280 frame
    150 2500 frame
    150 3280 frame
    150 3000 frame
    150 3280 frame
    drop
return

sub frame
    # move to given position and wait the desired period
    2 pick
    servo
    delay
return

sub check
    # check the voltage of the input with the range representing 
    # position of switches. Leave the switch status on the stack 
    # if correct
    4 pick
    dup
    rot
    less_than
    if
      greater_than
      if 
        drop drop
      else 
        rot #good to go!
      endif 
    else
       drop drop drop drop
    endif
return

I final got around to making a model signal to attach the servos too. You can see the result here

http://www.youtube.com/watch?v=DYCSSdNKsaM

Thanks to the Pololu team for their help and encouragement.

David