当我尝试在 Arduino UNO 中编译我的草图时,为什么会出现这些错误?

Why am I getting these errors when I try to compile my sketch in Arduino UNO?

错误信息:

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Uno"

C:\Users\ghane\AppData\Local\Temp\ccVLh1df.ltrans0.ltrans.o: In function `build':

C:\Users\ghane\OneDrive\Documents\Arduino\libraries\tinn-master/test.c:122: undefined reference to `fopen'

C:\Users\ghane\AppData\Local\Temp\ccVLh1df.ltrans0.ltrans.o: In function `lns':

C:\Users\ghane\OneDrive\Documents\Arduino\libraries\tinn-master/test.c:37: undefined reference to `rewind'

C:\Users\ghane\AppData\Local\Temp\ccVLh1df.ltrans0.ltrans.o: In function `xtsave':

C:\Users\ghane\OneDrive\Documents\Arduino\libraries\tinn-master/Tinn.c:133: undefined reference to `fopen'

C:\Users\ghane\AppData\Local\Temp\ccVLh1df.ltrans0.ltrans.o: In function `xtload':

C:\Users\ghane\OneDrive\Documents\Arduino\libraries\tinn-master/Tinn.c:145: undefined reference to `fopen'

collect2.exe: error: ld returned 1 exit status

exit status 1 Error compiling for board Arduino Uno.

代码:


extern "C"  {
#include "Tinn.h"
};

#define IN1 1   //left motor
#define IN2 2   //left motor
#define IN3 4   //right motor
#define IN4 6   //right motor

#define LMOTOR 3   //left motor
#define RMOTOR 5   //left motor

#define RLED 7  //red led
#define YLED 8  //yellow led
#define GLED 12  //green led

