Robotic Dog

Robot Dog prototype

Project Summary

Compact, modular robotic companion for DIY assistance

Hardware
  • ESP32
  • MG90s
  • 3D-printed chassis
Software
  • Gait control
  • Wi-Fi remote
Mechanics
  • Lightweight
  • lasercut tray
  • PLA Parts
Result
  • Design prototype
  • function prototype under construction
Challenges
  • stability vs. weigth
  • power supply
  • space for parts/partsizes
Next Steps
  • Following Function
  • IMU stabilisation

Content

  1. The Idea
  2. 3D Models
  3. Walking Gait
  4. Wiring
  5. Programming the ESP32
  6. Assembling
  7. Parts and Prices
  8. Planned improvements

The Idea

Dogs are a person’s best friend. Imagine having one that helps you like a true companion on every DIY project—handing you tools or fetching the parts you need.
Of course, for animal welfare reasons, it wouldn’t be a real dog, but a robotic one.

Functionality

The robotic dog should be able to follow its owner autonomously and carry parts or tools in a tray on its back. Due to a lack of qualified recievers which fit in the skaled dog, the first version will be controlled with a webserver and has no autonomous function.

Realistic Prototype

Since strong servos are quite expensive, the prototype was scaled down. The prototype should consist of 3D-printed body parts and 4 legs with 2 degrees of freedom each, driven by servos. The tray on the back should be able to carry small parts and should be detachable.

Control

Even so John Bradnam already provided code for walking gaits, all code was developed from scratch. The control components differ from the original design, too.
The robotic dog is controlled by an ESP32 and the MG90S servos are controlled via a PCA9685 servo driver board.
Following the owner is realized with the help of two RXB6 recievers which locate a 433 MHz transmitter held by the owner.

3D-Models

The basis for the robotic dog are 3D models from John Bradnam on www.hackster.io. Many changes were nessesary to fit the components which should be used and make the carrying function possible. This is discribed on Noras project site, because she did major part of 3D-Design. All code and the parts are provided in a GitHub respository

Walking Gait

The first version of the robotic dog has no interial measurement unit (IMU) and therefore no feedback control. Hence the walking gait had to be very stable and is only based on time.
Therefore, a walking gait was developed where the robot always has three legs on the ground.
The walking gait is based on four phases. In each phase, one leg is lifted, moved forward and set down again, while the other three legs provide stability.
The following pattern is used:

  1. left front leg
  2. right rear leg
  3. right front leg
  4. left rear leg
There maybe will be more complex and faster walking gaits in future versions.

Inverse kinematic

For a smooth walking gait, the servo angles have to be calculated depending on the desired foot position. Therefore, an inverse kinematic for the legs was developed. Each leg has two degrees of freedom, which are controlled by two servos.
The following figure shows the a model of one leg:

The distance between hip and foot kann be calculated with the Pythagorean theorem:
d = X 2 + Y 2
If X and Y are the coordinates of the foot with respect to the hip, d is the distance between hip and foot.
With the cosine law, the angles of the servos can be calculated:
d2 = L tight 2 + L lower leg 2 - 2 L tight L lower leg cos ( α knee )
α knee = arccos ( Ltight2 + Llowerleg2 - d2 2 Ltight Llowerleg )
With the same idea, the angle of the hip can be calculated:
B (t) = i=0 4 binom (4,i) (1-t)4-i ti Pi

This are the formulas for the inverse kinematic of one leg.
With these formulas, the servo angles can be calculated depending on the desired foot position. So it is possible to define smooth trajectories for the feet during the walking gait.

Movement of the legs

With the help of the inverse kinematic, it is possible to define trajectories for a feet in x and y dimension.
There are some requirements for the trajectories during the walking gait:

  • The foot has to be lifted during the forward movement.
  • The foot has to move smoothly.
  • The foot has to be set down smoothly.
  • The foot has to be accelarated smoothly.
These requirements can be fulfilled with a Bezier curve of fourth order which is shown below.

B (t) = (1-t)4 P0 + 4 (1-t)3 t P1 + 6 (1-t)2 t2 P2 + 4 (1-t) t3 P3 + t4 P4

Where P0 to P4 are the control points of the Bezier curve and t is a parameter between 0 and 1.
The following curve is used for the foot trajectory during the walking gait:
The animation below shows either the movement of one leg or all four legs during the walking gait.
As described above, the walking gait is divided into four phases.
In each phase, one leg is lifted, moved forward and set down again, while the other three legs provide stability.

Feel free to try it out:

Simulation of a leg

Before implementing the walking gait on the real leg, the movement of one leg was simulated in Python.
This made it possible to verify the moments, speeds und positions.
It allowed to optimize the walking gait before implementing it on the real robot. A maximum weight of 500 g was assumed for the dog which is distributed on three legs on time. The MG90s servos can provide a stall torque of 0.177 Nm which was divided by three for safety reasons.
The folowing figure shows the results of the simulation:

This is for a step length of 5 cm which starts 1 cm before the vertical projection of the hip.
All values are in a safe range for the servos and the variations are continuous and smooth. Therefore, the walking gait can be implemented on the real robot. If the robot will be lighter, even bigger step lengths are possible.

Steering

Since the robot has a 2 DOF leg which can only move in the sagittal plane, steering is limited like on a tracked vehicle.
Steering is realized by different step lengths for the left and right legs. If the left legs have a bigger step length than the right legs, the robot turns to the right and vice versa.
The bigger the difference between the step lengths, the sharper the turn.

Wiring

