Hi Everyone - first time playing with Pololu products - feels very useful.
Struggling a bit with the scripting language and calling subroutines. Yes, I’ve read the documentation. Conceptually what I’d like to achieve is:
Push button
move 20 servos to one extent of travel - subroutine called “folding”
put 3 on stack
while loop that calls subroutine named “flap” that moves servos from one extent to the other and back with some delays
decrement counter
stop when counter reaches 0
I can get discrete pieces to work: i.e. button push creates action, subroutine that moves all servos to various positions - but when I try an put it all together I get errors. Conceptual help welcomed
Adam
1 Like
Hello.
Conceptually, your plan sounds fine, but it is hard to give any useful advice without more specific information about your script and the errors you’re getting. In case it helps, here’s a quick example of what your pseudocode might look like as a Maestro script:
begin
0 get_position 500 less_than if #check if button on channel 0 is pressed
folding
3 begin dup while #while loop using an initial counter of 3
flap
1 minus #decrement counter
repeat
drop #drop unused counter value
endif
repeat
sub folding
#put code for your "folding" subroutine here
return
sub flap
#put code for your "flap" subroutine here
return
If you continue having problems, could you post a copy of your Maestro settings file? You can save a copy of your settings file from the “File” drop-down menu of the Maestro Control Center software while the controller is connected.
Brandon
1 Like
I was really close! didn’t have the endif or the drop. let me poke at it tonight!
thanks tons
AG
2 Likes
Brandon -
Ok that helps a lot - but does not quite work.
- I would like the button push to trigger a sequence - as written it requires the button to be held down.
- My subroutine folding just moves all the servos to a neutral position - it works
- My subroutine flapping is more complex, and I don’t think I’m doing something correctly. I’m using actuonix linear servos (standard PWM). But they are geared, so full travel takes roughly 6 seconds. The effect I am trying to achieve is the following:
begin servo 1 moving from fully retracted to fully extended. (6.2 seconds travel)
with a 250 ms delay, begin servo 2 moving from fully retracted to fully extended.
and so forth for 20 servos.
As each servo reaches its fully extended position, I’d like it to reverse and begin moving toward fully retracted.
This entire cycle to repeat 3 times.
Is this level of complexity may be beyond the scripting capability on the board and should I move to using an Arduino to control the Maestro?
thanks so much,
Adam
The way my code is written in my previous post, a single push of the button should call the folding
subroutine then call the flap
subroutine 3 times before waiting for a button press again to start the same sequence; you should not need to hold the button down.
From your description it sounds like the Maestro should be able to handle that kind of application. If you post a copy of your Maestro settings file as I suggested in my previous post, I can offer some more helpful suggestions (instructions for saving a copy of your settings file can also be found in my previous post).
Brandon
It looks like you tried to attach the file but something went wrong; could you try again? If you’re having problems attaching the file to your reply, you can also open the file, copy all the text, and paste it in your reply.
Brandon
So strange. I did that and it appears In-line in my email. Will poke when i land…
It sounds like you’re responding to the forum thread through email; unfortunately, attachments will not come through when responding via email like that. So, you will need to go to the forum thread and reply directly.
Brandon
1 Like
Brandon - perhaps this is better I am pasting all the settings file and code - but it is reducing it to a single line:
<!--Pololu Maestro servo controller settings file, http://www.pololu.com/catalog/product/1350-->
<UscSettings version="1">
<NeverSuspend>false</NeverSuspend>
<SerialMode>UART_FIXED_BAUD_RATE</SerialMode>
<FixedBaudRate>9600</FixedBaudRate>
<SerialTimeout>0</SerialTimeout>
<EnableCrc>false</EnableCrc>
<SerialDeviceNumber>12</SerialDeviceNumber>
<SerialMiniSscOffset>0</SerialMiniSscOffset>
<EnablePullups>false</EnablePullups>
<Channels MiniMaestroServoPeriod="80000" ServoMultiplier="1">
<!--Period = 20 ms-->
<!--Channel 0-->
<Channel name="" mode="Input" min="0" max="1024" homemode="Ignore" home="0" speed="0" acceleration="0" neutral="1024" range="1905" />
<!--Channel 1-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 2-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 3-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 4-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 5-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 6-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 7-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 8-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 9-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 10-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 11-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 12-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 13-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 14-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 15-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 16-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 17-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 18-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 19-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 20-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 21-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 22-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
<!--Channel 23-->
<Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="0" acceleration="0" neutral="6000" range="1905" />
</Channels>
<Sequences />
<Script ScriptDone="true">
begin
0 get_position 500 less_than if #check if button on channel 0 is pressed)
folding
3 begin dup while #while loop using counter of 3
flap
1 minus #decrement counter
repeat
drop #drop unused counter value
endif
repeat
sub folding
4000 1 servo
4000 2 servo
return
sub flap
8000 2 servo
250 delay
4000 2 servo
return
</Script>
</UscSettings>
1 Like
That works! It was all there, but I edited your post to include code tags so it is visible.
It looks like your flap
subroutine is only programmed to move a single servo right now, which is probably a good starting point. However, it does not look like you’re taking into account the 6.2 seconds your actuator takes to travel to its full stroke. For a single servo, your flap
subroutine should look something like this:
sub flap
8000 2 servo #extend servo
6200 delay #wait for servo to reach fully extended position
4000 2 servo #retract servo
6200 delay #wait for servo to reach fully retracted position
return
You should also consider adding 6200 delay
to the end of your folding
subroutine to make sure they have time to fully retract before the flap
subroutine gets called.
To expand that to 20 servos staggered by 250ms, it would probably be beneficial to use a while
loop since most of the code is repeated aside from the servo channel, for example:
sub flap
#loop through servo channels extending one every 250ms
1 begin dup 21 less_than while
dup 8000 swap servo
250 delay
1 plus
repeat
drop
#looping through all 20 servos takes about 5 seconds,
#so wait an additional 1.2 seconds to allow the actuators
#to fully extend beore retracting
1200 delay
#loop through servo channels retracting one every 250ms
1 begin dup 21 less_than while
dup 4000 swap servo
250 delay
1 plus
repeat
drop
return
Brandon