Shop OBEX P1 Docs P2 Docs Learn Events
Tilt Sensor-Memsic and servo Basic Stamp 2 — Parallax Forums

Tilt Sensor-Memsic and servo Basic Stamp 2

Jeff RJeff R Posts: 9
edited 2008-04-28 20:10 in BASIC Stamp
Hi, I am trying to find a way to use the Memsic 2125 and 2 servos to move in X <-> Y
using the Memsic to maintain a position when tilted.
I searched but didn't find anything for "tilt memsic servo" etc.
If someone has previous experience doing this please let me know.
I have seen some listings on using the boebot.
The setup would be like a gimbal keeping the memsic horizontal regardless of tilt.
Thank you for any info, Jeff

Here is the code from the Stampworks manual that I modified for 2 servos using CDS cells (photocells).
This was to track a light source but didn't work all the good.
I would like to try the Memsic to do this.

' {$STAMP BS2}
' {$PBASIC 2.5}
' ==============================================================================
'
' Program Description
'
' "This program shows how to control a standard servo with the BASIC Stamp."
'
' I/O Definitions [noparse][[/noparse]"CON" = constant]
'
'1st servo
PotCWX CON 0 ' pin 0 clockwise pot input
PotCCWX CON 1 ' pin 1 counter-clockwise pot input
ServoX CON 2 ' pin 2 servo control pin
'2nd servo
PotCWY CON 3 ' pin 3 clockwise pot input
PotCCWY CON 4 ' pin 4 counter-clockwise pot input
ServoY CON 5 ' pin 5 servo control pin
'
' Constants
'
'1st servo = X
ScaleX CON $0068 ' scale RCTIME To 0 - 250, BS2
'2nd servo = Y
ScaleY CON $0068 ' scale RCTIME To 0 - 250, BS2
' Scale CON $002C ' BS2sx
' Scale CON $002A ' BS2p
'
' Variables
'
'1st servo
rcRtX VAR Word ' rc reading - right
rcLfX VAR Word ' rc reading - left
diffX VAR Word ' difference between readings
sPosX VAR Word ' servo position
'2nd servo
rcRtY VAR Word ' rc reading - right
rcLfY VAR Word ' rc reading - left
diffY VAR Word ' difference between readings
sPosY VAR Word ' servo position
'
' Program Code
'
Main:
'1st servo
HIGH PotCWX '<
discharge caps
HIGH PotCWY '<
discharge caps

HIGH PotCCWX'<
discharge caps
HIGH PotCCWY'<
discharge caps
PAUSE 10

RCTIME PotCWX, 1, rcRtX'<
READ clockwise
RCTIME PotCWY, 1, rcRtY '<
READ clockwise

RCTIME PotCCWX, 1, rcLfX'<
READ counter-clockwise
RCTIME PotCCWY, 1, rcLfY'<
READ counter-clockwise

rcRtX = (rcRtX */ ScaleX) MAX 250'<- scale RCTIME TO 0-250
rcRtY = (rcRtY */ ScaleY) MAX 250'<- scale RCTIME TO 0-250

rcLfX = (rcLfX */ ScaleX) MAX 250'<- scale RCTIME TO 0-250
rcLfY = (rcLfY */ ScaleY) MAX 250'<- scale RCTIME TO 0-250

sPosX = rcRtX - rcLfX'<
calculate position (-250 TO 250)
sPosY = rcRtY - rcLfY'<
calculate position (-250 TO 250)

PULSOUT ServoX, (650 + sPosX)'<
move the servo [noparse][[/noparse]original=PULSOUT Servo, (750 + sPos)]
PULSOUT ServoY, (650 + sPosY)'<
move the servo [noparse][[/noparse]original=PULSOUT Servo, (750 + sPos)]
PAUSE 20

'DEBUG HOME, "Position: ", SDEC sPosX, " "
GOTO Main

Post Edited (Jeff R) : 4/28/2008 8:18:20 PM GMT
Sign In or Register to comment.