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

Pololu Forum

Using Acceleration Wrong?

I found a script on here that I’m using for my Ironman helmet.

servo_reset
eyes_off
servo_reset
main_loop
quit

sub servo_reset
		#reset servos to mid position
		500 delay
		-2000 2000 set_servos
return
sub servo_gate_open
		#move servos in the opposite direction
		500 delay
		4000 8000 set_servos
return
sub servo_fin_right
		#move both servos to the left
		500 delay
		2000 -2000 set_servos
return
sub set_servos
		#consume two stack values to run servos
		1 servo 0 servo
return

## lights

sub eyes_on
		8000 2 servo
	return

sub eyes_off
		2000 2 servo
	return

sub main_loop
#Test function: control light with a button
	begin
    wait_for_press
    led_on
    #arc_on
    1000 delay
    servo_fin_right
    500 delay
    eyes_flicker
    eyes_on
    led_off
    wait_for_press
    led_on
    eyes_off
    500 delay
    servo_reset
    500 delay
    #arc_off
    led_off
	repeat
return

sub wait_for_press
		wait_open
		wait_close
return

sub wait_open
  get_ms
  begin
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
    if drop return endif
    endif
  repeat
return

sub wait_close
  get_ms
  begin
  button
  if
    get_ms over minus 10 greater_than
  if drop return endif
  else
    drop get_ms
  endif
  repeat
return

sub eyes_flicker
  eyes_on
  20 delay
  eyes_off
  180 delay
  eyes_on
  40 delay
  eyes_off
  160 delay
  eyes_on
  80 delay
  eyes_off
  120 delay
return

sub button
		3 get_position 511 less_than
return

I wanted to adjust the speed and acceleration so I thought I could add

0 10 ACCELERATION
1 10 ACCELERATION 

To set the two servos. However this doesn’t work. The result is that only one servo works. The other does nothing. What am I doing wrong if I want to set the ACCELERATION for both servo 0 and 1?

I moved your post to the Servo controllers and servos section of the forum since it is more appropriate for questions pertaining to the Maestro.

If you are trying to set the acceleration of servo channels 0 and 1 to a value of 10, the order of your arguments is not correct. It should be:

10 1 acceleration
10 0 acceleration

However, please note that the problem you described (e.g. one servo not working) would not have been caused by that error. Instead, that would have just caused the Maestro to change the acceleration of servo channel 10.

By the way, if you do not need the acceleration to change throughout the script, you could just configure it for those channels in the “Channel Settings” tab of the Maestro Control Center instead of the script.

Also, it looks like you posted the unmodified script (before you added the commands) so it is hard to debug any further. If you continue to have problems can you post your updated script as well as your Maestro settings file? You can save your Maestro settings file through the “File” drop-down menu of the Maestro Control Center while the Maestro is connected.

Brandon

Thank you Brandon,

I updated the script to use
10 1 acceleration
10 0 acceleration

However it has a similar result. One servo moves the other does not.maestro_settings.txt (3.0 KB)

10 0 acceleration
10 1 acceleration
servo_reset
eyes_off
servo_reset
main_loop
quit

sub servo_reset
		#reset servos to mid position
		500 delay
		-2000 2000 set_servos
return
sub servo_gate_open
		#move servos in the opposite direction
		500 delay
		4000 8000 set_servos
return
sub servo_fin_right
		#move both servos to the left
		500 delay
		2000 -2000 set_servos
return
sub set_servos
		#consume two stack values to run servos
		1 servo 0 servo
return

## lights

sub eyes_on
		8000 2 servo
	return

sub eyes_off
		2000 2 servo
	return

sub main_loop
#Test function: control light with a button
	begin
    wait_for_press
    led_on
    #arc_on
    1000 delay
    servo_fin_right
    500 delay
    eyes_flicker
    eyes_on
    led_off
    wait_for_press
    led_on
    eyes_off
    500 delay
    servo_reset
    500 delay
    #arc_off
    led_off
	repeat
return

sub wait_for_press
		wait_open
		wait_close
return

sub wait_open
  get_ms
  begin
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
    if drop return endif
    endif
  repeat
return

sub wait_close
  get_ms
  begin
  button
  if
    get_ms over minus 10 greater_than
  if drop return endif
  else
    drop get_ms
  endif
  repeat
return

sub eyes_flicker
  eyes_on
  20 delay
  eyes_off
  180 delay
  eyes_on
  40 delay
  eyes_off
  160 delay
  eyes_on
  80 delay
  eyes_off
  120 delay
return

sub button
		3 get_position 511 less_than
return

There are definitely some problems with the script you posted. In particular, the servo reset and servo_fin_right subroutines try to set the position of the two servos to combinations of 2000 and -2000. The Maestro scripting language uses units of quarter microseconds when setting the target position, so the standard servo pulse width range of 1000-2000 microseconds is equivalent to 4000-8000 quarter microseconds. Negative values are not valid and values beyond the Min and Max settings configured in the “Channel Settings” tab of the Maestro Control Center (in microseconds) are constrained.

It sounds like you found the script somewhere and it was not written by you or for your particular setup; is that the case? If so, you will likely need to do a lot of testing and tuning to get it to work for you. I do not have any specific suggestions, since it is not clear from the code what it is trying to do. For example, the comments in the servo_reset subroutine say that it is intended to put the servos back to the mid position, which would be 6000 quarter microseconds (1500 microseconds), but it looks like it is trying to move one servo to one side and one servo to the other side. Additionally, the positions used by the original creator likely will not work for your application since they depend on several factors, such as the model servo used, their orientation, the position of the servo horn relative to the spline, and the mechanics of the system.

Please note that driving servos into a physical barrier and stalling them can quickly damage them, so while you are testing (especially with scripts that you did not write) I would recommend not having them connected to a setup that could cause them to stall.

If you try reworking the script to work for you and run into specific questions, I would be happy to help.

Brandon