New project with Mini Maestro 18

I am using a Mini Maestro 18 with a Hitec HS-785HB servo connected to CH0.
2 Push buttons, A & B, are connected to CH1 & CH2 respectively.

What I want:
Every time button A is pressed - servo must index 60 deg forward. (from where it is)
Every time button B is pressed- servo must index 60 deg backward. (from where it is)
If both buttons are pressed similtaneously , nothing must happen.

This is the code I’m working with:

begin
  button_a if sequence_a endif
  button_b if sequence_b endif
  
 repeat 
 
sub button_a
  1 get_position 500 less_than
  return
 
sub button_b
  2 get_position 500 less_than
  return
 
 
sub sequence_a
  6000 0 servo 1000 delay
  
  return
   
sub sequence_b
  2000 0 servo 1000 delay
  
  return

This code allows the servo to go to one position only with button 1 pressed and returned to start position with button 2 pressed.

Can someone help me with the required corrected code?

I have a new project using your Mini Maestro18, 1 Hitec HS-785HB servo and 2 push buttons.
Servo on CH0
Push Button A on CH1
Push Button B on CH2

Sequence:
Each press of Push button A - servo moves 60 deg forward.
Each press of Push button B - servo moves 60 deg backward

Can someone perhaps help me with the code

Hello.

I combined your posts since they seemed to be about the same thing.

It looks like you are off to a good start. The next step I would try to accomplish is having your sequence_a and sequence_b subroutines move the servo relative to where it is, instead of sending it to a hard-coded location. You can do that by using the get_position variable and then adding (or subtracting) a value from that. The value to move the servo 60-degrees is something you will probably need to find by trial and error. However, with some specs I found with a quick internet search, I think 37.5 microseconds (or 150 quarter-microseconds in the script) will be close. For example:

sub sequence_a
  0 get_position 		#get the current position being sent to channel 0
  150 plus		#add 150 to it
  0 servo 1000 delay	#set that as the new position
return

To change the direction (e.g. for sequence_b) you would change the plus to a minus.

One problem this could bring up is that when you first power the Maestro, it probably won’t be sending signals to channel 0, which might result in unwanted behavior. To fix this, you can configure the “On startup or error” setting for channel 0 to “Go to” and specify a position in the “Channel Settings” tab of the Maestro Control Center. Alternatively, you could send an initial position before entering the loop of your script, like this:

6000 0 servo		#initial position

begin
  button_a if sequence_a endif
  button_b if sequence_b endif
 repeat 

If you try adding that part and run into any problems, could you post an updated version of your code with a description of the problem?

Brandon

Thanks for your help. My servo is working perfectly.
My only problem now has nothing to do with the Maestro.
The servo lacks the torque to shift the gear mechanism that I’m trying to control.
Previously I was using a 12v geared dc motor controlled by a timing circuit which worked fine but expensive to make.
I don’t suppose you can advise me on how to use the maestro to give out a very precise programmable one shot timing pulse instead of controlling a servo motor

Hi Brandon,
I forgot to mention that I control the dc motor through an L298N motor driver bridge.
So I figured that I could possibly use the Maestro to give me precise one shot pulses

Do you only want a single pulse? If you are trying to control a motor driver, you might be able to use the Mini Maestro’s PWM output channel. However, please note that with a simple DC motor, you will not have the position control that servos provide without adding your own feedback system.

Brandon

Hi Brandon,
Yes I understand that - I’ve been a robotic / CNC engineer all my life.
What I want is to be able to have a controlled timed pulse output from each push button.
I will be using 2 outputs for each push button.
1 output will be for direction and the other for “ run”.
Also I want the output pulse (which will be in the order of about 2 ms to be variable according to a pot wired to another input.
This for both directions.
My dc motor is actually a motor gearbox.
By sending a short pulse to the motor I have in the past, achieved a final rotation of 60deg with surprising accuracy - but with a ver complicated timing circuit.
This is why I figured that using the maestro to provide the pulse rather than the timing circuit I have very accurate programmable control.
The pots would give me adjustment to overcome the backlash of the gearbox.
So in a nutshell, I will use the existing code for the push buttons but instead of a servo output, I want to use digital outputs.
BTW what code would I use to send an output on or off after configuring the a ch as an output?
Regards
Edwin

You might be able to generate a controlled pulse by using a digital output and writing a custom script; however, you will probably have to experiment with it to see if it is precise enough for your application. The servo command is still used to control a Maestro channel when it is configured as an output. Instead of indicating a pulse width, the position value of an output channel is used to control whether the output is low or high; it is low unless the position value is greater than or equal to 1500μs.

Ultimately, though, the precision you’re looking for might be hard to get with a Maestro, so you might need a more general purpose microcontroller or something else more suited for that.

Brandon