"variable or field declared void" While trying to declare functions

Hello world!

First post here, so I apologise in advance for the 20 forum fopause I am certain I am going to commit in this post. Feel free to politely correct me in your replies.

For my class, we are using the armUno 2.0 for one of our projects. The task I am trying to do is to use the IR remote to tell the arduino the order in which to stack blocks (eg. 4, 2, 1 then 3), then grab the blocks from a predetermined location and stack them into a tower. I am still working on writing my sketch and there is almost nothing in the main loop yet as I am concentrating on first writing the functions that I need to make the main loop nice compact and efficient.

I wrote up all the functions that are governing motion and the constants and figured I should probably try checking if it would compile. It then complains that “variable or field ‘goTo’ declared void”. After some googling, I thought I had figured it out when I added the Function Prototypes section, but alas it still throws the same error.

Any recommendations you lovely people might have would be most appreciated. And if there is anything I need to change in my post or other information you need feel free to let me know.

P.S. Yes, I know that I probably should have simplified a lot of my constants into arrays, but that thought didn’t occur to me until I was far too committed to turn back.

#include <Servo.h>

// Declaring the servo variables
Servo rotServo;
Servo rServo;
Servo zServo;
Servo clawServo;


// Preset Servo locations
const int rotHome = 95;
const int rHome = 75;
const int zHome = 170;

const int clawOpen = 70;
const int clawClosed = 30;

const int rot1 = 142;
const int r1 = 130;
const int z1 = 120;

const int rot2 = 142;
const int r2 = 106;
const int z2 = 101;

const int rot3 = 53;
const int r3 = 124;
const int z3 = 119;

const int rot4 = 52;
const int r4 = 110;
const int z4 = 104;



const int rotStack1 = 94;
const int rStack1 = 120;
const int zStack1 = 111;

const int rotStack2 = 98;
const int rStack2 = 90;
const int zStack2 = 124;

const int rotStack3 = 94;
const int rStack3 = 106;
const int zStack3 = 139;

const int rotStack4 = 97;
const int rStack4 = 101;
const int zStack4 = 154;

// Other variables
int stackSize = 0;

// Current Servo location
int rotDegree = rotHome;
int rDegree = rHome;
int zDegree = zHome;
int clawDegree = clawOpen;

// Servo Pins
const int rotServoPin = 13;
const int rServoPin = 12;
const int zServoPin = 11;
const int clawServoPin = 10;




// Function Prototypes
void goTo ( rotDegreeTarget, rDegreeTarget, zDegreeTarget );
void closeClaw();
void openClaw();
void place ();
void grab(int num);


void setup() {

  // Starting serial communication
  Serial.begin(9600);

  // Setting up the joystick buttons
  pinMode(SW1_pin, INPUT);
  digitalWrite(SW1_pin, HIGH);
  pinMode(SW2_pin, INPUT);
  digitalWrite(SW2_pin, HIGH);

  // Creating the servo objects
  rotServo.attach(rotServoPin);
  rServo.attach(rServoPin);
  zServo.attach(zServoPin);
  clawServo.attach(clawServoPin);

  // Setting the initial servo positions
  rotServo.write(rotDegree);
  rServo.write(rDegree);
  zServo.write(zDegree);
  clawServo.write(clawDegree);
}

void loop() {


  
    
    




}


// Defining Functions
void goTo(rotDegreeTarget, rDegreeTarget, zDegreeTarget) { // Moves the arm to the target posision while leaving the claw in place
  // Setting the current posision
  int startRot = rotDegree;
  int startR = rDegree;
  int startZ = zDegree;

  const int steps = 127;

  // Moving the motor to the new posision
  for (int i = 0; i <= steps; i++) {
    rotDegree = startRot + ((rotDegreeTarget - startRot) * i) / steps;
    rDegree = startR + ((rDegreeTarget - startR) * i) / steps;
    zDegree = startZ + ((zDegreeTarget - startZ) * i) / steps;
  
    rotServo.write(rotDegree);
    rServo.write(rDegree);
    zServo.write(zDegree);
    delay(20);
  }

  rotServo.write(rotDegreeTarget);
  rServo.write(rDegreeTarget);
  zServo.write(zDegreeTarget);
  delay(20);
}




void openClaw() {
  int startClaw = clawDegree;

  for (int i = 0; i <= 40; i++) {
    clawDegree = ((clawOpen - startClaw) * i) / 40;
    clawServo.write(clawDegree);
    delay(20);
  }

  clawServo.write(clawOpen);
  delay(20);
}





void closeClaw() {
  int startClaw = clawDegree;

  for (int i = 0; i <= 40; i++) {
    clawDegree = ((clawClosed - startClaw) * i) / 40;
    clawServo.write(clawDegree);
    delay(20);
  }

  clawServo.write(clawClosed);
  delay(20);
}





void grab(int num) {
  goTo( rotHome, rHome, zHome);
  openClaw();
  
  if (num == 1) {
    Serial.print("Going to Position 1");
    goTo( rot1, r1, z1 + 30);
    goTo( rot1, r1, z1);
    }
  else if (num == 2) {
    Serial.print("Going to Position 2");
    goTo( rot2, r2, z2 + 30);
    goTo( rot2, r2, z2);
    }
  else if (num == 3) {
    Serial.print("Going to Position 3");
    goTo( rot3, r3, z3 + 30);
    goTo( rot3, r3, z3);
    }
  else if (num == 4) {
    Serial.print("Going to Position 4");
    goTo( rot4, r4, z4 + 30);
    goTo( rot4, r4, z4);
    }
  else {
    Serial.print("Something went wrong in grab()")
  }
  closeClaw(); 
  goTo( rotHome, rHome, zHome);
}






void place() {
  stackSize = stackSize + 1;
  goTo( rotHome, rHome, zHome);
  
  if (stackSize == 1) {
    Serial.print("Placing the first block in the tower");
    goTo(rotStack1, rStack1, zStack1 + 5);
    goTo(rotStack1, rStack1, zStack1);
  }
  else if (stackSize == 2) {
    Serial.print("Placing the second block in the tower");
    goTo(rotStack2, rStack2, zStack2 + 5);
    goTo(rotStack2, rStack2, zStack2);
  }
  else if (stackSize == 3) {
    Serial.print("Placing the third block in the tower");
    goTo(rotStack3, rStack3, zStack3 + 5);
    goTo(rotStack3, rStack3, zStack3);
  }
  else if (stackSize == 4) {
    Serial.print("Placing the fourth block in the tower");
    goTo(rotStack4, rStack4, zStack4 + 5);
    goTo(rotStack4, rStack4, zStack4);
  }
  else {
    Serial.print("Something went wrong in place()");
  }

  openClaw();
  goTo( rotHome, rHome, zHome);
}





   

You need to specify the types of the arguments in both the function definition and the function prototype.

Wow, that that took me far too long to figure out! Thank you!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.