Hi.
I am having a very strange problem with my mini-maestro 18ch using the Arduino Library. I have built a robot arm with 6 servos and am the maestro for control through the Arduino Uno. What is happening is I after I move the two of the servos (shoulder and elbow in this case) and then try to move a third servo the maestro resets itself to the home values.
As for trouble shooting I checked and rechecked all the connenctions and they match what is on the Github page. I powered the setup with both a LiPo and wall charger (note power goes through a 5v regulator). I also ran the same sequence through the maestro control panel with the battery and the wall supply and it worked without an issue. I can not for the life of me think of what else to try to solve this problem.
Listed below is the code and a screen shot of the control panel settings:
[code]#include <PololuMaestro.h>
#include <Wire.h>
#include <avr/pgmspace.h>
/*in the Maestro Control Center and apply these settings:
- Serial mode: UART, fixed baud rate
- Baud rate: 9600
- CRC disabled
Be sure to click “Apply Settings” after making any changes
*/
/* 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
/* Next, create a Maestro object using the serial port.
Uncomment one of MicroMaestro or MiniMaestro below depending
on which one you have. */
//MicroMaestro maestro(maestroSerial);
MiniMaestro maestro(maestroSerial);
struct maestro_parameters
{
int servo_channel;
char servo_name[20];
int servo_min;
int servo_max;
int servo_home;
int servo_speed;
int servo_accel;
int servo_neutral;
int servo_fromLow;
int servo_fromHigh;
} servo[6];
String inputString = “”;
String servoString = “”;
String commandString = “”;
boolean stringComplete = false;
int servoNum, servoPosMs;
float servoPosDeg;
void setup() {
Serial.begin(9600);
// Set the serial baud rate.
maestroSerial.begin(9600);
Serial.println(“Ready”);
inputString.reserve(10);
servoString.reserve(10);
commandString.reserve(10);
//Serial.println(map(0,180,-180,4244,7680));
//maestro_parameters servo[6];
servo[0] = (maestro_parameters) {0, “Base”, 762, 1920, 1361, 0, 0, 1504, -180, 180};
servo[1] = (maestro_parameters) {1, “Shoulder”, 640, 2248, 2040, 40, 0, 1500, -180, 180};
servo[2] = (maestro_parameters) {2, “Elbow”, 992, 1856, 1738, 10, 0, 1505, 180, -180};
servo[3] = (maestro_parameters) {3, “Wrist_Pitch”, 896, 2064, 896, 10, 0, 1500, -90, 90};
servo[4] = (maestro_parameters) {6, “Wrist_Rotate”, 608, 2448, 1500, 40, 0, 1500, 90, -90};
servo[5] = (maestro_parameters) {7, “Gripper”, 1312, 1792, 1358, 7, 0, 1500, 0,10};
}
void loop(){
parseCommand();
}
void finish(){
while(true){
;
;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == ‘\n’) {
stringComplete = true;
}
}
}
void parseCommand(){
// print the string when a newline arrives:
if (stringComplete) {
inputString.trim();
//Serial.println(inputString);
int separatorIndex = inputString.indexOf(’,’);
servoString=inputString.substring(0,1);
commandString=inputString.substring(separatorIndex+1);
servoNum = servoString.toInt();
servoPosDeg = commandString.toInt();
moveServo();
// clear the string:
inputString = "";
servoString = "";
commandString = "";
stringComplete = false;
}
}
void moveServo() {
//Mini Maestro values given in 1/4 ms so you have to multiply by 4.
servoPosMs = 4*map(servoPosDeg, servo[servoNum].servo_fromLow, servo[servoNum].servo_fromHigh,
servo[servoNum].servo_min, servo[servoNum].servo_max);
maestro.setSpeed((uint8_t) servo[servoNum].servo_channel, (uint16_t) servo[servoNum].servo_speed);
maestro.setTarget((uint8_t) servo[servoNum].servo_channel, (uint16_t) servoPosMs);
//Serial.print ("Position is: ");
//Serial.println (maestro.getPosition(servo[servoNum].servo_channel));
Serial.println (“Done”);
}
[/code]
Any help would be appreciated.
Thanks in advance
Mike
EDIT: Here are a couple of photos of the Arm and Servos used as well as a shot of the electronics: