# Servo Array in 12 Servo Control Program

I've done a bit of research, but found nothing that really answered my specific problem.

Among other messes, I have a servo declaration in the start of my program that contains the following:

``````//---Servos: 12 x HS-5645MG (~750us - ~2200us)------
int ServoList[12] =           {0,    1,    2,    12,   13,   14,   16,   17,   18,   28,   29,   30};  //Servo pin #
int ServoCenters[12] =        {1800, 1900, 1250, 1200, 1100, 1750, 1200, 1100, 1750, 1800, 1900, 1250}; // The starting position of each servo that moves the body into a nice standing state
int Servo_OUT_UP_Limit[12] =  {2200, 750,  700,  750,  200,  750,  750,  2200, 750,  2200, 750,  2200}; The physical or digital limits of each servo moving away or up from the body
int Servo_IN_DOWN_Limit[12] = {1000, 2000, 2200, 1500, 1100, 2200, 2000, 1100, 2200, 1500, 1900, 750}; // The physical or digital limits of each servo moving towards or down from the body
int ServoGroup[12] =          {1,    1,    1,    2,    2,    2,    3,    3,    3,    4,    4,    4,};
``````

I need a way to control 12 servo in a 3-DOF quadruped, but I wanted to keep things relatively clean and use only a single function with multiple arguments to control each servo. The problem is that some of the servos are inverted, some (due to the asymmetrical nature of the quadruped) have physical limits. Some servos are used for Y movement and some for X shifts.

Is there a simpler way to address all the aspects of a servo in one call?
Ex: servoMove(sev_number, inverted?, Center?, distance_of_move)
taking into account boundaries and correcting by limiting movement.

My biggest problem is that I'm totally overwhelmed when 12 servos move at once, I'm trying to track errors and whatnot, but it's too hard to look at each servo.

I want to be able to use a number in a simple data range (say 0--->255) and have that be the same distance, move, and direction for every single servo.

I recently picked up and Arduino after a bit and am pretty rusty, I have a servo controller that's taking these commands over serial (SSC-32)

Is there a simpler way to address all the aspects of a servo in one call?

Simpler than what?

You know, comments do not HAVE to be on the same line as the statement they go with. Not having to scroll 6 screens sideways is a good thing.

1: The comments were last minute, and full screen for me (maybe get a better computer)
2: A simple way to address all of the aspects of a servo, think like a memory call:
ServoInfo[8,3] could return (SERVO_IN_DOWN, 2200);
So that I could call one function to return a bunch of different data types

And sure, that's what I want to do, but is there a better way?

Sarcasm really isn't appreciated, I'm just looking to finish my project.

ServoInfo[8,3] could return (SERVO_IN_DOWN, 2200);

Not in C.

You probably want to look in structs.

You probably could use a multi-dimensioned array but I think an array of structs would be easier to keep track of.

The struct should define all the data elements for 1 servo. I think the syntax is

struct servoStruct {
byte pin;
int center;
int upLimit;
int downLimit;
byte group;
}

...R

Is there a simpler way to address all the aspects of a servo in one call?

What is generating the commands for the servos? Below is arduino multi servo code, but if you are using an ssc-32, then the arduino might just act as the serial interface between the command generating device and the ssc-32.

``````//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo

void setup() {
Serial.begin(9600);

//myservoa.writeMicroseconds(1500); //set initial servo position if desired

myservoa.attach(6);  //the pin for the servoa control
myservob.attach(7);  //the pin for the servob control
myservoc.attach(8);  //the pin for the servoc control
myservod.attach(9);  //the pin for the servod control
Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

//expect single strings like 700a, or 1500c, or 2000d,
//or like 30c, or 90a, or 180d,
//or combined like 30c,180b,70a,120d,

if (Serial.available())  {
char c = Serial.read();  //gets one byte from serial buffer
if (c == ',') {
Serial.println(readString); //prints string to serial port out

// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
}
readString=""; //clears variable for new input
}
}
else {
``````// auto select appropriate value, copied from someone elses code