The second chapter on Inverse Kinematics is now published. In this one I show a simple code using the equations from chapter one to make the tetrapod alive...
I hope you find it interesting and useful. Follow @mybloggertricks
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
Serial.begin(115200); //initiate serial communication with SSC 32
}
void loop()
{
val = analogRead(potpin); // reads the value of the pressure sensor (value between 323 and 330)
val = map(val, 323, 330, 100, 500); // scale it to use it with the servo (value between 0 and 180)
Serial.print ("#");
Serial.print (0);
Serial.print (" P");
Serial.print (val); // sets the servo position according to the scaled value
Serial.print (" T");
Serial.println (800);
delay(15); // waits for small amount of time before making another reading
}
Maybe I can use this type of sensor to make my tetrapod react in different ways. We will see.
#include <Servo.h>
Servo servoMain1; // Define our 1st Servo
Servo servoMain2; // Define our 2nd Servo
Servo servoMain3; // Define our 3rd Servo
void setup()
{
servoMain1.attach(2); // servo1 on digital pin 2
servoMain2.attach(3); // servo2 on digital pin 3
servoMain3.attach(4); // servo3 on digital pin 4
}
void loop()
{
servoMain1.write(0); // Turn Servo1 to 0 degrees
servoMain2.write(90); // Turn Servo2 to center position (90 degrees)
servoMain3.write(180); // Turn Servo3 180 degrees
delay(1000); // Wait 1 second
servoMain1.write(180); // Turn Servo1 to 180 degrees
servoMain2.write(135); // Turn Servo2 135 degrees
servoMain3.write(90); // Turn Servo3 to center position (90 degrees)
delay(1000); // Wait 1 second
}
void setup() {
Serial.begin(115200); //Start serial communication at 115200 baud rate
}
void loop() {
Serial.println("#0 P750 #4 P750 #11 P750 T500"); //Moves 3 servos at same time
delay(1000); //Wait 1 second
Serial.println("#0 P2200 #4 P1500 #11 P2200 T500");
delay(1000);
}
Follow @mybloggertricks