Servo Question, fine tuning limits
pbrady73
Posts: 4
OK, here's the program
' ==============================================================================
'
' File...... Ex25 - Servo.BS2
' Purpose... Hobby Servo Control
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 01 MAY 2002
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
'
' ==============================================================================
'
' Program Description
'
' This program shows how to control a standard servo with the BASIC Stamp.
'
' I/O Definitions
'
PotCW CON 0 ' clockwise pot input
PotCCW CON 1 ' counter-clockwise pot input
Servo CON 2 ' servo control pin
'
' Constants
'
Scale CON $0068 ' scale RCTIME to 0 - 250, BS2
' Scale CON $002C ' BS2sx
' Scale CON $002A ' BS2p
'
' Variables
'
rcRt VAR Word ' rc reading - right
rcLf VAR Word ' rc reading - left
diff VAR Word ' difference between readings
sPos VAR Word ' servo position
'
' Program Code
'
Main:
HIGH PotCW ' discharge caps
HIGH PotCCW
PAUSE 1
RCTIME PotCW, 1, rcRt ' read clockwise
RCTIME PotCCW, 1, rcLf ' read counter-clockwise
rcRt = (rcRt */ Scale) MAX 250 ' scale RCTIME to 0-250
rcLf = (rcLf */ Scale) MAX 250
sPos = rcRt - rcLf ' calculate position (-250 to 250)
PULSOUT Servo, (750 + sPos) ' move the servo
PAUSE 20
GOTO Main
The Program and servo works as it should. My question pertains to fine tuning the servo position. Let's say i need to limit the position of the servo to a specific point to the right,
Could i do it by altering this line by giving it an offset, for example:
Original: sPos = rcRt - rcLf ' calculate position (-250 to 250)
Offset added: sPos = (rcRt -100) - rcLf ' calculate position (-250 to 250)
Or can it be done by altering the scale, for example
Original: rcRt = (rcRt */ Scale) MAX 250
rcLf = (rcLf */ Scale) MAX 250
Modified: rcRt = (rcRt */ Scale) MAX 250
rcLf = (rcLf */ Scale) MAX 200
Am i on the right path, or did i miss it entirely?
Thanks!
PMB
' ==============================================================================
'
' File...... Ex25 - Servo.BS2
' Purpose... Hobby Servo Control
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 01 MAY 2002
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
'
' ==============================================================================
'
' Program Description
'
' This program shows how to control a standard servo with the BASIC Stamp.
'
' I/O Definitions
'
PotCW CON 0 ' clockwise pot input
PotCCW CON 1 ' counter-clockwise pot input
Servo CON 2 ' servo control pin
'
' Constants
'
Scale CON $0068 ' scale RCTIME to 0 - 250, BS2
' Scale CON $002C ' BS2sx
' Scale CON $002A ' BS2p
'
' Variables
'
rcRt VAR Word ' rc reading - right
rcLf VAR Word ' rc reading - left
diff VAR Word ' difference between readings
sPos VAR Word ' servo position
'
' Program Code
'
Main:
HIGH PotCW ' discharge caps
HIGH PotCCW
PAUSE 1
RCTIME PotCW, 1, rcRt ' read clockwise
RCTIME PotCCW, 1, rcLf ' read counter-clockwise
rcRt = (rcRt */ Scale) MAX 250 ' scale RCTIME to 0-250
rcLf = (rcLf */ Scale) MAX 250
sPos = rcRt - rcLf ' calculate position (-250 to 250)
PULSOUT Servo, (750 + sPos) ' move the servo
PAUSE 20
GOTO Main
The Program and servo works as it should. My question pertains to fine tuning the servo position. Let's say i need to limit the position of the servo to a specific point to the right,
Could i do it by altering this line by giving it an offset, for example:
Original: sPos = rcRt - rcLf ' calculate position (-250 to 250)
Offset added: sPos = (rcRt -100) - rcLf ' calculate position (-250 to 250)
Or can it be done by altering the scale, for example
Original: rcRt = (rcRt */ Scale) MAX 250
rcLf = (rcLf */ Scale) MAX 250
Modified: rcRt = (rcRt */ Scale) MAX 250
rcLf = (rcLf */ Scale) MAX 200
Am i on the right path, or did i miss it entirely?
Thanks!
PMB
Comments
PULSOUT Servo, MIN 500 (750 + sPos) MAX 1000 ' move the servo
You will need to experiment to find the appropriate values for MAX and MIN.
Rich H
DE
KC5KLQ