Help with State Machine?
Archiver
Posts: 46,084
Jeff-
The way I read it, you have two states. I'd set it up that way
rather than trying to handle it in one processing loop:
state1:
IF x <= limit THEN state1
[noparse][[/noparse]send go forward cmd]
maintain_speed=[noparse][[/noparse]current speed]
state2:
IF x <= limit THEN state1
IF [noparse][[/noparse]current speed] <> maintain_speed THEN state1
GOTO state2
Steve
The way I read it, you have two states. I'd set it up that way
rather than trying to handle it in one processing loop:
state1:
IF x <= limit THEN state1
[noparse][[/noparse]send go forward cmd]
maintain_speed=[noparse][[/noparse]current speed]
state2:
IF x <= limit THEN state1
IF [noparse][[/noparse]current speed] <> maintain_speed THEN state1
GOTO state2
Steve
Comments
subcommand in a state machine. In this example, I want to send the
"go_forward command one time when x is above the threshold and then do
nothing unless "speed" changes or x falls below the threshold. Can anyone
help me? I can post my real code if it will help.
hex_out data $20, $96, $fe
speed var byte
x var word
y var bit
Start:
read hex_out +(x/5), speed
if x>10 and y<>1 then go_forward
goto start
go_forward:
serout ,speed
y=1
goto start
Thanks
Jeff
hex_out data $20, $96, $fe
speed var byte
x var word
y var bit
Resety:
y=0
Start:
' Must be something here to read a new value of x?
read hex_out +(x/5), speed
if x>10 and y<>1 then go_forward
if x<=10 then Resety
goto start
go_forward:
serout ,speed
y=1
goto start
Untested, but it seems your problem is there is no way to reset y.
Good Luck!
Al Williams
AWC
* Microcontroller Projects with Basic Stamps:
http://www.al-williams.com/awce/sbook.htm
>
Original Message
> From: Jeff & Julia [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ZZkNPNRI1ZrMKDD7tqQZ3w25gERmvv6-6Q4ghCZayeuaB-5DIIzNUfgGIgKWlSlr43grsSff6BexedQ]EL-JEFE@P...[/url
> Sent: Tuesday, March 20, 2001 7:52 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Help with State Machine?
>
>
> I am having trouble trying to track multiple parameters of a single
> subcommand in a state machine. In this example, I want to send the
> "go_forward command one time when x is above the threshold and then do
> nothing unless "speed" changes or x falls below the threshold. Can anyone
> help me? I can post my real code if it will help.
>
>
> hex_out data $20, $96, $fe
> speed var byte
> x var word
> y var bit
>
>
> Start:
> read hex_out +(x/5), speed
> if x>10 and y<>1 then go_forward
> goto start
>
> go_forward:
> serout ,speed
> y=1
> goto start
>
> Thanks
>
> Jeff
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
Both solutions would work except that I can't figure out how to store the
speed sent to the serial motor controller as a variable. When the conditions
are right in my "if- then" statement, the program sends a single speed
command to the Motor Mind and then doesn't check back in until the state
changes. So in other words, the value of rctime changes every pass through
the loop, but it doesn't matter because the first value read has already
been sent and the program won't send another speed command unless the state
changes. If I could store the hex speed sent to the motor mind as a variable
I could just use it as my state and just add another parameter to my if-then
statement.
maybe I could write the next line of code below the serout speed, to write
the current speed to another variable and use it as my speed state tracker.
I don't know how long it would take between commands, but my guess is that I
would have to move the joystick pretty fast in order to get a different
value than was sent to the motor mind one line above.
Is it possible to have the serout command sent the string to the motor mind
and record it in the bs2's eeprom?
Jeff
laptop with the code on it and I'll send you what I have been playing with.
Original Message
> Both solutions would work except that I can't figure out how to store
the
> speed sent to the serial motor controller as a variable. When the
conditions
> are right in my "if- then" statement, the program sends a single speed
> command to the Motor Mind and then doesn't check back in until the state
> changes. So in other words, the value of rctime changes every pass through
> the loop, but it doesn't matter because the first value read has already
> been sent and the program won't send another speed command unless the
state
> changes. If I could store the hex speed sent to the motor mind as a
variable
> I could just use it as my state and just add another parameter to my
if-then
> statement.
>
>
> maybe I could write the next line of code below the serout speed, to write
> the current speed to another variable and use it as my speed state
tracker.
> I don't know how long it would take between commands, but my guess is that
I
> would have to move the joystick pretty fast in order to get a different
> value than was sent to the motor mind one line above.
>
> Is it possible to have the serout command sent the string to the motor
mind
> and record it in the bs2's eeprom?
hex_out data $20, $96, $fe
speed var byte
lastspeed var byte
x var word
y var bit
Resety:
y=0
Start:
' Must be something here to read a new value of x?
read hex_out +(x/5), speed
if x>10 and y<>1 then go_forward
if x<=10 then Resety
goto start
go_forward:
serout 9,84,[noparse][[/noparse]speed] ' I made up 9/84
lastspeed=speed
y=1
goto start
Maybe I don't understand what you mean?
Al Williams
AWC
* Microcontroller Projects with Basic Stamps:
http://www.al-williams.com/awce/sbook.htm
>
Original Message
> From: Jeff & Julia [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=r2J4lOJ2_PncEbE6enwANzgSl0sFZyZa5-CgqWWRA4YbyZ_yxghwVJF-w9TVgl4VM-f4wcA6y-Ty]EL-JEFE@P...[/url
> Sent: Tuesday, March 20, 2001 9:11 PM
> To: basicstamps@yahoogroups.com
> Subject: Re: [noparse][[/noparse]basicstamps] Help with State Machine?
>
>
> Thanks Al W. And Mr. Parkis,
>
> Both solutions would work except that I can't figure out how to
> store the
> speed sent to the serial motor controller as a variable. When the
> conditions
> are right in my "if- then" statement, the program sends a single speed
> command to the Motor Mind and then doesn't check back in until the state
> changes. So in other words, the value of rctime changes every pass through
> the loop, but it doesn't matter because the first value read has already
> been sent and the program won't send another speed command unless
> the state
> changes. If I could store the hex speed sent to the motor mind as
> a variable
> I could just use it as my state and just add another parameter to
> my if-then
> statement.
>
>
> maybe I could write the next line of code below the serout speed, to write
> the current speed to another variable and use it as my speed
> state tracker.
> I don't know how long it would take between commands, but my
> guess is that I
> would have to move the joystick pretty fast in order to get a different
> value than was sent to the motor mind one line above.
>
> Is it possible to have the serout command sent the string to the
> motor mind
> and record it in the bs2's eeprom?
>
> Jeff
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
one of those days. [noparse]:)[/noparse]
>go_forward:
>serout 9,84,[noparse][[/noparse]speed] ' I made up 9/84
>lastspeed=speed
>y=1
>goto start
I had it in my head that lastspeed=speed would always return the same
number, but of course lastspeed wouldn't change unless that section of code
was included in the main loop. D'oh. I guess I'll have to give up drunken
stamping (j/k)
Thank you!
Jeff