PDA

View Full Version : logical AND - initial state


Mark Bresler
08-03-08, 03:00 PM
Hi,
I have made a machine to move a servo between two states by operating two switches one for up and one for down. When both switches are active I want to stay in the up state. The switches have pull-up resistors so pressing them causes a logical low. The following state works fine but I'm wondering why it does not need another AND at the end of the fourth line.

------------------
IN-STATE
RAISED
CONDITION
PB1 OFF? AND PB0 ON? AND
CAUSES 4000 SERVO1
REDLED ON
GRNLED OFF
THEN-STATE
LOWERED
TO-HAPPEN
--------------
when the AND is added, I get a stack empty error.

Second question, the following initialization turns off the LEDs and appears to stay the LOWERED state waiting for an up command, but the red LED does not turn on and the servo is not initialized.

----
: INITIALIZE
32767 PWMB1 PWM-PERIOD
YELLED OFF REDLED OFF GRNLED OFF
INSTALL POWER-LAPTRAY
LOWERED SET-STATE
;
---
for reference LOWERED follows:

IN-STATE
LOWERED
CONDITION
PB0 OFF? AND
CAUSES 6000 SERVO1
REDLED OFF
GRNLED ON
THEN-STATE
RAISED
TO-HAPPEN
---

As I mentioned, this program works okay, I am just wondering about these two details,
thanks,
Mark

RMDumse
08-03-08, 03:35 PM
Hi,
but I'm wondering why it does not need another AND at the end of the fourth line.

------------------
IN-STATE
RAISED
CONDITION
PB1 OFF? AND PB0 ON? AND
CAUSES 4000 SERVO1
REDLED ON
GRNLED OFF
THEN-STATE
LOWERED
TO-HAPPEN
--------------


Remember, reverse polish notation. Value (nouns) go on the stack first then actions relating them (verbs) follow.

So 1 2 + to add two number on the stack and -1 -1 AND to and two number on the stack.

So the problem isn't the AND on the end, it's the extra AND in the middle.

PB1 OFF? PB0 ON? AND

is the proper way.

Second question, the following initialization turns off the LEDs and appears to stay the LOWERED state waiting for an up command, but the red LED does not turn on and the servo is not initialized.

----
: INITIALIZE
32767 PWMB1 PWM-PERIOD
YELLED OFF REDLED OFF GRNLED OFF
INSTALL POWER-LAPTRAY
LOWERED SET-STATE
;

---
for reference LOWERED follows:

IN-STATE
LOWERED
CONDITION
PB0 OFF? AND
CAUSES 6000 SERVO1
REDLED OFF
GRNLED ON
THEN-STATE
RAISED
TO-HAPPEN
---


First, always set the state before installing the machine, so the order should be

LOWERED SET-STATE
INSTALL POWER-LAPTRAY

As soon as you install something it may run, and you might not be in a legal state yet, and you could crash your machine.

Secondly, there's that AND again.

PB0 OFF? AND

Says object PB0, method see if it is off and leave a Boolean, AND with whatever mystery thing happens to be on the stack that I didn't put there.

You were fine up til the AND which is superfluous.

PB0 OFF?

will feed the boolean of CAUSES as it is without the AND. Your probably accidentally ANDing with a ZERO which prevents the condition from firing.

Thirdly you've asked why the REDLED doesn't turn on. Both times you reference it in the code you're doing REDLED OFF. Maybe you meant the GRNLED didn't turn on?

Mark Bresler
08-05-08, 10:22 AM
Hi,
per your suggestion I took out the AND statements and it works fine. (It also does not crash after a few minutes) I was trying to imitate the code used in the toy traveler program you sketched in December 2006 where there was an AND statement used in this line:
DELAY COUNT PA0 ON? AND
looking more closely at that line, the condition was that the count had expired and PA0 was on, so I had not taken the whole line in context.

The machine still does not initialize at the start, I am using

: INITIALIZE
32767 PWMB1 PWM-PERIOD
YELLED OFF REDLED OFF GRNLED OFF
LOWERED SET-STATE
INSTALL POWER-LAPTRAY
;
I am thinking of leaving this as it is, letting the user move to the initial state after power up when they are ready.

I am using my old IsoPod board to developed a prototype, but am interested in using the IsoPod SR1 running off of a 12 V sealed lead acid battery in the final version. I don't seem to find information about the switching regulator, such as efficiency and how much 5 V power is available for peripherals.
Thanks,

RMDumse
08-05-08, 03:22 PM
Maybe I'm confused, what do you expect to happen?

Looking at the code, being in the lowered state, nothing happens (that's the nature of a wait) until the condition is met.

IN-STATE
LOWERED
CONDITION
PB0 OFF? AND
CAUSES 6000 SERVO1
REDLED OFF
GRNLED ON
THEN-STATE
RAISED
TO-HAPPEN

So leaving the AND off, until PB0 OFF? condition is true, the action in the CAUSES - THEN-STATE doesn't execute.

Once PB0 goes low, the code 6000 SERVO1 REDLED OFF GRNLED ON executes once before going to the RAISED state.

If you want an action before entering a state, you need to do it explicitly in your initialization, because once in a state no action happens (because a state means to stand still without action).

You can force an action by putting an action into the CONDITION - CAUSES phrase, but that changes from a Mealy model to a Moore model, where being in the state causes the action, but that's rather an advanced state machine programming concept.

[QUOTE]I am using my old IsoPod board to developed a prototype, but am interested in using the IsoPod SR1 running off of a 12 V sealed lead acid battery in the final version. I don't seem to find information about the switching regulator, such as efficiency and how much 5 V power is available for peripherals.
Thanks,

We made our own switching regulator for a while, but found a TI module that could drop right in and probably did a better job. It's rated at 1A, so you've got ~750mA for peripherals.

Mark Bresler
08-08-08, 07:47 PM
OK thanks for the info. I will buy a IsoPod SR1. I am not sure we will use a servo mechanism, due to friction it was constantly hunting for it's null point, so we may go with another actuator type.
Thanks again,
Mark

RMDumse
08-08-08, 08:24 PM
So are you interesting in making your own servo? where you can control the deadband and response, etc.?

Mark Bresler
08-11-08, 06:30 AM
So are you interesting in making your own servo? where you can control the deadband and response, etc.?

I was thinking of a lead screw with nut and limit switches, but am not thrilled with the prospect of building and adjusting the limit switches, so if you have alternatives I am open to suggestions.
Thanks,
Mark