Teachable Robotic Arm编码错误

时间:2013-12-06 20:29:30

标签: c++ arduino robotics

我正在研发一种机器人手臂,它有六个舵机,由一个arduino uno控制。舵机是来自adafruit的模拟伺服系统,它们是特殊的,你可以从舵机获得反馈,即在你告诉它去哪里后它们的实际位置。我正在努力的是尝试调整这个示例代码以包含六个伺服而不是一个。 https://github.com/adafruit/Feedback-Servo-Record-and-Play/blob/master/servo_recordplay.ino

这是我到目前为止的代码及其错误

// Example code for recording and playing back servo motion with a 
// analog feedback servo
// http://www.adafruit.com/products/1404


#include <Servo.h>
#include <EEPROM.h>

#define CALIB_MAX 512
#define CALIB_MIN 100
#define SAMPLE_DELAY 25 // in ms, 50ms seems good

uint8_t recordButtonPin = 12;
uint8_t playButtonPin = 7;
uint8_t servo1Pin = 9;
uint8_t servo2Pin = 10;
uint8_t servo1FeedbackPin = A0;
uint8_t servo2FeedbackPin = A1;
uint8_t servo3FeedbackPin = A2;
uint8_t servo4FeedbackPin = A3;
uint8_t servo5FeedbackPin = A4;
uint8_t servo6FeedbackPin = A5;
uint8_t ledPin = 13;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

void setup() {
  Serial.begin(9600);
  pinMode(recordButtonPin, INPUT);
  digitalWrite(recordButtonPin, HIGH);
  pinMode(playButtonPin, INPUT);
  digitalWrite(playButtonPin, HIGH);
  pinMode(ledPin, OUTPUT);

  Serial.println("Servo RecordPlay");
}

void loop() {
 if (! digitalRead(recordButtonPin)) {
   delay(10);
   // wait for released
   while (! digitalRead(recordButtonPin));
   delay(20);
   // OK released!
   recordAllServos(servo1Pin, servo1FeedbackPin, recordButtonPin);
 }

  if (! digitalRead(playButtonPin)) {
   delay(10);
   // wait for released
   while (! digitalRead(playButtonPin));
   delay(20);
   // OK released!
   playAllServo(servo1Pin, playButtonPin);
 }
}

void playAllServo(uint8_t servoPin, uint8_t buttonPin) {
  uint16_t addr = 0;
  Serial.println("Playing");


  servo1.attach(servo1Pin);
  while (digitalRead(buttonPin)) {    
    uint8_t x = EEPROM.read(addr);
    Serial.print("Read EE: "); Serial.print(x);
    if (x == 255) break;
    // map to 0-180 degrees
    x = map(x, 0, 254, 0, 180);
    Serial.print(" -> "); Serial.println(x);
    servo1.write(x);
    delay(SAMPLE_DELAY);
    addr++;
    if (addr == 512) break;
  }
  Serial.println("Done");
  servo1.detach();
  delay(250);  
}

void recordAllServos(uint8_t servoPin, uint8_t buttonPin) {
  uint16_t addr = 0;

  Serial.println("Recording");
  digitalWrite(ledPin, HIGH);

  pinMode(servo1FeedbackPin, INPUT); 
  pinMode(servo2FeedbackPin, INPUT); 
  pinMode(servo3FeedbackPin, INPUT); 
  pinMode(servo4FeedbackPin, INPUT); 
  pinMode(servo5FeedbackPin, INPUT); 
  pinMode(servo6FeedbackPin, INPUT); 

  while (digitalRead(buttonPin)) 
  {
     readServo(servo1FeedbackPin);
     readServo(servo2FeedbackPin);
     readServo(servo3FeedbackPin);
     readServo(servo4FeedbackPin);
     readServo(servo5FeedbackPin);
     readServo(servo6FeedbackPin);

     if (addr > 506) break;
     delay(SAMPLE_DELAY);
  }
  if (addr != 1024) EEPROM.write(addr, 255);

  digitalWrite(ledPin, LOW);

  Serial.println("Done");
  delay(250);
}

void readAllServo(uint8_t analogPin)
{
     uint16_t a = analogRead(analogPin);

     Serial.print("Read analog pin "); Serial.print(analogPin); Serial.print(": ");
     Serial.print(a);                  
     if (a < CALIB_MIN) a = CALIB_MIN;
     if (a > CALIB_MAX) a = CALIB_MAX;
     a = map(a, CALIB_MIN, CALIB_MAX, 0, 254);
     Serial.print(" -> "); Serial.println(a);
     EEPROM.write(addr, a);
     addr++;
}

我从arduino ide获得的错误是

Teachable_Arm_Mark.cpp: In function 'void loop()':
Teachable_Arm_Mark:10: error: too many arguments to function 'void recordAllServos(uint8_t, uint8_t)'
Teachable_Arm_Mark:49: error: at this point in file
Teachable_Arm_Mark.cpp: In function 'void recordAllServos(uint8_t, uint8_t)':
Teachable_Arm_Mark:100: error: 'readServo' was not declared in this scope
Teachable_Arm_Mark.cpp: In function 'void readAllServo(uint8_t)':
Teachable_Arm_Mark:127: error: 'addr' was not declared in this scope

任何帮助非常感谢 感谢

1 个答案:

答案 0 :(得分:0)

在void loop中你有

  recordAllServos(servo1Pin, servo1FeedbackPin, recordButtonPin);

但是recordAllServos被声明为

void recordAllServos(uint8_t servoPin, uint8_t buttonPin)

因此有太多的争论3对2 ...