movement experiment of spider leg... from gavilan on Vimeo.
The materials are minimalistic and only for this experiment. You can clearly see that the leg is cycling through (D = 2, H = 3), then (D = 8, H = 3), then (D = 8, H = 4), then (D = 2, H = 4), then back. With two legs mounted on the front of my robot, this would be enough to propel it forward 6 inches per touch down.
Here is the source code:
#define servo2Pin 2 #define servo3Pin 3 int i; void setup(){ pinMode(servo2Pin, OUTPUT); pinMode(servo3Pin, OUTPUT); Serial.begin(9600); } float l1 = 4.5; float l2 = 6; float d,H; void loop(){ H = 3; for(d=2;d<8;d=d+0.2){ for(i=0;i<1;i++){ goToAngle(servo3Pin, hipAngle(d, H, l1, l2)); goToAngle(servo2Pin, kneeAngle(d, H, l1, l2)); delay(20); } } H = 4; for(d=8;d>2;d=d-0.2){ for(i=0;i<1;i++){ goToAngle(servo3Pin, hipAngle(d, H, l1, l2)); goToAngle(servo2Pin, kneeAngle(d, H, l1, l2)); delay(20); } } } int kneeAngle(float d, float H, float l1, float l2){ return ((acos((l1*l1 + l2*l2 - d*d - H*H)/(2*l1*l2))*180)/PI); } int hipAngle(float d, float H, float l1, int l2){ return 180 - (atan(d/H) + acos((l1*l1 - l2*l2 + d*d + H*H)/(2*l1*sqrt(d*d + H*H))))*180/PI; } void goToAngle(int pinNumber, int angle){ if(angle <= 180 && angle >= 0){ sendPulse(pinNumber, (600+(angle*9.72))); } } void sendPulse(int pinNumber, int pulseWidth){ digitalWrite(pinNumber, HIGH); delayMicroseconds(pulseWidth); digitalWrite(pinNumber, LOW); }
Fun stuff! 50 or so lines can do quite a bit!
No comments:
Post a Comment