Pass Servo Array into Function

Hi all!
I’d like to pass a servo array as a parameter into a function, however I’m receiving the error “declaration of ‘servos’ as array of references”. I’ve tried setting Servo array, as well as Servo array[3] as the arguments of a function, but they both throw that error. Any ideas?

#include<Servo.h>

//Servo parameters
//Increasing uS, more CCW
#define FORWARDCENTRE 1410
#define FORWARDMAX 1500
#define FORWARDMIN 1300
#define RIGHTCENTRE 1375
#define RIGHTMAX 1500
#define RIGHTMIN 1300
#define LEFTCENTRE 1410
#define LEFTMAX 1500
#define LEFTMIN 1300

//Servo objects
Servo servoArray[3];

//Servo pins
#define FORWARDPIN 11
#define RIGHTPIN 10
#define LEFTPIN 9

//Servo scaling constants
double scalingConstants[2][3];

void setup() {
  setScalingConstants();
  
  //Attach servos
  int servoPinArray[3] = {FORWARDPIN, RIGHTPIN, LEFTPIN};
  for(int i = 0; i<3; i++)
    servoArray[i].attach(servoPinArray[i]);
}

void loop() {
  
}

//Input range -1 -> 1
void servoWrite(Servo servos[], double inputSpeed[3]) {
  for(int i = 0; i<3; i++)
    servos[i].writeMicroseconds(scalingConstants[1][i]*inputSpeed[i] + scalingConstants[0][i]);
}

void setScalingConstants() {
  scalingConstants[0][0] = FORWARDCENTRE;
  scalingConstants[0][1] = RIGHTCENTRE;
  scalingConstants[0][2] = LEFTCENTRE;
  scalingConstants[1][0] = FORWARDMAX - scalingConstants[0][0];
  scalingConstants[1][1] = RIGHTMAX - scalingConstants[0][1];
  scalingConstants[1][2] = LEFTMAX - scalingConstants[0][2];
}

Shouldn’t this:

void servoWrite(double inputSpeed[3]) {
  for(int i = 0; i<3; i++)
    servos[i].writeMicroseconds(scalingConstants[1][i]*inputSpeed[i] + scalingConstants[0][i]);
}

be:

void servoWrite(double inputSpeed[]) {     // No need for the '3' here
  for(int i = 0; i < 3;  i++)
    servoArray[i].writeMicroseconds(scalingConstants[1][i]*inputSpeed[i] + scalingConstants[0][i]);
}

Also, most programmers would leave the dimension of the inputSpeed array out in the parameter list.

There is no harm in specifying the size of the array in the function declaration. I prefer it, in fact, so that I know I am passing the correct size array to the function.

OP: When I compile the code you posted, using 1.0.5, I get only one "error":

Binary sketch size: 1,942 bytes (of a 30,720 byte maximum)

If you are getting something different, 1) define what version of the IDE you are using 2) quit using that buggy version

@Paul: I didn't say it would do any harm, but I think passing in the size is a bad idea. What happens if you change the array size later on? Now you have to do searches on the function calls to see which arrays need to be edited. I guess you could get around this with a defined constant, but it still seems weird to me. Also, when the OP looks at 99% of the code out there, he's not going to see that construct.

I get no errors when compiling the code as posted, using IDE V1.6.5, (UNO board selected).

Sketch uses 1,900 bytes (5%) of program storage space. Maximum is 32,256 bytes.
Global variables use 90 bytes (4%) of dynamic memory, leaving 1,958 bytes for local variables. Maximum is 2,048 bytes.