Random Movement to specific routine

I have been using the micro maestro for a couple of years now in an animatronic Halloween display with great success but have realized I am not utilizing the full potential of this powerful little controller. Up til now I had used the slider controls to adjust the servo positions and then saved the frame and then copy that routine to the micro so it would automatically run on start up. Since I was able to get almost three minutes worth of frames with 6 servos, I felt the head movements (servos are in 3 axis heads) would look random to the audience.
This year i want to step it up. I have began reading thru the Maestro Scripting Language and feel confident that I can make this vision a reality. This is what I plan to do:
I have two witches whose movement are controlled by Micro maestros (one each). Each witch has 3 servos for head movement (Nod/Pan/Tilt) one with has 3 servos for eye movement (nod/pan/eyelid) and the other has two for finger movements. I would like these servos to move randomly.
In front of the witches will be a button. When the button is pressed the witches will both turn their heads to look at the “button pusher”. After a designated amount of time, they will return to the random pattern until the button is pushed again.
I know I can program the “button” sequence with a “goto” command. What I want to know is how to program random movements into the micro. Is it even possible? As well, the Witch Scene is controlled by a Picaxe 18M2. I can have the Picaxe set one pin high when the button is pushed. However, that may mean eating up one of the servo pins, correct? My other option is to do a serout command on the picaxe TX to the micro RX. However I am unsure of what specific command to give the micro to "goto’ the button push routine. Any help would be appreciated.
thanks in advance!

Hello.

That sounds like a fun project! If you want your Maestros to behave randomly, you could designate an unused channel as an input, and read the a few of the least-significant bits. That would give you a few bits of randomness, but it would eat up one of the servo pins. Regarding your other question, you could use the “Restart Script at Subroutine” serial command, which is documented in the Maestro user’s guide. When a button is pressed, the Picaxe microcontroller could send that command to the Maestros in order to make the witches look in a particular direction.

Yes, if you designate a pin as an input then you cannot use it to drive servos. You should consider getting a Maestro with more channels:
pololu.com/catalog/product/1352

–David

Thanks for that, David, read over that section again. In fact, I have been re reading the User’s guide. I think I can get away with the routine already downloaded onto the maestro, if I add the sub routine. If I understand this correctly, I just go through the script, count up the number of subroutines and add that number to the end of the command.
A couple more questions. If I want to send a serial command to two maestros, I would connect the appropriate pin of the microcontroller to the RX line of one maestro, then from the TX of that maestro to the RX of the second, DaisIy chain style, correct?
As well, i know the importance of connecting grounds together. I am using a computer power supply (CPS) for the witches (I need both 5V and 12V and, of course, enough amps to run 12 servos) and I was getting a voltage drop when I fired it up, which caused the maestros to reset. I had to power the maestros using wallwarts and power the servos with the cps. Now with linking the maestros (wallwart) with the microcontroller (cps) do I still have to connect the grounds?
thanks again

No, that would not work. To use the “Restart Script at Subroutine” command, first decide what subroutine you want to call, then count the number of subroutines that are defined before that one. That will be the subroutine number that you enter into the command.

No, that would not work. You should connect all GNDs, then connect the TX of the microcontroller to the RX of both Maestros.

Unless you are doing something very advanced, all the grounds in your system need to be connected somehow. It is usually OK if the connection is indirect, but it needs to exist.

–David

Just so I am understanding this clearly. even though I am using seperate Wall warts to power two maestros, I can still connect those two boards 0V to the 0V of a cps. Sorry for stating what may be obvious to others. Making sure I don’t release the magic blue smoke.
i read further in and saw I have to connect the rx lines.

Yes, that is correct. --David

I am waiting for some hardware to arrive so I can move forward on this project. In the meantime I have been reading thru the Maestro User’s guide, specifically the sections on Serial Interface and Scripting Commands. I must admit that it is a bit Greek to me. While I am familiar with Picaxe programming (which appears to be a variation of Basic Stamp), it is only slightly above a novice’s knowledge. While I have no intention of becoming a master programmer, I like to understand what (and why) I am doing something, as opposed to just “mimic-ing”. Is there any info, either here or on the web, where I can gain more knowledge on these protocols?

The primary thing to understand is that a byte is simply a number between 0 and 255, and doesn’t inherently contain any information about characters or letters. Next, you need to understand that a serial or virtual serial interface allows you to send and receive these bytes from a device. There is no inherent grouping of bytes, but we can design a protocol that defines commands as groups of particular bytes that are sent consecutively. I don’t have any particular resources to recommend for learning more, but maybe some community members will chime in and help you.

–David

Thanks David, I will muddle along and try to assimilate. Onward and upward!
I finally have all the hardware constructed for this project and can get down to the programming.
Here is what I am trying to do: I have a three axis animatronic head (nod/tilt/pan) which also has 2 axis eyes (up-down/ left right) and eyelids for a total of six servos. I am trying to get a “random” look to most of the movements, but I also would like a couple of “repeat” movements such as “eye blink” and “scanning the cauldron”. In trying to understand the script language, I looked at the script that resulted from my initial programming, which was simply moving the sliders on the status tab and saving frames. I noticed that the program created subroutines automatically. Here is the code (note: only three servos in this code, not six)


