Coding and power supply for 12 CH Mini

Hi,

I am using the 12 CH Mini to power a model dragon I built. Here is the code I wrote to perform a few bodily movement routines. A joystick moves the head and a button wags the head. A second button trips a relay for a sound effect. Finally, a motion sensor activates a preprogrammed movement of the head.

#MASTER
begin
  fire  
  head_control
  tail
  motion_detector
repeat


### analog servo control
sub head_control
  
    1 get_position
    4 times 4500 plus  #x axis, lower number looks to her left
    6 servo
    2 get_position
    4 times 2500 plus  #y axis, lower number is higher head level
    7 servo
  return




Sub fire
  10 get_position 500 less_than
  if 
    7000 9 servo
    1000 delay
    5000 9 servo  #this 4000 value may need to be lower
  endif
  return

###TAIL WAG##
#TAIL MOVEMENT

#Moves servo in a sine wave between 1 and 2 ms
sub tail

  5 get_position 500 less_than
  if 
  
    8000 8 servo
    100 delay
    4000 8 servo
    200 delay
    8000 8 servo
    200 delay
    4000 8 servo
    200 delay
    8000 8 servo
    200 delay
    4000 8 servo
    300 delay
    8000 8 servo
    400 delay
    4000 8 servo
    400 delay
    8000 8 servo
    400 delay
    6000 8 servo
  endif
return

###MOTION DETECTOR

sub motion_detector
  0 get_position # gets position of detector from 0 to 1023
  100 less_than  #test whether it is less than 512 -> 1 if true, 0 if false
  if
    6500 6 servo
    5000 7 servo
    1000 delay
    5000 6 servo
    6500 7 servo
    1000 delay
    6500 6 servo
    5000 7 servo
    1000 delay
    5000 6 servo
    6500 7 servo
    400 delay
    8000 9 servo
    1000 delay
    4000 9 servo
    6500 6 servo
    5000 7 servo
    1000 delay
    8000 9 servo
    1000 delay
    4000 9 servo 
  else
  endif
return

The problem I have is that the routines do not run simultaneously, meaning the head cannot be moved with the joystick while the tail is wagging. Is there a way to overcome this through a different code?

The other problem I’m having is a lot of “misfires” by the motion sensor. The input from the motion sensor jumps around a lot even with nothing in front of it. I don’t know if it considered “noise” or what. The problem is bad when the servos are moving a lot. I’m wondering if it could be the result of a voltage or current drop. I am using a 5V regulated 2-AA cell power supply. I could substitute in a 4-AA cell power supply, which would be 6 volts. Can the Mini handle 6 volts or is it better to keep the regulated 5 volt one? Does this sound like a voltage drop problem?

Thanks!

Hello,

The Mini Maestro can operate with a Vin of up to 16V, as it says in the product specifications. So your 6V battery should be fine. Do you have a separate power supply for the servos? What kind of motion sensor are you using, and how are you activating the relay? In general, if you want to debug problems, you should simplify your system to the smallest possible system that demonstrates the problem, to help you identify the problematic components.

As for your idea of doing multiple motion sequences at the same time, that requires some advanced coding, but it should be possible. Basically, you will need to re-write the main loop so that the subroutines called from the main loop always return quickly, even while running a motion sequence, which means that any state will need to be stored on the stack somewhere. One trick for doing this easily is to set up global variables. See this forum post for some example code showing how to get that to work; maybe that will give you some ideas.

By the way, can you post any pictures? A Maestro-powered dragon sounds really fun.

-Paul

Hi Paul,

I see, that does sound complicated. A lot of peeking around the stack and keeping track of where the values are. That’s pretty much what I was afraid of. I’ll give it a try, but this has to be on display on the 26th, so I might run out of time.

Thanks for confirming the voltage. I wanted to make sure since I read some posts about chips getting fried by reversing the polarity, etc. I did what you suggested. Each of my subroutines were tested individually and they work well. It’s when I combine them into the master program that I have difficulty.

When I get the head banging around (2 servos), the motion sensor starts to wig out. I can see the red light on the back of it start to flicker very quickly as if it is being triggered, even with nothing infront of it. It is the “Pololu Carrier with Sharp GP2Y0D805Z0F Digital Distance Sensor 5cm”.

I use the 5V regulated supply for the servos. I have used the jumper in hopes of having it power the Mini as well, which works, although I do note that if I am rocking the servos pretty hard, the red light on the board comes on. Also, I have the same problem with the motion sensor when the USB is pluggd in.

The reed relay just gets acitvated through Channel 9 as an output. I just wired it straight to the relay coil. I was concerned the Mini board might not give it enough juice to trigger it, but it did. The relay then activates a totally separate power supply to another hobby motor & LEDs.

So at this point, I really need to figure out if the motion sensor is malfunctioning b/c of a power loss and if so, what I can do about it.

Oh, and yes, absolutely, I will post some pics of it when it is done. The head still needs to be painted and I have to fix the LEDs in the eyes. It’s been a fun but tough project. Thanks!

Hello,

Your problems indicate that you do not have a sufficient power supply. Most 5V regulators will not provide enough current for servos; you need 1-2A per servo. Do you have that much available? Even if the power is enough for the servos, they might cause noise or variation on the 5V line that could be resetting your Maestro and distance sensor, so I highly recommend using either separate supplies for Vin and servos or a voltage of greater than 5V so that the Maestro’s regulator can keep the 5V level constant.

-Paul

Thanks Paul, I increased the voltage by using the 4AA power pack instead and it seems to have solved the motion sensor problem.