servo position
Boneyard
Posts: 10
Im using a track ball to to control a servo, Im having one problem , every time I stop the ball movement the servo returns to the end position. How can I have the servo keep its position
until·I move the track ball again?
·
until·I move the track ball again?
·
Comments
Hope this helps!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
·
'{$STAMP BS2}
'P0 to cs
'P1 to Data
'P2 to Clock
'P7 to servo
cs VAR OUT0········· 'chip select line
clock VAR OUT1······ 'chip clock line
Do VAR IN2·········· 'Chip data input line
Servo VAR OUT15········· 'servo output data
mousex VAR Bit······ 'mouse input value
mousey VAR Byte······ 'mouse clock line
pass VAR Bit········ 'loop counter variable
servotime VAR Word· 'output time for servo
programtop:
DIRL=%1011··········· ' set low byte of IO direction
DIRH=11111
mousey=1
cs=1················· 'set chip select nominal state
clock=1·············· 'set clock nominal state to reset chip
DEBUG "starting"
'*****************************************
looptop:
'········· start a loop that reads the data from the mouse
clock=0
pass=0
mousey=1
cs=0
'·········· clock the data in
getmousey:
mousex=mousex <<1······ 'shift the data bits in the value variable
PULSOUT 1,2············ 'strobe the clock bit
mousex=do·············· 'get the data and stuff it into a bit var
mousex=mousex········· 'or the bit var with the value variable
pass=pass+1············ 'increment the bit counter
IF pass >7 THEN getmousey··· 'if not 8 bits done do again
cs=1························· 'end read with chip select
'······ the data is now read into the
'······ mouse variable and can be used for
'······ other things
'*****************************************
'······ start a servo output time calculation
'······ based on the read data
servotime = mousex * 5
PULSOUT 15, 1500-1··· 'send the pulse to the servo on pin 15
PULSOUT 15,servotime
pulsout 6,500············ 'send a dummy pulse on pin 6 (unused)
······················ ' to slow the loop down for the servo
goto looptop
goto programtop
That's just the few I got from giving it the once over...I would address these issues first.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Post Edited (Chris Savage) : 8/21/2004 5:50:28 PM GMT
i have not cleaned it up
yes p7 should be 15
im chechking the rest ill clean it up and re submit.
the mousex=mousx line i cant explain but if I remove it the the servo will not turn.
i only use the mouse clock line to make this work.
and it does work well, just cant hold the position when i stop moving the track ball
'{$STAMP BS2}
'P0 to cs
'P1 to Data
'P2 to Clock
'P15 to servo
cs VAR OUT0········· 'chip select line
clock VAR OUT1······ 'chip clock line
Do VAR IN2·········· 'Chip data input line
Servo VAR OUT15········· 'servo output data
mousex VAR Bit······ 'mouse input value
mousey VAR Byte······ 'mouse clock line
pass VAR Bit········ 'loop counter variable
servotime VAR Word· 'output time for servo
'******************************************************
programtop:
DIRL=%1011··········· ' set low byte of IO direction
mousey=1
cs=1················· 'set chip select nominal state
clock=1·············· 'set clock nominal state to reset chip
DEBUG "starting"
'*****************************************
looptop:
'········· start a loop that reads the data from the mouse
clock=0
pass=0
mousey=1
cs=0
'·········· clock the data in
getmousey:
mousex=mousex <<1······ 'shift the data bits in the value variable
PULSOUT 1,2············ 'strobe the clock bit
mousex=do·············· 'get the data and stuff it into a bit var
mousex=mousex········· 'or the bit var with the value variable
pass=pass+1············ 'increment the bit counter
IF pass >7 THEN getmousey··· 'if not 8 bits done do again
cs=1························· 'end read with chip select
'······ the data is now read into the
'······ mouse variable and can be used for
'······ other things
'*****************************************
'······ start a servo output time calculation
'······ based on the read data
servotime = mousex * 5
PULSOUT 15, 1500-1··· 'send the pulse to the servo on pin 15
PULSOUT 15,servotime
PULSOUT 6,500············ 'send a dummy pulse on pin 6 (unused)
······················ ' to slow the loop down for the servo
GOTO looptop
GOTO programtop
·
Example 1
==============================================
NewServoPos VAR BYTE 'Desired servo position
CurServoPos VAR BYTE 'Current servo position
MoveRate CON 5 'Servo move step
' Servo move subroutine. CurServoPos holds the current servo position.
' NewServoPos holds the desired servo position. MoveRate specifies the
' size of the servo step. This value, the rate this routine is called, and the
' Basic Stamp being used determines how fast the servo moves.
MoveServo:
IF NewServoPos = CurServoPos THEN MoveServo2
IF NewServoPos > CurServoPos THEN MoveServo1
CurServoPos = CurservoPos - MoveRate
GOTO MoveServo2
MoveServo1:
CurServoPos = CurservoPos + MoveRate
MoveServo2:
PULSOUT 15,CurServoPos
RETURN
Example 2
==============================================
NewServoPos VAR BYTE 'Desired servo position
CurServoPos VAR BYTE 'Current servo position
MoveRate CON 5 'Servo move step
MinPos CON 600 'Minimum servo position
' Servo move subroutine. CurServoPos holds the current servo position.
' NewServoPos holds the desired servo position. MoveRate specifies the
' size of the servo step. This value, the rate this routine is called, and the
' Basic Stamp being used determines how fast the servo moves.
MoveServo:
IF NewServoPos = CurServoPos THEN MoveServo2
IF NewServoPos > CurServoPos THEN MoveServo1
CurServoPos = CurservoPos - MoveRate
GOTO MoveServo2
MoveServo1:
CurServoPos = CurservoPos + MoveRate
MoveServo2:
PULSOUT 15,MinPos+CurServoPos
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.geocities.com/donbuczynski
·· Are you sure you want Bit variables for mousex and pass?· If you have a counter with a Bit variable, it can only count to 1.· And again, you are shifting bits in a single bit variable.
·· Can anybody give a second opinion?· I am kinda out of it today, but I don't think that can be done, not in this code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
·
if i remove the mousex if you look further down the code
its used in the servotime cal.
with out that command the code will not work
also the sequence only respondes in the bit· 0 or 1· on pass and mousex
this code works fine its doing what i want it to do just will not hold position wiht i stop the track ball
Ihave yet to Dons idea
Same with that mousex variable...You're assigning it two different variables in a row, which I don't see what that's accomplishing...Perhaps someone else can figure this out.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Post Edited (Chris Savage) : 8/22/2004 9:56:21 PM GMT
but its works (go figure)
I really thank you for all your time and help
Even though your code seems to work, I think that when you previously combined the code from several different
sources, some of the variables got mixed around and the program is probably not doing what you think it is.
I would like to suggest a few changes that will make it easier to understand and it probably will work a lot better.
To start off, I believe the desired program flow is as follows:
1. Initialization
2. Start the loop:
3. Get 8 bits from the mouse, one at a time(mousex), and combine them into an 8-bit Byte(mousey)
4. Multiply the byte(mousey) by 5, to get Servotime
5. Send Servotime to the servo, using PULSOUT
6. Slow down the loop for a while, then do the loop again.
FYI: Servos typically want a 20 millisecond delay between PULSOUTs.
Here is a suggested finished program, with my comments in ( ).
'P0 to cs
'P1 to Clock (it looks like you switched the words associated with P1 and P2)
'P2 to Data
'P15 to servo
cs VAR OUT0
clock VAR OUT1
Dat VAR IN2 (I would change "Do" to "Dat" since the word Do is used in some versions of Basic to "DO" things)
Servo VAR OUT15
mousex VAR Bit 'mouse input bit
mousey VAR Byte 'mouse byte value (I would suggest that you change your comment from "mouse clock line" to
"mouse byte value", which is more descriptive)
pass VAR Byte (you absolutely need to change "Bit" to "Byte" since the "pass" variable is used to count from
0 to 8 in the loop below. A bit can only count up to 1, a byte can count up to 255).
servotime VAR Word
'*********************************************************************
programtop:
(you should add the following two lines to define the inputs and outputs)
DIRL = %00000011 'set low byte of IO direction (bits 0 & 1 are outputs for cs & clock, bit 2 is an input for the mouse data)
DIRH = %10000000 'set high byte of IO direction (bit 15 is a 1, for the servo output)
mousey = 1
cs = 1
clock = 1
DEBUG "starting"
'**********************************************************************
looptop:
' start a loop that reads 8 bits of data from the mouse (notice the wording here)
clock = 0
pass = 0
mousey = 1
cs = 0
' clock 8 bits of data in, one bit per getmousey loop
getmousey:
mousey = mousey << 1 (you need to change "mousex" to "mousey" in this line. Somehow the two got switched)
PULSOUT 1,2
mousex = Dat (please use "Dat" instead of "Do")
mousey = mousey | mousex (this is the critical step, where the new bit is combined into the byte.
Mousex and mousey must be in this exact order. Also notice the "|" between them.
The "|" is the symbol for the "or" function and is located above the backslash on your keyboard)
pass = pass + 1 (this variable counts up from 0 to 8)
IF pass > 7 then getmousey
cs = 1
'***********************************************************************
servotime = mousey * 5 (you need to change "mousex" to "mousey", they are switched again)
PULSOUT 15, 1500-1 (you need to delete this line. The next line is the correct one to control the servo.
PULSOUT 15, servotime
PULSOUT 6, 500 (I would delete this line and replace it with a more accurate line below)
PAUSE 20 '20 millisecond pause for the servo
GOTO looptop
GOTO programtop (this line could be deleted because the program always stays in the Looptop loop)
Good luck
Dave
·· I myself cannot focus on troubleshooting until the obvious stuff is licked, and we couldn't seem to get past that...I mentioned already several of these things, but anyway...Glad you were able to provide a more overall solution.· I didn't want to try and re-write his code without knowing exactly what data was coming in (i.e. from the trackball controller).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
·
Then you could probably get rid of the mousex=mousex.
just put a ' in front of each of those lines.· It'll just remark them out of the code.
·
Check Jon Williams programming template.· Trust me....when I first started I was doing things like you...hodgepodge messy and all.· I find that now, if I come back to the program a couple months later, it's WAY easier to understand what the heck I was doing!
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
http://www.geocities.com/paulsopenstage
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I will try the changes this weekend and let you know how it went