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

Pololu Forum

Halloween Prop

Hello, I have a Halloween prop controlled by a Maestro Micro with two Sg-90 servos. I’d like the servos to return to a certain position when power is cut to the Micro. Is that possible? Here is the prop. https://youtu.be/C01ejF1mFlE

Thank you for your interest in our Maestro. You might be able to set up a system using the Maestro, a momentary button and one of our push button power switches to tell the Maestro to move the servos to a home position and then power itself down, but if you are concerned with unintended power outage or something abrupt like that, the Maestro cannot send any signals to your servos when it is un-powered.

-Derrill

Derrill, thanks for the response. My main concern is the prop showing the incorrect address on power down. Since the props are all on a timer, what if I just wrote a script that went on for X amount of time then settles on the “0’s” until it powers down?

Your plan seem reasonable.

-Derrill

Derrill,
I am still a complete noob at this. I usually have the display on a timer for 5-6 hours. How would i be able to write a script for this? If I had it run for 4.5 hours then have the servos stop moving for a 1/2 hour, before the power shuts off. I would appreciate any help.

Best,

Rudy

Hi, Rudy.

There are probably a number of ways you could do something like that. For example, you could store a number on the stack that you increment up each time your sequence finishes, then have the Maestro send the servos to some home position when it hits the number of cycles you want. The timing might not be extremely accurate depending on your script, but your half hour window seems fine for that. If you give it a shot and have problems, can you post the code you have so far?

-Derrill

Derrill, This is what I have so far.

<!--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>
  <Channels ServosAvailable="6" ServoPeriod="156">
    <!--Period = 19.968 ms-->
    <!--Channel 0-->
    <Channel name="" mode="Servo" min="0" max="13120" homemode="Off" home="64" speed="124" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 1-->
    <Channel name="" mode="Servo" min="1984" max="8896" homemode="Off" home="1984" speed="124" acceleration="0" neutral="6000" range="1905" />
    <!--Channel 2-->
    <Channel name="" mode="Servo" min="3968" max="8000" homemode="Off" home="3968" speed="3" 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" />
  </Channels>
  <Sequences>
    <Sequence name="Sequence 0">
      <Frame name="Frame 0" duration="600">9280 1984 0 0 0 0</Frame>
      <Frame name="Frame 1" duration="3000">9280 8896 0 0 0 0</Frame>
      <Frame name="Frame 2" duration="600">9280 1984 0 0 0 0</Frame>
      <Frame name="Frame 4" duration="3000">10560 8896 0 0 0 0</Frame>
      <Frame name="Frame 4" duration="3000">12800 8896 0 0 0 0</Frame>
    </Sequence>
  </Sequences>
  <Script ScriptDone="false"># Sequence 0
begin
  1000 9280 1984 0 0 0 0 frame_0..5 # Frame 0
  6000 8896 frame_1 # Frame 1
  1000 1984 frame_1 # Frame 2
  6000 2176 frame_0 # Frame 4
repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

</Script>
</UscSettings>

I do not see any attempt to add the behavior your are describing. Can you give it a try?

-Derrill

Derrill,

I am a total noob at this and wouldn’t know where to begin. Could you point me in the right direction? At least what commands to use?

Best,

Rudy

Below is a simple script that puts the number 1 on the stack and increments it by 1 every time the begin repeat loop completes:

1
begin
  1000 delay
  1 plus
repeat

You could then add an IF/ELSE statement to check the loop count and move your servos to your home position when your code has ran through some specific number of loops (however many you want that gets you to about four and a half hours) and end the script with a QUIT command. You can see all of the commands available in the “Command Reference” section of the user’s guide.

-Derrrill

Derrill,

would I add it as a subroutine like this?

sub frame_6
1		
begin
	1000 delay
	1 plus 
repeat

Hello.

While you could add some of the code Derrill suggested in a subroutine, it would need to be done slightly differently. Instead, I suggest trying to modify your main BEGIN/REPEAT loop, which currently looks like this (from the settings you posted last week):

begin
  1000 9280 1984 0 0 0 0 frame_0..5 # Frame 0
  6000 8896 frame_1 # Frame 1
  1000 1984 frame_1 # Frame 2
  6000 2176 frame_0 # Frame 4
