Robotic arm idea... with servos

Hi Everyone,

Does anyone have a rough outline of what code would be required to tell a servo to go from where it is currently positioned up by 1 degree? I’m thinking about creating a robotic arm but the motion would need to be controlled by holding down a button and keep moving until it stops.

None of the projects I’ve done to date have included using the loop, rather only using the int commands and I was wondering if there’s something in the loop I can use. Basically, the below but using real code. :smile:

void loop { 

    if buttonPushed = true {

        if (currentPosition = < 180) {
            
        newPosition = (currentPosition + 1);
        servo.write (newposition);
        delay (50);

        }

        else { }

    }

else {}

}

int buttonPush(String command) {
    
    buttonPushed = true;
    
}

Don’t worry if you can’t help, just thought I’d ask… I’m struggling to find anyone who’s done anything similar.

Thanks

Tim

1 Like

I would try inverse kinematics to let the processor deal with specific angles and let you focus on specifying only the endpoint of the business end of your robotic arm.

Example code… good luck.

#include "math.h"

const float cx=2; //coxa
const float fm=6.2; //femur
const float tb=8.3; // tibia
float Lsq, L, L1;
float alpha, alpha1,alpha2,beta,gama;
const float fm2= fm*2;
const float fm2tb =fm2*tb;
const float fm_sq = pow(fm,2);
const float tb_sq = pow(tb,2);
const float tbsq_fmsq= tb_sq-fm_sq;
const float to_deg = 180/M_PI;

void setup()
{
 Serial.begin(9600); 
}
void loop()
{
trigono_xyz(2, 4, 6); //contoh x,y,z
Serial.print("gama= ");
Serial.print(gama*to_deg);
Serial.print(", alpha= ");
Serial.print(alpha*to_deg);
Serial.print(", beta= ");
Serial.print(beta*to_deg);
Serial.println();
}

void trigono_xyz(float x, float y, float z)
{
 L1=sqrt(pow(x,2)+pow(y,2));
 gama=atan(x/y);
 Lsq=pow(L1-cx,2)+pow(z,2);
 L=sqrt(Lsq);
 beta=acos((tbsq_fmsq-pow(L,2))/(fm2tb));
 alpha1=acos(z/L);
 alpha2=acos((fm_sq+Lsq-tb_sq)/(fm2*L));
 alpha=(alpha1+alpha2);
}

Thanks! I think it’s going to take me about 400 years to understand what that does… but I’ve got to start somewhere.

i just thought i would mention that every time i come up with an idea that at some point i get stumped on something when i do a google search on keywords that express at least the concepts of the idea it turns out someone has already done very similar projects from which i can gain good insights and solutions. even though this means i have not thought of anything really new it also means a great deal of the time the solution exists i just need to find it. good luck on your project.

1 Like

@dkryder - I had tried that, I just didn’t get anywhere. I have a 3 hour rule… if I can’t find anything that helps within 3 hours, then I ask.

Have you seen this Robot arm on Thingiverse? Is it similar to what you want to make?

1 Like

You’re absolutely right! That’s exactly the plan. Thanks so much.

I don’t suppose you know what I would need to change in the code for it to be accepted on a Photon do you? I know it doesn’t need the servo.h but is there anything else or do you think it would just work?