#define Trig1 A0  //front uss sent
#define Echo1 A1  //front uss received
#define Trig2 A2  //left uss sent
#define Echo2 A3  //left uss received
#define Trig3 A4  //right uss sent
#define Echo3 A5  //right uss received


  long duration, MyUSsensor1, MyUSsensor2, MyUSsensor3, y1, y2, y3;

  int initial_motor_speed = 150;
  int mtoutput;
  float out;
  float x1;
  float x2;
  float biases[] = {
  0.375973, 0.226676
  };

  float weights[] = {
  2.000090, -2.732119, -1.512398, 2.352158, -1.499895, -2.407945,
  -3.524677, 1.051439, 4.120766, 0.006929, -2.855277, 0.514731,
  5.028436, 1.573380, -4.188428, -1.534567, -1.662638, 1.460011,
  -0.469579, -3.754514, 1.828197, 1.151905, -3.960257, -0.032369,
  -4.076006, -4.283566, 6.279175, -2.485125, 1.049302, -1.357511,
  -4.136541, -3.860311, -3.208045, 0.286115, -1.206529, -3.035516,
  7.187942, -3.311538, -5.129674, -4.287395
  };

  Tinn tinn ;

  void setup() {

  // Setup the neural network
  tinn = xtbuild(3, 8, 2);
  for (int i = 0; i < tinn.nb; i++)
    tinn.b[i] = biases[i];
  for (int i = 0; i < tinn.nw; i++)
    tinn.w[i] = weights[i];

  pinMode(LMOTOR, OUTPUT); // PWM for Left Motor
  pinMode(RMOTOR, OUTPUT); // PWM for Right Motor
  pinMode(IN1, OUTPUT);    // Control for Left Motor 1
  pinMode(IN2, OUTPUT);    // Control for Left Motor 2
  pinMode(IN3, OUTPUT);    // Control for Right Motor 1
  pinMode(IN4, OUTPUT);    // Control for Right Motor 2

  pinMode (RLED, OUTPUT); //Control for rled
  pinMode (YLED, OUTPUT); //Control for yled
  pinMode (GLED, OUTPUT); //Control for gled

  Serial.begin (9600);
  pinMode (Trig1, OUTPUT);  //control for front uss sent
  pinMode (Echo1, INPUT);  //control for front uss received
  pinMode (Trig2, OUTPUT);  //control for left uss sent
  pinMode (Echo2, INPUT);  //control for left uss received
  pinMode (Trig3, OUTPUT);  //control for right uss sent
  pinMode (Echo3, INPUT);  //control for right uss received

  digitalWrite(IN1, HIGH);  //Initially Moving Forward
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);

  digitalWrite (RLED, LOW); //Initially no light
  digitalWrite (YLED, LOW);
  digitalWrite (GLED, LOW);

  analogWrite(LMOTOR, initial_motor_speed); //Left Motor Speed
  analogWrite(RMOTOR, initial_motor_speed); //Right Motor Speed
  }


  float get_ultrasensor (int trigPin, int echoPin) {
  digitalWrite (trigPin, LOW);
  delayMicroseconds(30);
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (100);
  digitalWrite(trigPin , LOW);
  duration =  pulseIn(echoPin, HIGH);
  long distance = (duration / 2) / 29.1;
  return distance;
  }

  float* predict_output() {
  float NN_input[3] = {  0.0, 0.0, 0.0 };
  NN_input[0] = y1;
  NN_input[1] = y2;
  NN_input[2] = y3;
  return xtpredict(tinn, NN_input);
  }

  float integer(float value) {
  if (value < 10) {

    return 1.0;
  }
  else {

    return 0.0;
  }
  }

  void motor_output() {
  if (x1 <= 0.5 && x2 <= 0.5) {
    mtoutput = 0;
  }

  else if (x1 < 0.5 && x2 >= 0.5) {
    mtoutput = 3;
  }

  else if (x1 >= 0.5 && x2 <= 0.5) {
    mtoutput = 2;
  }
  else if (x1 >= 0.5 && x2 >= 0.5) {
    mtoutput = 1;
  }



  if (mtoutput == 1) {
    digitalWrite (RLED, HIGH);  //active rled

    analogWrite(LMOTOR, 0);   //Stop the motor
    analogWrite(RMOTOR, 0);
    delay(1000);              //Delay 1 second

    digitalWrite (RLED, LOW);  //deactive rled

    digitalWrite(IN1, LOW);  //Reverse //0
    digitalWrite(IN2, HIGH); //1
    digitalWrite(IN3, LOW); //0
    digitalWrite(IN4, HIGH); //1
    delay(50);
    analogWrite(LMOTOR, 150); //reverse
    analogWrite(RMOTOR, 150);
    delay(2000);              //Delay 2 seconds

    analogWrite(LMOTOR, 0);   //stop
    analogWrite(RMOTOR, 0);
    digitalWrite(IN1, LOW);   //Perform U-Turn on current position
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    analogWrite(LMOTOR, 150);
    analogWrite(RMOTOR, 150);
    delay(4000);               //Delay time need to change accordingly

    digitalWrite(IN1, HIGH);   //Moving Forward
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);

  }

  //RIGHT CORNER DETECTED, AVOID RIGHT CORNER
  else if (mtoutput == 2) {
    digitalWrite (GLED, HIGH);  //active gled

    analogWrite(LMOTOR, 0);
    analogWrite(RMOTOR, 0);
    delay(1000);

    digitalWrite (GLED, LOW);  //deactive gled

    //2.TURN LEFT
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    delay(50);
    analogWrite(LMOTOR, 150);
    analogWrite(RMOTOR, 150);
    delay(2000);

    //3.MOVE FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //4.TURN RIGHT
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //5.MOVE FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //6.TURN RIGHT
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //7.MOVE FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //8.TURN LEFT AND MOVE FORWARD
    digitalWrite(IN1, HIGH);      //TURN LEFT
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    delay(50);
    delay(2000);

    digitalWrite(IN1, HIGH);      //MOVE FORWARD
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);
  }

  //LEFT CORNER DETECTED, AVOID LEFT CORNER
  else if (mtoutput == 3) {
    digitalWrite (YLED, HIGH);  //active yled

    analogWrite(LMOTOR, 0);
    analogWrite(RMOTOR, 0);
    delay(1000);

    digitalWrite (YLED, LOW);  //deactive yled

    //2.TURN RIGHT
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    analogWrite(LMOTOR, 150);
    analogWrite(RMOTOR, 150);
    delay(50);

    //3.MOVE FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //4.TURN LEFT
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    delay(50);
    delay(2000);

    //5.MOVE FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //6.TURN LEFT
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    delay(50);
    delay(2000);

    //7.MOVE FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    //8.TURN RIGHT AND MOVE FORWARD
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);

    digitalWrite(IN1, HIGH);      //MOVE FORWARD
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);
  }
  else {

    analogWrite(LMOTOR, 150);
    analogWrite(RMOTOR, 150);
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(50);
    delay(2000);
  }

  }

  void loop() {

  MyUSsensor1 = get_ultrasensor(Trig1, Echo1);
  Serial.println (MyUSsensor1);
  MyUSsensor2 = get_ultrasensor(Trig2, Echo2);
  Serial.println (MyUSsensor2);
  MyUSsensor3 = get_ultrasensor(Trig3, Echo3);
  Serial.println (MyUSsensor3);

  y1 = integer(MyUSsensor1);
  y2 = integer(MyUSsensor2);
  y3 = integer(MyUSsensor3);

  float *out = predict_output();

  out[0] = x1;
  out[1] = x2;
  motor_output();
}

包含库的文件必须与 .ino 文件位于同一文件夹中。这样做后,没有发现任何错误消息。