I am currently making a robotic arm using the library Fabrik2D and the Adafruit Servo Driver library to control the servos. I am using the Fabrik2D library for calculating the inverse kinematics of the robotic arm. However, after compiling it says that the 'lengths' variable, which is an array of the length of the links was not defined in the 'loop()' scope. I have set the variable outside of the 'void setup()', making it a global variable but it still says it is not defined in the scope.
Here is my current code:
#include <FABRIK2D.h>
#include <Adafruit_PWMServoDriver.h>
int lenghts[] = {194, 150};
Fabrik2D fabrik2D(3,lenghts);
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 140
#define SERVOMAX 520
void setup() {
Serial.begin(9600);
Serial.println("Ready!");
pwm.begin();
pwm.setPWMFreq(60);
fabrik2D.setTolerance(0.5);
}
uint16_t tilt_deg(int degree) {
uint16_t pulse = map(degree, 0, 180, SERVOMIN, SERVOMAX);
return pulse;
}
uint16_t elbow_deg(int degree) {
const int MIN = 200;
const int MAX = 500;
uint16_t pulse = map(degree, 0, 180, MIN, MAX);
return pulse;
}
void loop() {
fabrik2D.solve(200,50,lengths);
int tiltAngle = fabrik2D.getAngle(0) * 57296 / 1000;
int elbowAngle = fabrik2D.getAngle(1) * 57296 / 1000;
pwm.setPWM(0, 0, tilt_deg(tiltAngle));
pwm.setPWM(1, 0, tilt_deg(elbowAngle));
delay(1000);
}
And the error message was:
In function 'void loop()':
inverse_kinematics:39:25: error: 'lengths' was not declared in this scope
fabrik2D.solve(200,50,lengths);
^
exit status 1
'lengths' was not declared in this scope
Is there anything that I am missing in my code?