Hey Arduino fans,
This is my attempt to make a robot that mimics the very basics of a bird's wing movement. This is turning out to be fairly complex for me and as of now i only have the code finished up (still tweaking), getting the parts together soon. If you are familiar with Robo-Raven, a slightly recent success by robotic students at Maryland's Robotic Center, then you could picture that as my final goal. Of course my version isn't intended to fly due to the bulkiness of servos, their weight, and slow speed. But at least i can attach two wings to my main servos and a third in the rear to give the basic shape of a bird. Let me know what you think of the code but i advise you check out Robo-Raven's design below first, then the motions will make a lot more sense.
Also if your wondering why i had so many different pos variations for example lpos cpos or rpos when i could've just used one or two, its because i got confused and it just made sense in my head to distinguish between two.
#include <Servo.h>
//Declare servo objects; left wing 1, right wing 2, rear wing r.
Servo wing1;
Servo wing2;
Servo rwing;
//Attach servos to appropriate pins.
void setup()
{
wing1.attach(9);
wing2.attach(10);
rwing.attach(11);
}
//Begin loop to list functions.
void loop()
{
centerServo();
flapTen();
leftTurn();
}
//Centers servos before flight.
void centerServo()
{
int cpos;
for(cpos = 0; cpos < 90; cpos +=1)
{
wing1.write(cpos);
wing2.write(cpos);
rwing.write(cpos);
delay (1000);
}
}
//Flaps wings ten times and then centers them for glide.
void flapTen()
{
int i;
int n = 10;
int pos;
for(i = 0; i < n; i+=1)
{
for(pos = 90; pos < 180; pos +=90)
{
wing1.write(pos);
wing2.write(pos);
delay(500);
}
for(pos = 180; pos > 1; pos -=179)
{
wing1.write(pos);
wing2.write(pos);
delay(500);
}
}
for(pos = 1; pos < 90; pos +=90)
{
wing1.write(pos);
wing2.write(pos);
delay(500);
}
}
//Turns bird left in mid-flight.
void leftTurn()
{
int lpos;
int rpos;
for(lpos = 90; lpos < 135; lpos+=45)
{
rwing.write(lpos);
delay(500);
}
for(rpos = 90; rpos < 180; rpos+=90)
{
wing2.write(rpos);
delay(500);
}
for(lpos = 135; lpos > 90; lpos-=45)
{
rwing.write(rpos);
delay(500);
}
for(rpos = 180; rpos > 90; rpos-=90)
{
wing2.write(rpos);
delay(500);
}
}