I recently bought a 4 DOF (Degree Of Freedom) robotic arm kit. I successfully assembled it and now I want to program the arduino to control it. I know how to make the servos work using arduino but could not figure out how to move the hand to specific positions.
I tried manually creating a two dimensonal array with rotational values for each motor in degrees. This works but it is very hard to get the values and create the array. Currently I adjusted the values by trial and error.
The array I created manually :
short first[] = { 180 , 80 , 0 , 90 };
short pos[][4] =
{
{ 180 , 80 , 00 , 85 },
{ 180 , 85 , 00 , 80 },
{ 180 , 90 , 00 , 75 },
{ 180 , 95 , 00 , 75 },
{ 180 , 100 , 0 , 70 },
{ 180 , 110 , 0 , 70 },
{ 180 , 115 , 0 , 70 },
{ 180 , 120 , 0 , 65 },
{ 180 , 125 , 0 , 65 },
{ 180 , 130 , 0 , 65 },
{ 180 , 135 , 0 , 65 },
{ 180 , 140 , 0 , 65 },
{ 180 , 145 , 0 , 65 },
{ 180 , 150 , 0 , 65 },
{ 180 , 150 , 0 , 70 },
{ 180 , 150 , 0 , 75 },
{ 180 , 150 , 0 , 80 },
{ 180 , 150 , 0 , 90 },
{ 180 , 145 , 0 , 90 },
{ 180 , 140 , 0 , 90 },
{ 180 , 135 , 0 , 90 },
{ 180 , 130 , 0 , 90 },
{ 180 , 125 , 0 , 90 },
{ 180 , 120 , 0 , 90 },
{ 180 , 115 , 0 , 90 },
{ 180 , 110 , 0 , 90 },
{ 170 , 110 , 0 , 90 },
{ 160 , 110 , 0 , 90 },
{ 150 , 110 , 0 , 90 },
{ 140 , 110 , 0 , 90 },
{ 130 , 110 , 0 , 90 },
{ 130 , 115 , 0 , 90 },
{ 120 , 120 , 0 , 90 },
{ 120 , 125 , 0 , 90 },
{ 120 , 130 , 0 , 90 },
{ 120 , 135 , 0 , 90 },
{ 120 , 137 , 0 , 90 },
{ 120 , 139 , 0 , 90 },
{ 120 , 140 , 0 , 85 },
{ 120 , 140 , 0 , 80 },
{ 120 , 140 , 0 , 75 },
{ 120 , 140 , 0 , 70 },
};
The complete code that I wrote :
/*
* claws - 90 close 75 open
* elbow - 0 to 100
* sholder - 30 to 180
*/
Servo Servos[4];
void setup()
{
Servos[0].attach(3);
Servos[1].attach(5);
Servos[2].attach(9);
Servos[3].attach(11);
reset();
run();
Servos[0].detach();
Servos[1].detach();
Servos[2].detach();
Servos[3].detach();
}
void run()
{
for(int i=0; i<sizeof(pos) / sizeof(short) /4 ; i++)
{
for(int j=3; j>=0; j--)
{
Servos[j].write(pos[i][j]);
delay(15);
}
delay(15);
}
for(int i=-1+ sizeof(pos) / sizeof(short) /4;i>=0 ; i--)
{
for(int j=3; j>=0; j--)
{
Servos[j].write(pos[i][j]);
delay(15);
}
delay(15);
}
delay(3000);
}
void reset()
{
for(int i=3; i>=0; i--)Servos[i].write(first[i]);
}
void loop(){}
I want some function to calculate the values of the array for any given coordinate or something like that.(That is the moves of each servo to position the end of the arm at that point)
Photo of the Arm :
Here is the product page of the actual arm :
https://www.amazon.in/gp/product/B07LDNY9J3/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&psc=1
I finally solved the problem ! I tried figuring out the inverse kinematics for the arms but I found out it is very hard and due to the uncertainty in the hardware it doesn't work good either. The actual solution was to use sensors. I put distance sensors (Ultra-sonic) on the arm so that I can measure distance between arm parts in real time. Since I know the length of each segment of the arm (I don't have to worry about uncertainty here.) and also the distance between them I can do simple trigonometry to calculate the coordinates of the tip of the arm. This means that I can simply use a feedback loop to position the arm with ineradicable accuracy and overcome the limitations of the Hardware.
I do understand that this is not the exact answer for the asked question but I found out from my experience that this method is the most suitable for the situation (When compared to the attempt according to the question).