# Gertie Complete 2
begin
  2400 6000 6000 6000 0 0 0 frame_0..5 # Frame 0
  1800 7040 5044 frame_0_1 # Frame 1
  2000 7451 frame_1 # Frame 2
  2200 5631 6042 8000 frame_0..2 # Frame 3
  2000 4692 4672 frame_1_2 # Frame 4
  2500 delay # Frame 5
  2200 7138 5944 5984 frame_0..2 # Frame 6
  3000 4242 frame_2 # Frame 7
  2000 8000 frame_2 # Frame 8
  3300 3968 frame_2 # Frame 9
  2000 5220 3987 frame_0_2 # Frame 10
  2800 7177 6414 frame_1_2 # Frame 11
  2500 5788 4613 7882 frame_0..2 # Frame 12
  2400 delay # Frame 13
  3000 7471 frame_1 # Frame 14
  2800 7256 frame_0 # Frame 15
  2400 6003 frame_2 # Frame 16
  2500 4379 frame_1 # Frame 17
  1800 7197 frame_1 # Frame 18
  2200 5416 6101 4222 frame_0..2 # Frame 19
  2000 6864 frame_0 # Frame 20
  2000 5435 frame_0 # Frame 21
  2800 8000 8000 frame_1_2 # Frame 22
  2200 6727 frame_0 # Frame 23
  2100 5377 frame_0 # Frame 24
  2200 3968 4065 frame_1_2 # Frame 25
  2000 6003 5964 frame_1_2 # Frame 26
  2000 7138 frame_0 # Frame 27
  2700 4124 frame_1 # Frame 28
  2500 8000 frame_1 # Frame 29
  1700 5866 6336 7902 frame_0..2 # Frame 30
  2000 6982 frame_0 # Frame 31
  2000 5631 frame_0 # Frame 32
  2400 5044 5886 frame_1_2 # Frame 33
  2700 7256 frame_0 # Frame 34
  3500 7138 7236 frame_1_2 # Frame 35
  2500 4809 4770 frame_1_2 # Frame 36
  2500 4927 frame_0 # Frame 37
  2500 7001 6042 frame_1_2 # Frame 38
  1800 7099 5122 frame_0_1 # Frame 39
  2000 7471 6943 frame_1_2 # Frame 40
  2000 5377 5298 frame_1_2 # Frame 41
  2000 5612 6062 frame_0_1 # Frame 42
  2500 4046 7862 frame_1_2 # Frame 43
  2500 7941 frame_1 # Frame 44
  2200 4300 frame_1 # Frame 45
  2100 7197 frame_0 # Frame 46
  2100 7941 3968 frame_1_2 # Frame 47
  1800 5475 6649 5259 frame_0..2 # Frame 48
  2000 7001 5357 frame_0_1 # Frame 49
  2000 5240 frame_0 # Frame 50
  2200 delay # Frame 51
  1800 4300 frame_1 # Frame 52
  2200 7471 frame_1 # Frame 53
  2500 6786 frame_0 # Frame 54
  2500 5240 frame_0 # Frame 55
  2800 7334 4770 5984 frame_0..2 # Frame 56
  2700 7432 4966 frame_1_2 # Frame 57
  2200 5220 5259 7471 frame_0..2 # Frame 58
  2500 6688 4320 frame_1_2 # Frame 59
  2000 5984 5631 8000 frame_0..2 # Frame 60
  2100 6258 7667 frame_0_1 # Frame 61
  2500 5259 frame_0 # Frame 62
  2500 6806 6062 4790 frame_0..2 # Frame 63
  2200 4046 frame_1 # Frame 64
  2100 7393 frame_1 # Frame 65
  2100 4379 7725 frame_1_2 # Frame 66
  2500 7843 frame_1 # Frame 67
  2500 5651 4359 frame_0_1 # Frame 68
  2200 7393 frame_1 # Frame 69
  2500 6551 4379 frame_0_1 # Frame 70
  2500 5377 6453 4927 frame_0..2 # Frame 71
  2800 4085 5925 frame_1_2 # Frame 72
  2000 6747 6884 frame_0_1 # Frame 73
  2100 4574 7706 frame_1_2 # Frame 74
  2800 5455 6081 6023 frame_0..2 # Frame 75
  2248 7706 frame_0 # Frame 76
  2100 3968 frame_2 # Frame 77
  2400 3968 frame_1 # Frame 78
  2100 6355 7647 frame_1_2 # Frame 79
  1800 6081 6982 frame_0_2 # Frame 80
  2500 5338 4476 frame_0_2 # Frame 81
repeat

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

sub frame_0_1
  1 servo
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

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

sub frame_1_2
  2 servo
  1 servo
  delay
  return

sub frame_2
  2 servo
  delay
  return

sub frame_0_2
  2 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

If I am understanding this correctly, in this line:
2500 7001 6042 frame_1_2 # Frame 38
the first number is delay time in millisec, the second is a servo position, the third is a servo position and frame is the sub routine which defines the servo(s) used. Everything after # is a comment.
Here is one for a simple eyblink, again from just moving sliders

# eye blink
begin
  100 5984 6003 5984 6003 6000 5984 frame_0..5 # Frame 0
  100 3968 frame_5 # Frame 1
  100 6003 frame_5 # Frame 2
  100 3968 frame_5 # Frame 3
  100 6003 frame_5 # Frame 4
repeat

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

sub frame_5
  5 servo
  delay
  return

If i wanted to add this into the first code, I would need to insert

 100 5984 6003 5984 6003 6000 5984 frame_0..5 # Frame 0
  100 3968 frame_5 # Frame 1
  100 6003 frame_5 # Frame 2
  100 3968 frame_5 # Frame 3
  100 6003 frame_5 # Frame 4

as many times as I wanted and put

sub frame_5
  5 servo
  delay
  return

into the subroutine? Also, I see that the first subroutine is named “frame_0…5”, the second “frame_0_1” and so on. Is this the proper name/sequence for subroutines?

You should not insert a subroutine “into” another subroutine. Subroutines should be separate from each other, like your existing code. Other than that, everything you said is correct.

Yes.

–David