repeat

If you add Derrill suggestion, it would become this:

1 		#put the initial cycle count on the stack

begin
  1000 9280 1984 0 0 0 0 frame_0..5 # Frame 0
  6000 8896 frame_1 # Frame 1
  1000 1984 frame_1 # Frame 2
  6000 2176 frame_0 # Frame 4

  1000 delay 		# this delay is arbitrary/optional, you can change it based on how long you want between cycles
  1 plus			# add 1 to the number on the stack

repeat

If you run your script from the “Script” tab of the Maestro Control Center with this modified code, you should see the number on the stack (on the right side of the window) increase by one every time the script loops.

If that works correctly, you can add the IF statement to the end that checks the cycle count and, if true, moves the servos to a home position before quiting the script. For example:

  dup			#make a copy of the number on the top of the stack
    10 greater_than  if 	#check if it is greater than the number of cycles you want to run
    6000 0 servo		#move servos to starting position
    5000 delay		#delay long enough for servos to reach their starting positions 
    quit			#end script
  endif

Note that I arbitrarily chose to move servo 0 to a target position of 6000 in that example to show where you would put the code to move your servos; you will probably want to modify it to your needs.

Brandon

Brandon,

This is what i have so far

# Sequence 0
1
begin
  1000 13120 1984 0 0 0 0 frame_0..5 # Frame 0
  6000 8896 frame_1 # Frame 1
  1000 1984 frame_1 # Frame 2
  6000 256 frame_0 # Frame 4
1000 delay
1 plus
 dup			
    2 greater_than  if 	
    256 1984  0 1 servo	
    5000 delay		
    quit			
  endif
repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

Only problem right now, after it runs once, I click on “run script” in control center and nothing happens.

ok i think just needed to click restart script.

Ok, so if 40 cycles take about 10 minutes, 1000 should last about 4 hours. Please let me know if any of the script can be improved. I’d appreciate any input.

Best,

Rudy

# Sequence 0
1
begin
  1000 13120 1984 0 0 0 0 frame_0..5 # Frame 0
  6000 8896 frame_1 # Frame 1
  1000 1984 frame_1 # Frame 2
  6000 256 frame_0 # Frame 4
1000 delay
1 plus
 dup			
    1000 greater_than  if 	
    256 1984  0 1 servo	
    5000 delay		
    quit			
  endif
repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

You are correct; once you quit the script, you will need to restart it (or power cycle the Maestro) to get it to run again.

I do not see anything obviously problematic about your script, but I suspect your code for moving the servos to a “home” position is not doing what you want it to. For reference, here is the line of code I am referring to:

256 1984 0 1 servo

Right now, that line will send a target position of 0 to channel 1 (e.g. 0 1 servo), but the first two numbers it places on the stack (256 and 1984) are just left on the stack and are not used. Can you describe what you want to do with those servos at this point of the script?

Brandon

Brandon,

Servo channel 0 at position 256. Servo channel 1 position 1984. Which are the neutral positions. Funny, with if then of of a small number like two. It ends with the servos in the position I need.

Best,

Rudy

The correct code for setting servo channel 0 to 256 and channel 1 to 1984 would look like this:

256 0 servo
1984 1 servo

However, please note that both of those target positions are well outside of the standard servo pulse width range, and almost certainly outside of the range your servo can actually respond to. The standard servo pulse width range is between 1000μs and 2000μs; servos will usually respond to commands slightly outside of this range (sometimes you can stretch it to between 600μs and 2400μs, depending on your servo), Please note that some servos can be commanded to move beyond their end stop, which could permanently damage them, while other servos will stop responding to pulse width signals outside of their accepted range. The SERVO command in the Maestro script uses the units of quarter-microseconds, so you are sending those servos pulse widths of 64μs and 496μs respectively. You can find a method for safely finding the limits of your servos in the “How do I use my Maestro servo controller to get the maximum possible range of motion from my servo?” entry under the “FAQs” tab of the Maestro product page.

Brandon

Those were the limits that I could push the servos to acheive 180 degree rotation. I did a test run today and 1000 cycles was approximately 4.5 hours.