Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Maestro 12 channel with sensor at start

I would like to start my sequence after 10 pulses of a position sensor but I can’t get it to work.
this is the script I entered.

10 
Begin 
Dup 
While 
2 get_position 
300 less_than 
1 minus 
Repeat

can you tell me the right script to insert? thanks

Hello.

It looks like all you need to do is add a if statement before your 1 minus line and a corresponding endif after it. You can find more information about how to use if structures in the Maestro scripting in “The Maestro Scripting Language” section of the Maestro user’s guide.

-Patrick

I tried this script but it doesn’t work:
10
Begin
Dup
While
If
2 get_position
300 less_than
1 minus
Endif
Repeat
Can you help me? Please.

Hello.

In the Maestro scripting language the if should come after the test, in this case the line with 300 less_than, not before. So your code should look like this:

10
Begin
Dup
While
2 get_position
300 less_than
If
1 minus
Endif
Repeat

-Patrick

I’m sorry but this way it doesn’t count down from 10 to 0 but at the first impulse it receives the stack goes to 0 and the program continues.

Hello.

It sounds like you need to add something to your code to prevent your loop from quickly iterating ten times while the signal from your position sensor is low before it has a chance to go high again. The simplest way to do this would be to add some delay inside of your if condition that allows enough time for the pulse to pass.

-Patrick

I’m afraid of not being able to find a delay that goes well at the start and at high speeds. One solution would be to add less_than, a greater_than so that it subtracts to the stack only when it is first low and then high, but I don’t know how to insert it in the script.

Hello.

One way to implement something that does that is by nesting a while loop inside your if statement that makes your program wait for a high signal before exiting your if condition. That way, you know the signal will be high when your main loop repeats. Here is an example of how that might look:

10
begin
dup
while
     2 get_position
     300 less_than
     if
          1
          begin
          dup
          while
               2 get_position
               300 greater_than
	if
	     1 minus
	endif
          repeat
     endif
     1 minus	
repeat

Hello Patrick,
In this case if i start with the sensor with the high signal it does nothing and the stack remains at 0. While if I start with the low signal (therefore sensor active), the stack is at 10 but then every time it goes off in the stack it starts to count the negative seconds that pass before the sensor is reactivated and saves the seconds (for example, if 3 seconds pass -3000) in the topmost position of the stack.

Hello.

It looks like the last script Patrick posted has a bug in it; this modified one should essentially do what he was describing:

10
Begin
     Dup
     While
          2 get_position
          300 less_than  
          If
               1 minus
               50 delay         #small delay for debouncing purposes
               begin 
                    18 get_position 300 less_than while       #while the sensor is low stay in this inner loop
               repeat
          Endif
Repeat

Brandon