Running a motor controller on mini maestro 12

I have been working on a project utilizing 4 servos and 2 motor controllers. The 4 servos I have moving continuously through 2 different positions and I would like the 2 motor copntrollers to run synchronistically at a certain speed as the servos are moving back and forth. I’m not sure how and where to put the code for the motor controllers to accomplish this. I tried at the beggining of the script but they just start up and don’t continue as the script runs past it. Please help

Hi, which servo and which motor controller are you using?

Hello.

Please post your script you are currently running along with more details about what happens when you run it compared to what you want to happen.

Brandon

the servos I have are Robostar SBR5-5314HTG and the motor controllers are the Hobbyking Brushless Car ESC 30A.

Here is my script. Right after the initial delay I am ramping up both servo channels 4 and 5 so the motor controllers don’t burn out which has happened before. I can’t keep them running through the mainloop though. They start then shut off, start then shutoff. I don’t know if I should run a seperate sub routine for them or something.

begin
   15000 delay
   1500 4 servo 500 delay
   1500 5 servo 500 delay
   1550 4 servo 500 delay
   1550 5 servo 500 delay
   1600 4 servo 500 delay
   1600 5 servo 500 delay
   mainloop
repeat

sub mainloop
begin
  1000 7616 6784 7616 6784 6000 6000
  0 0 0 0 0 0 frame_0..11 # Frame 0 
  0 0 speed # set speed to 10 on channel 0
  0 1 speed # set speed to 10 on channel 1
  0 2 speed # set speed to 10 on channel 2
  0 3 speed # set speed to 10 on channel 3
  1600 4 servo
  1600 5 servo
  1000 6784 7616 6784 7616 frame_0..3 # Frame 1
  10 0 speed # set speed to 10 on channel 0
  10 1 speed # set speed to 10 on channel 1
  10 2 speed # set speed to 10 on channel 2
  10 3 speed # set speed to 10 on channel 3
  1600 4 servo
  1600 5 servo 
  1000 7616 6784 7616 6784 frame_0..3 # Frame 2
repeat

sub frame_0..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

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

Thank you for the additional information.

I notice a few problems with your script that should be easy to fix. The first is that your SERVO commands in the very beginning (before mainloop) are using units of microseconds instead of quarter-microseconds (which is what script expects). So, for example 1500 4 servo should become 6000 4 servo.

However, I suggest adding a really conservative acceleration limit to channels 4 and 5 in the Channel Settings tab, instead of ramping up their speed with multiple commands. If you set their acceleration to something low like 3, you should be able to just set the speed directly and let the Maestro ramp it up gradually for you. For example, something like this:

begin
   6000 4 servo  #set initial position for servo 4 and 5 so they are stopped
   6000 5 servo 

   15000 delay   #wait 15 seconds

   6400 4 servo  #set target position for channel 4 and 5 that the Maestro will ramp up to
   6400 5 servo
   mainloop #call mainloop
repeat

Next, it looks like your frame_0..11 subroutine is resetting the target for channel 4 and 5 back to 6000 quarter-microseconds (1500µs). To fix this, you can delete the two 6000 values from the first line of your mainloop, and remove the 5 servo and 4 servo lines from your frame_0..11 subroutine. So, the first line of your mainloop would look like this:

  1000 7616 6784 7616 6784
  0 0 0 0 0 0 frame_0..11 # Frame 0 

And your sub frame_0..11 would look like this:

sub frame_0..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

Lastly, I suggest removing your extra SERVO commands for channel 4 and 5 from inside your mainloop since they should not be necessary (although if you do keep them, you should multiply the target value by 4 like I described above).

Brandon

Thanks! I will give that script a shot and see how it goes.

1 Like

This is working great thanks! Having the exact movements I’m looking for! Now if I wanted to speed up the motor controllers on channel 4 and 5 for the target position should I just change the 6400 to something higher at the beggining?

I do not know much about your particular ESC and brushless motors, but typically ESCs consider 1500µs (6000 quarter-microseconds) as a neutral (stopped) position and increase the speed as the pulse width gets farther from that point. So if that is the case, increasing the 6400 target for channels 4 and 5 should cause them to speed up. You might consider testing with the sliders in the “Status” tab of the Maestro Control Center while the script is not running to find the value you want to use, just remember to multiply it by 4 for the script (since the “Status” tab shows it in units of microseconds).

Brandon

Thanks!

So the acceleration feature is kind of messing with our motorcontroller. How could I write the script so it could get up to say 6800 in 15 seconds. Would it be something like this?

6800 4 servo #set target position for channel 4 and 5 that the maestro will ramp up to for 15 seconds
6800 5 servo
mainloop #call mainloop
repeat

Thanks!

