[Robotgroup] Robot Head: BS2 Stamp programming Help?!

Vern Graner vern at txis.com
Tue Aug 5 11:18:25 PDT 2008


LHudson wrote:
> The problem is that if there is no command to execute the Pan & Tilt, then
> the servos receive no PULSOUT.  With no charge to the motors, the slightest
> bump can cause a severe case of whiplash.  My tentative solution was to put
> additional PULSOUT codes before the ...LOOP:  

Servo motors need a constant stream of pulses in order to operate. More 
specifically, a servo's main "job" is to correct for errors in position. 
In order to correct (i.e. move), it needs to have two values to compare--

* The first value is derived from the potentiometer that is attached to 
the servo's output shaft (i.e. where the servo IS)

* The second value is derived by measuring the incoming PWM pulses (i.e. 
where the servo SHOULD BE)

The servo is constantly checking and correcting for differences between 
the first and second value. If there is no discernible difference, then 
the servo *holds* its existing position.

If you do not provide a constant stream of pulses for the servo to 
"compare" with its current position, then the motor will not "power up" 
or move at all (i.e. goes "slack" as if it were un-powered). 
subsequently, if you exert external force on your pan/tilt mechanism, it 
will simply "flop" over to whatever position it is pushed towards since 
it only has one value (i.e. the potentiometer value) so no "correction" 
can be derived.

In the situation you described, you would need for the basic stamp to 
"refresh" the servo output in a continuous loop (ever 20ms).

This will be a problem with your existing code since you are using a 
Serial-In command. The Serial-In (i.e. SERIN) is considered "blocking" 
code in that the Basic Stamp will HALT, and WAIT for this command to 
complete successfully (or time out) before continuing.

To get around this problem, there are two apparent choices:

   1) Use an external piece of hardware to produce the stream of pulses 
to the servo. Examples include many "serial servo controllers" such as:

ServoPAL from Parallax: http://tinyurl.com/58ymtp

or

SSC from Parallax: http://tinyurl.com/5a4kqf

or

Micro Servo Controller: http://www.pololu.com/catalog/product/207

This approach is the simplest and it will absolutely solve the issue as 
it "offloads" the "feeding" of the servos to an external device that is 
designed specifically for that task. This leaves the BSII free to 
"listen" constantly for a serial input.


   2) Modify your code to both monitor the serial port AND refresh the 
servos in a loop, such as:

--------------------- CODE -----------------------
DEBUG CR, "Enter Command: "

DO
  SERIN 16, BAUD, 20, RefreshServos, [DEC COMDATA]

  IF COMDATA < 100
    ' {Do the Speech Code}
    ELSEIF COMDATA < 1000
     ' {Do the Movement Code}
    ELSE
     ' {Do the Pan or Tilt Code}
  ENDIF

  RefreshServos: 'Update Servo Positions
    PULSOUT PIN_PanTilt_Pan, POS_PanTilt_Pan
    PULSOUT PIN_PanTilt_Tilt, POS_PanTilt_Tilt

LOOP
--------------------- /CODE ----------------------

The above code waits 20 ms for an incoming serial command, if one is not 
received, it then updates the PWM output to the servo motors. If a 
serial command is received during the 20ms wait period, it will execute 
the IF comparison pseudo-code.

I have not tested the above code to see if it works. One issue that 
comes to mind is if a serial command begins while the servo PWM is being 
sent. You might miss the first few bytes of the transmission.

Hope this helps. :)

Vern

-- 
Vern Graner CNE/CNA/SSE    | "If the network is down, then you're
Senior Systems Engineer    | obviously incompetent so why are we
Texas Information Services | paying you? Of course, if the network
http://www.txis.com        | is up, then we obviously don't need
Austin Office 512 328-8947 | you, so why are we paying you?" ©VLG




More information about the Robotgroup mailing list