Code help?
Archiver
Posts: 46,084
· A serial motor controller I am using is giving me a problem concerning the reverse command. When this device receives the motor reverse string it simply reverses whatever the last direction was.· Since my code is an infinite loop to constantly poll the joystick and send appropriate code to the serial motor device, I get a reversal of motor direction every pass through the loop. i.e.
x var byte
y var byte
start:
rctime 1, x··· ··· 'check pot 1
rctime 2,y··· ··· 'check pot 2
if x=0 and y=0 then halt
if x>0 and y=0 then Forward
if y>0 and x=0 then Back
Halt:
'send string for motor stop
goto start
Forward:
'send string to start motor
goto start
Reverse:
'send string for reverse.
'send string to start motor.
goto start
·After the serial device receives the reverse signal, it waits to receive a "start"
signal before setting the motor in motion. Therefore, every pass through the loop while the joystick is in reverse, causes another motor reversal. How can I get the stamp to send the reverse string once and then wait for a change in joystick position before sending another command to the serial device?
Jeff
· Sorry to keep bugging you guys about this same problem but I am baffled.
x var byte
y var byte
start:
rctime 1, x··· ··· 'check pot 1
rctime 2,y··· ··· 'check pot 2
if x=0 and y=0 then halt
if x>0 and y=0 then Forward
if y>0 and x=0 then Back
Halt:
'send string for motor stop
goto start
Forward:
'send string to start motor
goto start
Reverse:
'send string for reverse.
'send string to start motor.
goto start
·After the serial device receives the reverse signal, it waits to receive a "start"
signal before setting the motor in motion. Therefore, every pass through the loop while the joystick is in reverse, causes another motor reversal. How can I get the stamp to send the reverse string once and then wait for a change in joystick position before sending another command to the serial device?
Jeff
· Sorry to keep bugging you guys about this same problem but I am baffled.
Comments
state you were in. Let's say halt=1, forward=2, and back=3. Below is what
I'd do. I'm assuming your joystick code is all correct (it doesn't look
right, but I know this is just an example).
Good luck!
Al Williams
AWC
* HURRY: January sale almost over! Details at
http://www.al-williams.com/awce
x var byte
y var byte
laststate var nib ' ***** NEW
laststate=0 ' ***** No state
start:
rctime 1, x 'check pot 1
rctime 2,y 'check pot 2
if x=0 and y=0 and laststate<>1 then halt ' ******
if x>0 and y=0 and laststate<>2 then Forward ' ******
if y>0 and x=0 and laststate<>3 then Back ' ******
' what if nothing happens?
goto start ' *******
Halt:
'send string for motor stop
laststate=1 ' *********
goto start
Forward:
'send string to start motor
laststate=2 ' *********
goto start
Reverse:
'send string for reverse.
'send string to start motor.
laststate=3 ' *********
goto start
Thank you for your elegant solution. It works well, but I have another
puzzler for you--
My Joystick's center position is an open circuit so I get 4 different R
values dependent upon which corner the stick is located. X left, xright,
yup,ydown. In my previous question, I was actually working xleft , xright.
The new puzzler dealing with this same serial device is: once the reverse
command is issued to the serial controller, the next signal to the motor
will be the reverse of the last direction. In other words, if I go into
reverse consecutively my motor will run in different directions each time.
The reverse signal does nothing more than tell the serial device that the
next instruction it receives will execute in the opposite direction. I would
like to assign 1 direction of the motor to 1 position of the joystick. Any
suggestions?
I also wanted to ask if a pakVI will decode an "Alps Glide point" mouse
pad into a variable ? I posed a problem to this group a few years ago about
a patient of mine that could use a mouse pad like this to operate her
prosthetic arms. I would love to get that idea working for her.
Thanks, Jeff
Original Message
From: Al Williams <alw@a...>
To: <basicstamps@egroups.com>
Sent: Wednesday, January 24, 2001 3:16 PM
Subject: [noparse][[/noparse]basicstamps] RE: [noparse][[/noparse]basic stamps] Code help?
> If I understand your question, it seems like you need to remember the last
> state you were in. Let's say halt=1, forward=2, and back=3. Below is what
> I'd do. I'm assuming your joystick code is all correct (it doesn't look
> right, but I know this is just an example).
>
> Good luck!
>
> Al Williams
> AWC
> * HURRY: January sale almost over! Details at
> http://www.al-williams.com/awce
>
>
>
> x var byte
> y var byte
>
> laststate var nib ' ***** NEW
> laststate=0 ' ***** No state
>
> start:
> rctime 1, x 'check pot 1
> rctime 2,y 'check pot 2
>
> if x=0 and y=0 and laststate<>1 then halt ' ******
> if x>0 and y=0 and laststate<>2 then Forward ' ******
> if y>0 and x=0 and laststate<>3 then Back ' ******
> ' what if nothing happens?
> goto start ' *******
>
> Halt:
> 'send string for motor stop
> laststate=1 ' *********
> goto start
>
> Forward:
> 'send string to start motor
> laststate=2 ' *********
> goto start
>
> Reverse:
> 'send string for reverse.
> 'send string to start motor.
> laststate=3 ' *********
> goto start
>
>
>
>
>