If the acceleration setting is causing problems, you might try disabling the acceleration limiting (i.e. setting it to 0) and using a speed limit of 1 instead. This will update the pulse width output at a flat rate of 0.25µs per 10ms, which means it will take 8 seconds to go from 6000 to 6800. (Please note that this is only true if you are using the default period of 20ms; if you change that, the units of the speed setting will change.)

If you want to try even slower than that, you could use a while loop like this:

#initialize servos
6000 4 servo
6000 5 servo

800 begin dup while                       #loop 800 times
  4 get_position 1 plus 4 servo    #increment the position of channel 4 by 1 (0.25µs) 
  5 get_position 1 plus 5 servo    #increment the position of channel 5 by 1 (0.25µs)
  17 delay                                           #adjust delay to change speed of ramp
  1 minus                                             #subtract 1 from loop counter
repeat

mainloop

However, please note that this loop is blocking, so your script will only move on to your main loop after it is finished ramping up.

Brandon

Thanks! I will try that. We’re manufacturing gyroscopes here and the motor controllers are controlling the gyros while the servos control the arms. When I was altering the acceleration of the motorcontrollers it seemed to pulse the signal and the motorcontrollers heated up pretty quick anmd burned out. Thank you

Hey Brandon,
The acceleration of the motor controllers works great! Now once it gets to the 6800 would it be possible to have it go to 6400 for one frame and back to 6800 for another frame of the movement? And continue doing this throughout the cycle of the script? Thanks!

I am glad to hear the acceleration is working for you. I don’t see any problems with having it move between 6400 and 6800 each frame like you described. If you try modifying your script to do this and have problems, you can post an updated version of your script, and I would be glad to take a look and see if I can give any specific suggestions.

Brandon

Here is the script I tried. I didn’t want to mess with the intial ramping up phase so I added 6400 and 6800 for servo 4 and 5 for the individual frames but it didn’t work. What should I try instead?

#initialize servos
6000 4 servo
6000 5 servo

15000 delay

800 begin dup while                 #loop 800 times
  4 get_position 1 plus 4 servo #increment the position of channel 4 by 1 (0.25µs)
  5 get_position 1 plus 5 servo #increment the position of channel 5 by 1 (0.25µs)
  17 delay                             #adjust delay to change speed of ramp
  1 minus                               #subtract 1 from loop counter
repeat
   


sub mainloop
begin
  600 7616 6784 7616 6784
  0 0 0 0 0 0 frame_0..11 # Frame 0 
  0 0 speed # set speed to 10 on channel 0
  0 1 speed # set speed to 10 on channel 1
  0 2 speed # set speed to 10 on channel 2
  0 3 speed # set speed to 10 on channel 3
  6400 4 servo
  6400 5 servo
  600 6784 7616 6784 7616 frame_0..3 # Frame 1
  10 0 speed # set speed to 10 on channel 0
  10 1 speed # set speed to 10 on channel 1
  10 2 speed # set speed to 10 on channel 2
  10 3 speed # set speed to 10 on channel 3
  6800 4 servo
  6800 5 servo
  600 7616 6784 7616 6784 frame_0..3 # Frame 2
repeat

sub frame_0..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

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

I see that it probably won’t work with becasue 4 and 5 servos aren’t listed in the sub frames, but I’m not sure how to add it to the initialization.

I tried this as well by putting the values I want at the end of the intialization but it seemed to skip the ramp up phase and tried to go right to full speed.

#initialize servos
6000 4 servo
6000 5 servo

15000 delay

800 begin dup while                 #loop 800 times
  4 get_position 1 plus 4 servo #increment the position of channel 4 by 1 (0.25µs)
  5 get_position 1 plus 5 servo #increment the position of channel 5 by 1 (0.25µs)
  17 delay                             #adjust delay to change speed of ramp
  1 minus                               #subtract 1 from loop counter
6400 4 servo # frame 1
6400 5 servo # frame 1
6800 4 servo # frame 2
6800 5 servo # frame 2
repeat

It is not clear to me from your description or your code how you are wanting it to work. So, before getting into specific suggestions, I’d like to better understand your goal.

It sounded like you wanted the outputs on those channels to oscillate between two values on each frame. However, right now you have 3 frames, so for example if you have them set to 6800 in frame 0, then 6400 in frame 1, and back to 6800 in frame 2, the script will loop back to frame 0 and it will stay at 6800. Since you have an odd number of frames, to have the values alternate each frame you would probably need to do something a bit more complicated (such as having a separate subroutine that reads the current value and toggles it to the other one when it is called). So, can you clarify which of those behaviors you are trying to achieve, and if you want to hardcode the values, which values do you want each frame to use?

By the way, I am not sure how you expected that modification to the ramping code to work, but please note that this part of code only runs once before your main loop starts, so it will not ramp the outputs on those channels every time they are commanded to change. Also, the way you modified it will essentially break the ramping code and rapidly switch the outputs from 6400 to 6800 each time through the 800 cycles.

Brandon