project log 3- pot x,y coord

A project log for Quadruped learning project

Quadruped robot learning.

tsmspacetsmspace 01/02/2017 at 08:130 Comments

So I've managed to rig up an experiment with my little leg, where I use two potentiometers mapped to x and y coordinate ranges to direct the foot location. It never worked perfectly, but did display some "workingness".

I noticed that when changing one potentiometer, the other potentiometers input would also change (although less,, I don't say slightly because it was certainly noticable). I think this is because when one potentiometers resistance would change, the current flowing through the other potentiometer would be affected. This is probably because the entire circuit is two potentiometers, and two servos (drawing power from arduino directly,,, lights flickering), all connected to power in parallel. So although the pot outputs run to two seperate pins, an important amount of voltage flows to ground, which is what will change the most as the other potentiometers value is changed. This would certainly result in a change in value at the analogRead, and therefore (in my case) a change in y coordinate (mostly y,, x was more stable,, probably the range of motion was mostly in a different place on the potentiometer, meaning the resistance to ground was significantly different between the two pots for the range of motion I was within).

I did manage to get some good motion out of the leg, though. I very clearly saw it move MOSTLY along the changes in x or why I input.

my rig is very unstable. The servos are jumpy, one of them wags. I switched it with one that had previously shown to be more stable, but now it wags,,,. I bought both wagging servos at radioshack,, but now am thinking it might be because the cardboard arm is a generally very unstable place to be mounted, resulting in lots of movement that might cause bouncing connections, or other distortion.

I have more videos of the experiment and problems (although also the successes), but I will keep it to one at the very bottom of this log. I will put the link after the code for the experiment, which is next.

Unfortunately, I did lots of little things to the code over time, so exactly the code for experimenting might be a touch different. I did use a much longer delay in order to allow for me to watch the serial.print a little more easily. However, the code as it is was running only moments ago and producing the desired (well,,, from the code anyway) results. I would probably benefit from some more well produced physical equipment. nice machining,, all that jazz. For now, though, I am able to worry about certain fundamentals.

//hip servo oriented such that 0 degrees is straight downward, and 180 is straight upward

//knee servo oriented so that 0 is directly toward femur, and that 180 is directly away from tibia (so 180 fully extends the leg)

//my model is backward, with the leg extending to my left, so I input negative values and it seems to want to work

//there are still problems with this code, the solutions it may pick may not be within the range of motion of the servos.

//all measurements are in milimeters.

//open serial monitor to see angle B then angle A, B is hip angle so printed first

#include <Servo.h>

#include <math.h>

Servo hip;

Servo knee;

int femur = 100;

int tibia = 90;

void setup() {

// put your setup code here, to run once:





void loop() {

// put your main code here, to run repeatedly:

int joyx = analogRead(A0);

int joyy = analogRead(A1);

int x = map(joyx, 0, 1023, -250, 0);

int y = map(joyy, 0, 1023, -150, 150);

Serial.print (x);

Serial.print (" ");

Serial.println (y);

//assuming servo hip is oriented, 0 straight down, 180 straight up, y is inverted, so -y is above the x axis

float L = sqrt((x*x)+(y*y));

float A = acos(((femur*femur)+(tibia*tibia)-(L*L))/(2*femur*tibia));//outputs number in radians as A

float B = acos(((femur*femur)+(L*L)-(tibia*tibia))/(2*femur*L))+acos(((L*L)+(y*y)-(x*x))/(2*L*y));//outputs number in radians as B

Serial.print(degrees(B));//converts radians to degrees

Serial.print(" ");

Serial.print(degrees(A));//converts radians to degrees

Serial.println ("----------------------");

hip.write(degrees(B));//converts radians to degrees

knee.write(degrees(A));//converts radians to degrees