Hello, I am writing a code to do the inverse kinematics for a 3DOF robot. While writing this code I encountered the following error:
Arduino: 1.6.1 (Windows 7), Board: "Arduino Uno"
EXP06_Stocks.ino: In function 'void loop()':
EXP06_Stocks.ino:70:28: error: invalid operands of types 'float' and 'float' to binary 'operator^'
Error compiling.
This error only effects the xt, and yt within my void loop (in my code below). I am using the map() function to draw a straight line along the y axis while maintaining a constant spatial angle.
I'm hoping this will also resolve the issue with my theta values being incorrect.
Any help with understanding the source of this error would be appreciated.
#include <Servo.h> // adds the Servo.h library commands (allows us to use those commands)
//Servo1
Servo servo1; // create servo object to control a servo (named servo1)
// a maximum of eight servo objects can be created
int pos1 = 1465.5; // variable to store the servo1 position as an integer (midpoint default)
float ang1 = 0; // angle of servo1 in degrees (+90 to -90). Use the 'float' type for decimal #'s
//Servo2
Servo servo2; //create servo2
int pos2=1450;
float ang2 = 0; //angle of servo2 in degrees(+90 to -90)
//Servo3
Servo servo3; //create servo3
int pos3=1450;
float ang3 = 0; //angle of servo3 in degrees (+90 to -90)
unsigned int time = 0; // sets the time variable as an interger and assigns an initial value
void setup() // this section of code is performed once at startup
{
Serial.begin(9600); //(115200 is the baud (data transfer) rate. Start with 9600.
//Servo1
servo1.attach(9, 544, 2400); // attaches the servo on pin 9 and sets pulse limits
servo1.writeMicroseconds(1465.5); // starting position (midpoint)
//Servo2
servo2.attach(10,500,2400); // attaches the servo to pin 10
servo2.writeMicroseconds(1450);// Initial position (midpoint)
//Servo3
servo3.attach(11,500,2400); //attaches the servo to pin 11
servo3.writeMicroseconds(1450);//Initisal position (midpoint)
time=millis();
}
void loop() // this section of code is repeated indefinately (until Arduino loses power, at least)
{
float pi=3.1415;
int x; // Selected spatial x
int y; // Selected spatial y
float tht=0*180/pi; // Selected tool angle
int dx;
int dy;
int xt;
int yt;
int rt;
int th1;
int th2;
int th3;
int a;
int b;
// ________________________________________________________________________________
for( ;millis() <=2000;){
for ( ;millis() <= 2000;){
float dy = map(millis(),0,2000,500,100);
float y = dy/100;
float x = 6.0;
float xt = x - .1443 - 2.178*cos(tht);
float yt = y + .7475 - 2.178*sin(tht);
float rt = sqrt(xt^2+yt^2);
float a = 1/cos(rt/11);
float b = atan2(yt,xt);
float th1 = (a + b - pi/2);
float th2 = pi - 2*a - pi/2;
float th3 = tht-th1-th2;
ang1 = th1*pi/180;
pos1 = -10*ang1+1465.5;
servo1.writeMicroseconds(pos1);
ang2 = th2*pi/180;
pos2 = 10.556*ang2-1450;
servo2.writeMicroseconds(pos2);
ang3 = th3*pi/180;
pos3 = -10.734*ang3+1450;
servo3.writeMicroseconds(pos3);
time=millis();
Serial.print(time); // write the number currently stored in the variable time to the serial port
Serial.print("\t"); // tab
Serial.print(x);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(xt);
Serial.print("\t");
Serial.print(yt);
Serial.print("\t");
Serial.print(rt);
Serial.print("\t");
Serial.print(ang1);
Serial.print("\t");
Serial.print(ang2);
Serial.print("\t");
Serial.print(ang3);
Serial.println("");
}
delay(1000);
}
}