Pololu Micro Maestro Servo Controller

Hey guys, I am back again. I am looking for some help with the Pololu Micro Maestro servo controller. Currently I have the sequences for the differ positions of the arm of the robot. What I need is to learn how to call those sequences with the Arduino. Specifically, if the color sensor hooked up to the Arduino "sees" red, I need the Micro Maestro to execute the "go to red bin" sequence. Similarly, I will be using an IR sensor to detect the presence of a fish, but for the time being am going to use a button. Any tips? I am still pretty new to the Ardunio and only know enough to be dangerous, so bear with me. Thanks in advance.

Competition_Code.ino (2.52 KB)

maestro_settings.txt (6.38 KB)

Might be good if you posted your code using code tags like #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

  pinMode(out, INPUT);

I've seen some stupid names for variables, but this one really takes the cake.

Currently I have the sequences for the differ positions of the arm of the robot.

Where? Are they somewhere where the Arduino can read them? Have you written any code to read that file? Have you written any code to parse that XML file?

What I need is to learn how to call those sequences with the Arduino.

You can't. You can call functions.

PaulS:

  pinMode(out, INPUT);

I've seen some stupid names for variables, but this one really takes the cake.

Really because "out" is a pin on the color sensor. So out is an output from that and an input to the Arduino.

Where? Are they somewhere where the Arduino can read them? Have you written any code to read that file?

They are in a script stored to the Micro Maestro.

Have you written any code to parse that XML file?

It isn't an XML file. It is a text file representation of a script file that the Micro Maestro software uses to do its thing.

You can't. You can call functions.

Bull. You can call the sequences. I have seen it done, just don't understand how.

Something tells me you will be of no help nor do you even know what I am talking about.

It isn't an XML file.

It doesn't have an xml extension. It IS an XML file, nonetheless.

Bull. You can call the sequences.

Well, go right ahead. Do it, then.

I'm after doing a similar thing;

I'm very new to this, but so far i have my Arduino looking for button pushes (1, 2 or 3) and then it calls the corrasponding subroutines, however - the servo controller only plays the first line of each subroutine when it is called?

I'm after the subroutine to be played on a loop untill the Arduino calls up another - is this possible?

James

and then it calls the corrasponding subroutines, however - the servo controller only plays the first line of each subroutine when it is called?

Is that a question, as evidenced by the ? at the end, or a statement?

I'm after the subroutine to be played on a loop untill the Arduino calls up another - is this possible?

Yes. That your code appears, to you, to being doing something different, you should change it.

If you don't understand why or how, keeping the code from us is not helping matters.

Thanks for your quick response PaulS.

It was a statement, but I was also questioning why it would do this, sorry for not being clear!

I'm including my code bellow, hopefully you can help me get my head around this.

James

Arduino Code:

#include <PololuMaestro.h>

/* On boards with a hardware serial port available for use, use
that port to communicate with the Maestro. For other boards,
create a SoftwareSerial object using pin 10 to receive (RX) and
pin 11 to transmit (TX). */
#ifdef SERIAL_PORT_HARDWARE_OPEN
  #define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
  #include <SoftwareSerial.h>
  SoftwareSerial maestroSerial(10, 11);
#endif


MicroMaestro maestro(maestroSerial);

const int buttonPin1 = A0;
const int buttonPin2 = A1;
const int buttonPin3 = A2;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;

void setup()
{
  maestroSerial.begin(9600);
  Serial.begin(9600);
  
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
}

void loop()
{
 
  buttonState1 = digitalRead(buttonPin1);

  
  if (buttonState1 == HIGH) {    
      maestro.restartScript(02); 
      Serial.println("Button 1 = High");
  }
  else {
 
  buttonState2 = digitalRead(buttonPin2);

 
  if (buttonState2 == HIGH) {    
      maestro.restartScript(01); 
       Serial.println("Button 2 = High");
  }
  else {
 
  buttonState3 = digitalRead(buttonPin3);


  if (buttonState3 == HIGH) {    
      maestro.restartScript(00); 
       Serial.println("Button 3 = High");
  }
  else {
   maestro.stopScript();
  }
  }
  }
}

Maestro Code:

### Sequence subroutines: ###

# Flat-Line

sub FlatLine

  500 5888 5888 5888 0 0 0 frame_0..5 # Frame 0
  500 delay # Frame 1

return
# Increased Heart Rate

sub Increased_Heart_Rate
begin
  500 5888 5120 5888 0 0 0 frame_0..5 # Frame 0
  500 6656 frame_1 # Frame 1
  500 5120 frame_1 # Frame 2
  500 6656 frame_1 # Frame 3
repeat

# Regular Heart Rate

sub Regular_Heart_Rate

  500 5120 5120 5120 0 0 0 frame_0..5 # Frame 1 
  500 6656 6656 6656 frame_0..2 # Frame 2
  500 5120 5120 5120 frame_0..2 # Frame 2
  500 6656 6656 6656 frame_0..2 # Frame 3
  
return

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

sub frame_1
  1 servo
  delay
  return

sub frame_0..2
begin
  2 servo
  1 servo
  0 servo
  delay
  repeat

Whenever anyone posts code that has switches connected to INPUT pins, instead of INPUT_PULLUP pins, I have to ask how ARE the switches wired, and why did you do it THAT way?

A link to the Maestro library would be in order. I'm guessing that will answer a lot of questions that b3ttykr0ck3r wouldn't.

Being a 'newbie' I have just followed a tutorial for connecting push buttons, so thats why I've done it that way (please see attached image to clarify how I have my buttons connected)

Please also find attached the Arduino library for the Maestro.

Thanks again for your help

James

maestro-arduino-master.zip (16.3 KB)

Do any of the examples work correctly?

I Have tried the 'Basic' and the 'Script' examples, both of which seem to work as they should

I Have tried the 'Basic' and the 'Script' examples, both of which seem to work as they should

This suggests that the problem is with your Maestro code, not with the hardware, the Arduino, or the Maestro library.

Lovely,

Thanks for the pointer - I had a play in the Maestro code with where I had placed the 'begin' and 'repeat' tags - these control the looping and I have it doing what I need.

I'm sure more luck than judgement, but hey ho

Here is then new working Maestro code:

### Sequence subroutines: ###

# Flat-Line
sub FlatLine
  500 5888 5888 5888 0 0 0 frame_0..5 # Frame 0
  500 delay # Frame 1
  return
# Increased Heart Rate
sub Increased_Heart_Rate
  begin
  500 5888 5120 5888 0 0 0 frame_0..5 # Frame 0
  500 6656 frame_1 # Frame 1
  500 5120 frame_1 # Frame 2
  500 6656 frame_1 # Frame 3
  repeat
# Regular Heart Rate
sub Regular_Heart_Rate
  begin
  40 5120 5120 5120 0 0 0 frame_0..5 # Frame 1
  100 6656 6656 6656 frame_0..2 # Frame 2
  80 5120 5120 5120 frame_0..2 # Frame 2
  20 6656 6656 6656 frame_0..2 # Frame 3
  repeat

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  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

these control the looping and I have it doing what I need.

I'm sure more luck than judgement, but hey ho

Sometimes, luck is good.