Robotic Dog
Hello! This is a robotic dog. It is able to perform many functions from walking to balancing when pushed. I tried to model it off MIT's Mini Cheetah: Backflipping MIT Mini Cheetah - YouTube- Without the flipping of course! I hope y'all are doing well and enjoy this project!
Downloads
Supplies
8 Servo Motors
2 Hrs04 Ultrasonic Sensor
Breadboard
Arduino Mega
Wide and Thin Sticks
Jumper Wires
Make Joints and Body
This project can be split up into 2 major steps. The code, and the structure. Once the body is built, and the joints can move independently, it is up to you to create its functions. I will give you a few later on.
Building the body-
- Cut out a rectangle. This can be with thin plywood, 3d printed, sturdy plastic, or anything else you can find. I use some red plexi glass.
- For the individual joints take 2 servo motors. attach one to the side of the other like shown in the pictures above.
- Cut out or 3d print 4 legs. I found that about a 75 degrees angle works best. Attach these legs to the outward servo motor like pictured above. As for the legs, find a good level of friction for then to work.
- Then use a breadboard and Arduino Mega to wire up the servos. The servos should have a pos, gnd, and pin wired to it.
That should be it for the body. It should look like a rectangle with 4 legs and 8 joints attached to it.
Sensors
This project can be as complex or as simple as you want, so feel free to put sensors anywhere you want. I put a sensor in the front, and at the bottom of the bot. To install a sensor-
- vcc and gnd attached to corresponding pins.
- A sensor works by sending a signal. This signal bounces off the nearest item and is picked up by the sensor. The amount of time for this process to happen shows how far an item is. So, attach echo and trig to its corresponding pins, and use this code to send a signal:
digitalWrite(trig, LOW);
delay(50);
digitalWrite(trig, HIGH);
delay(50);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration;
Serial.println(distance);
delay(50);
if(distance<1500){
Be sure to establish your pins as input for echo, and trig as output
Code for Walking
The following steps will show how each function will be preformed.
joint2.write(0);
joint1.write(80);
leg1.write(155);
leg4.write(150);
leg2.write(15);
leg3.write(20);
delay(150);
leg1.write(120);
leg4.write(120);
delay(150);
leg1.write(155);
leg4.write(155);
delay(150);
leg2.write(50);
leg3.write(50);
delay(150);
Catching Itself From Falls
joint2.write(0);
joint1.write(90);
leg1.write(145);
leg4.write(145);
leg2.write(35);
leg3.write(35);
digitalWrite(trig, LOW);
delay(10);
digitalWrite(trig, HIGH);
delay(100);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration;
Serial.println(distance);
delay(100);
if(distance2<1500){
for(land= 1; land< land; sit++){
if(pos2<30){
pos2 ++;
}
if(pos>60){
pos--;
}
joint2.write(pos2);
joint1.write(pos);
delay(30);
}
}
delay(1000);
Turning
Left:
joint2.write(30);
joint1.write(90);
leg1.write(155);
leg4.write(155);
leg2.write(15);
leg3.write(20);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(155);
leg4.write(155);
delay(150);
leg1.write(155);
leg4.write(155);
delay(150);
leg2.write(50);
leg3.write(50);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
//}
delay(150);
Right:
joint2.write(0);
joint1.write(60);
leg1.write(155);
leg4.write(155);
leg2.write(15);
leg3.write(20);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(155);
leg4.write(155);
delay(150);
leg1.write(110);
leg4.write(110);
delay(150);
leg2.write(15);
leg3.write(20);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
//}
delay(150);
Shuffle
Left:
joint2.write(15);
joint1.write(85);
leg1.write(155);
leg4.write(155);
leg2.write(15);
leg3.write(20);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(155);
leg4.write(155);
delay(150);
leg1.write(155);
leg4.write(155);
delay(150);
leg2.write(50);
leg3.write(50);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
//}
delay(150);
Right:
joint2.write(0);
joint1.write(65);
leg1.write(155);
leg4.write(155);
leg2.write(15);
leg3.write(20);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(155);
leg4.write(155);
delay(150);
leg1.write(110);
leg4.write(110);
delay(150);
leg2.write(15);
leg3.write(20);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
//}
delay(150);
Crouching and Crawling
digitalWrite(trig, LOW);
delay(100);
digitalWrite(trig, HIGH);
delay(100);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration;
Serial.println(distance);
delay(100);
Serial.println(sit);
if(sit=2){
if(distance<1000){
joint2.write(30);
joint1.write(60);
leg1.write(145);
leg4.write(150);
leg2.write(35);
leg3.write(30);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(110);
leg4.write(110);
delay(150);
leg1.write(145);
leg4.write(150);
delay(150);
leg2.write(70);
leg3.write(70);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(150);//
joint2.write(30);
joint1.write(60);
leg1.write(145);
leg4.write(150);
leg2.write(35);
leg3.write(30);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(110);
leg4.write(110);
delay(150);
leg1.write(145);
leg4.write(150);
delay(150);
leg2.write(70);
leg3.write(70);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(150);//
joint2.write(30);
joint1.write(60);
leg1.write(145);
leg4.write(150);
leg2.write(35);
leg3.write(30);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(110);
leg4.write(110);
delay(150);
leg1.write(145);
leg4.write(150);
delay(150);
leg2.write(70);
leg3.write(70);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(150);//
joint2.write(30);
joint1.write(60);
leg1.write(145);
leg4.write(150);
leg2.write(35);
leg3.write(30);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(110);
leg4.write(110);
delay(150);
leg1.write(145);
leg4.write(150);
delay(150);
leg2.write(70);
leg3.write(70);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(150);//
joint2.write(30);
joint1.write(60);
leg1.write(145);
leg4.write(150);
leg2.write(35);
leg3.write(30);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(110);
leg4.write(110);
delay(150);
leg1.write(145);
leg4.write(150);
delay(150);
leg2.write(70);
leg3.write(70);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(150);//
joint2.write(30);
joint1.write(60);
leg1.write(145);
leg4.write(150);
leg2.write(35);
leg3.write(30);
//digitalWrite(trig, LOW);
delay(150);
//digitalWrite(trig, HIGH);
leg1.write(110);
leg4.write(110);
delay(150);
leg1.write(145);
leg4.write(150);
delay(150);
leg2.write(70);
leg3.write(70);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(150);//
}
if(sit=1){
for(sit = 1; sit < 40; sit++){
if(pos2<30){
pos2 ++;
}
if(pos>60){
pos--;
}
joint2.write(pos2);
joint1.write(pos);
delay(50);
}
sit=2;
}
}
Backing Up
joint2.write(0);
joint1.write(90);
leg1.write(140);
leg4.write(125);
leg2.write(60);
leg3.write(45);
//digitalWrite(trig, LOW);
delay(500);
//digitalWrite(trig, HIGH);
leg1.write(140);
leg4.write(170);
delay(500);
leg1.write(140);
leg4.write(125);
delay(500);
leg2.write(60);
leg3.write(0);
//digitalWrite(trig, LOW);
//duration = pulseIn(echo, HIGH);
//distance = duration;
//Serial.println(distance);
delay(500);
Balancing
joint2.write(0);
joint1.write(90);
leg4.write(165);
leg1.write(165);
leg2.write(25);
leg3.write(15);
delay(100);
leg2.write(35);
leg4.write(155);
delay(100);
leg2.write(25);
leg4.write(165);
delay(100);
leg3.write(25);
leg1.write(155);
delay(100);
leg3.write(15);
leg1.write(165);
delay(100);