As already mentioned, the robotic dog is controlled by an ESP32 and the MG90S servos are controlled via a PCA9685 servo driver board. In addition, a 7,4 V 2000 mAh 15C LiPo battery and two XL4015 are used to supply the robot dog with sufficent power. The XL4015 convert the battery voltage to 5 V. The servos are connected directly to the XL4015 outputs, four to each. The ESP32 and the PCA9685 are also supplied with 5 V from the XL4015 and are interconnected with I2C.
The folowing schematic shows the wiring of the components:

Programming the ESP32

The ESP32 was programmed with ESP-IDF in a combination of C and C++ in VS Code. There are two classes one for the I2C-bus and one for a leg. They are capsuled in wrappers to be useable in the main programm which is written in C. Since all code is avaiable on GitHub
The class Leg includes the trajectories and the inverse kinematic and allows to build four objects of type Leg which have its own step height, step length and height, but use a step time together.

Debugging

For testing the software and for debugging, there is debug.c file which defines functions for usb output. The usb output can be visualized with a python script that animate the legs in time.
As the following picture shows:

Web interface

Since the "Follow Owner"-function isn't implemented yet, the robot is fully controlled with the webinterface.
The ESP32 creates an accespoint which SSID and passwort must be defined in ESP-IDF.
When connected, the server is on http://192.168.4.1 and looks like shown below.

There is a live test version on this website, too.
Feel free to try it yourself: Here

Assembling

Post treatment of 3D printed parts

Once the print is finished, the parts looks as shown in the picture below.

So, the first step is remove the parts from the print bed and remove the supports from parts.
Therefore, pliers and a sharp knife are useful.

Build a leg

Before assembling the leg, all servos should be in a defined state, so that there are no surprises when the robot starts moving. It is recommanded to use the calibration web interface and set all angles to 90 degrees.
First, the hip servo is screwed to the hip element. Then, the thigh is set on the gearwheel of the servo is screwed tight. There are different parts for left and right, so it is important to use the right ones. In the next step, the knee servo is screwed to the tight. The following picture shows the current state.

After that, the lower leg is mounted and screwed. The correct orientation is shown in the picture below. The screw has to be tighten carfully, so the leg don't wiggle, but can turn easily.
Following this, the lower leg is connected to the servo. Therefore a 1.8 mm plastic coated iron wire is bend as shown in the picture.
Inserting the wire finishes the leg.

Wiring and solding

Most cables are connected via soldering, because it needs less space than other methods.
First step is the design of the perforated board which is used to distribute the current from the two XL4015. As shown in the part Wiring, there is only one ground for all components which is important for the interpretation of the i2c and pwm signal.
One XL4015 5 V is only connected to four servos and the other is connected to four servos and the ESP32 and the PCA9685.
Due to a defect of the level shifter, the shown dog uses only 3.3V for the PCA9685 from the ESP32. Check if the used servos work with 3.3V pwm signals. Short jumper male ends can be used as connection between the board and the servos. The ESP32 (and PCA9685) is connected wie male-female jumper wires which are soldered to the board, too.

The thicker wires below are connected with the outputs of XL4015s, so the board looks like shown below.
If the battery is connected to the inputs of the XL4015s, the eletric components are built. Before connecting something to the board, the output voltage of the XL4015s must be ajusted to 5.0V.

The body

Before assembling the body, the electronic components should be placed in the body parts as shown below.

The lid is secured with four M3 screws. The nuts are fused into the body part to make assembling easier, like in the model in the next picture.
After that, the legs can be screwed to the body. It is important to use the right legs on the right positions. The front legs have a different hip part than the rear legs and left and right legs are mirrored. Due to the headsize of the screws every leg is secured with only one screw.
Finally, the tray can be placed on the back of the dog. It is only placed there and not screwed, so it can be removed easily. And the the head and tail is mounted which is only for optical reasons.
The following two pictures show the assembled design model from different perspectives.

Calibration

Before starting the servos, the parameters of the servo must be compared to the cal.h, otherwise the servos could be destroyed.
For the best result, the robot has to be calibrated. In this version, a complete calibration with the webserver isn't possible. When the robot and the software is set up, the "All 90 Degree","All 10 Degree","All 170 Degree" buttons can be used for calibrating.
If the results are not satisfying, the pwm values in the cal.h can be changed to improve the precision.
The formula for calibration is:

PWM = dutytime in ms 20 ms 4096
For example for 90° which is 1.5 ms for the used servos:
PWM = 1.5 ms 20 ms 4096 = 307

Parts and Prices

Amount Part Price
1 ESP32 6.99 €1
1 PCA9685 6.89 €
8 MG90S 19.99 €
2 XL4015 5.33 €1
1 7,4 V Li-ion 2000mAh 16.98 €
1 perforated board 0.55 €1
small amount solder 3.99 €2
1 Set Jumper Wires 6.99 €2
1 Set M3 Screws 6.99 €2
300g PLA filament 6.90 €1
26g silicone SH A 45 7.95 €
200 cm2 acrylic glas (PMMA) 10.20 €2
8 Nail 0.9 x 30 mm 0.25 €1
small amount talc powder 2.59 €2
40cm 1.8 mm plastic coated iron wire 3.60 €2
Total 97.19 €
1   calculated as part of a set
2   can't be calculated, so hole set price

Machines and Tools

  • Trotec laser
  • Prusa MK4S
  • soldering station
  • multimeter

Planned improvements

  • real size
  • following function
  • stabilisation
  • improved calibration
  • different walking gaits

This project was a cooperation with Nora. Please check her website, too.

License

Since the originals are licenced under GPL3+, this project is also licenced under GPL3+.