This video demonstrates how to derive and implement inverse kinematics equations for a three-degree-of-freedom quadruped robot leg, showing the complete process from CAD design using parametric modeling in Fusion 360 to coding the kinematic equations in Python, including coordinate system transformations and trajectory generation for walking motion.
Designing a Quadruped Robot Leg: Inverse Kinematics and 3D Printing Guide
Added:I spent 200 hours engineering a leg for my robot dog because getting a job.
It's made out of camera fibers, so it's super lightweight. It's got three degrees of freedom, which makes it possible to move in X, Y, and Z axis.
And the thing I like most about this leg is the sero hub. All motors are placed inside a single part, which barely moves. That way, most of the mass is stationary, and the leg can move really fast. This video is going to be all about the engineering. I'm going to derive the inverse schematics, go through the code, explain how the leg moves and why my dog is scared of it.
But like all good things in life, we are going to start with the Fusion 360 assembly. I just finished modeling hopefully the final version of this leg.
Basically took the latest design, made it smaller, remodeled a bunch of parts, and because of parametric modeling, it took me only a single day to model. In Fusion, you get these things called parameters. These parameters allow you to basically set variable dimensions. So instead of using a set dimensions for the diameter of these cubes, I used diameter of D and I can change expression for D anytime I want. I'm going to change it to 8 mm, which is what the new design uses. And you can see it got pretty up. This is the case almost always with parametric modeling. You actually have to go back in this timeline and change all the up features. But it still speeds up the process and you don't have to change every single diameter manually.
you can just update the expression and it updates the whole design at once. So now I'm going to assemble it and let's hope it's rigid enough. I started off by cutting up some carbon fiber tubes. And I'm using some water. That's just because I don't want to breathe in the carbon fiber dust which is harmful.
After that, I got to the main assembly.
And as I said before, the main idea behind this new design is taking the latest design and making it smaller, lighter, but keeping the rigidity, which is quite a challenge. I did this mainly by decreasing the diameter of the tubes.
And that's not because of the tubes. The tubes actually weigh next to nothing. I think it's 20 g for the whole leg. The reason I decrease the diameter is so that I can make all the 3D printed parts smaller, which are the majority of the weight. As for the joints, each revol joints consist of an M3 bolt and a spacer. The spacer has a diameter of 3.1 mm, which is close to the 3 mm diameter of the bolts, so there's very little backlash. And since it's made out of metal, the joints should last a decent amount of time.
The M3 spacers are just press fitted into the 3D printed bars, but I had to use a hammer for most of the fit. For the material, I'm printing everything from PLA Pro. It's better than regular PLA because it's got a higher impact strength, higher tensile strength, and in my experience, it's a bit more ductile, so it doesn't crack as easily.
I got this filament from my sponsor, Insigic. They actually do lab tests for their filaments, so you can get the parameters like the tensile strength, shore hardness, and stuff like that.
Otherwise, they do engineering grade filaments. So, if you want TPU9A or carbon fiber infused filament, I'm going to link them in the description and you can check them out.
D was strong enough to hold up its own weight. So, I decided I'm going to add some payload to account for the weight of the robot.
I was doing some calculations to decide which payload this leg needs to withstand. So this leg weighs 260 g. I plan on adding a third motor. So if I just add 50% the leg should weigh 400 g.
Then for the body of the robot I assume that the printed parts the tubes it's going to weigh about 200 g. The battery is 250. I might add some buck converters which are 70 g each. So the total weight of the body is going to be 500 g. Four legs plus the body. The robot should weigh 2.1 kg. Since the robot is going to walk such that two legs are touching the ground at the same time. If I divide the body weight by two, I get the weight per leg, which is about 1 kg. But it already weighs 260. So I just need this leg to lift 750 g. To increase the payload of the leg, I got two main options. I can shorten the carbon fiber tubes, but this would make the robot smaller. So, I decided to go with the second option first, which is adding a spring to offset the weight of the robot. If you're wondering why I added two springs in series instead of just one spring, when you try to compress the spring, you can't really do it. But if you got two springs in series, they just collapse like this.
The leg can jump, which is good. This is 500 g.
Oh wow. Before this leg could lift 300 g. Now it's able to lift 500. So these two springs added 200 g to the payload.
If you like building robots, you should check out my sponsor PCB way. With PCBs, you can take all of these wires components and compress them into a single circuit board just like this one I used for my hexapot. In my next video, I will actually be getting a PCB for this robot dog. And PCB way makes this process easy. You just choose the board dimensions, number of layers and color like this purple one you can get for free this September. Then you upload your gerbal files and track the manufacturing process in real time. You can also choose their PCB assembly services which is what I planned to do because soldering sucks. So thank you PCB way for allowing me to make these projects. I can't wait to see this robot run. At this point I decided that the two degree of freedom leg is finished.
So, I just did some final touches to make sure every part is decent and I don't have to remake it four times once I build the whole robot. Now, I'm at the point where I think the design is decent. There is no obvious way to make significant improvements. I think I can finally go ahead and add the third degree of freedom. To add the third servo motor, I printed this elegant part. It's a sero hub that houses two sero motors just like before. And the third motor is actually going to be attached perpendicular to them. The whole surro hop needs to rotate. So I used a spacer with an M3 bolt again. I even got to use this tool which I never use.
So this is just a screw. It gets screwed in through this part and it sticks out into spacer that's inside this part.
[Music] Oh yeah, this looks super cool. If you're wondering how I made these parts look like they're made out of carbon fiber, I actually got this plate, bamboo lab carbon fiber. I tucked that into AliExpress and it makes this nice pattern. So, I was just mounting these sero motors and noticed a potential issue. Right now, the bolts aren't tightened all the way, and you can see that the servo can flop around a lot, and that's because of these bolts. So, I decided I'm going to use bolts with a counter head. This should help the servo to self center.
[Music] And now it's perfectly aligned. By the way, these gaps between the sero motors are for passive air cooling since the motors get hot. So, I just printed hopefully the final version of the servo hub. And as I'm disassembling the light, I can finally feel the spring force without the gearbox of this servo slowing it down. It's pretty cool.
All right. Now, I want to show you the cable management I came up with because I think it's pretty sick. So, as you can see, the sero hub went through many iterations. At first, I had no cable management. Then, I added this hook for sero 2. Then I added it for sero one as well. And then I changed the design to like these buttons. And now it finally works. So you just press the cable in like this. And then you twist it into place. And now all the cables come straight up.
Again, now I want to actually make this thing move. So for that I need to solve inward kinematics. So I'm going to do that on paper and then transfer it to code. There's two main ways to control this leg. You can either control the joint angles. This is called forward kinematics.
That way the foot moves in an arc or you can control the foot position. So you choose the XY Z position and the leg will move there. With inverse kinematics, you can do cool stuff like making the foot move in a straight line.
But this comes at a cost. You need to solve a ton of equations. Firstly, I'm going to consider the leg to be just these two lengths. The kinematics of this leg are more complicated, but we're going to build up to that. So, these are the two lengths of the leg. Here is the foot and here's the base. We know the foot position because that's the input.
And our goal is going to be calculating theta 2 and theta 3 out of this position. We can draw this triangle and this is going to help us calculate these angles. L23 is just going to be the square root of these corner squared.
It's also going to be helpful to know the angle. So, I'm going to call this angle gamma 3. And that's just going to be the arc tangent of x / z. To get theta free, we kind of need this angle.
So I'm going to call that alpha 23. And to calculate it, we're going to use cosine law. Now we can solve for alpha 23.
And theta 3 is just going to be 180° minus alpha 23. But I'm just going to write that as pi. This is just 180° in radians. So we solved the first motor angle. And now we need to solve theta t.
To get that it would be useful to get this little angle. I'm going to call it alpha 2. And we can use cosine law again to calculate it. Then theta 2 is just going to be gamma 3 minus alpha 2. So these are the kinematic equations for this simplified version of the leg. Now we're going to move to the 3D case. The leg is going to rotate around the x-axis. So we're going to look at it from this side.
That way x is just going to be pointing straight up. Y is going to be pointing to the left and Z is going to be down.
From this side, the leg is just going to be a straight line.
Going to look something like this.
Again, we know the foot position and we want to calculate this angle because of the coordinate system. If you point your right thumb along X, these angles are positive. So, this angle is going to be negative. So, this is going to be minus theta 1. And to calculate it, we can just take the arc tangent of y / z. So minus theta 1 is arc tangent of y / z.
Therefore, theta 1 is going to give us minus that. Now we need to make a correction. So before we assumed that this is a 2D case, but if you took this mechanism and rotated it around the x-axis, you need to make the z coordinate longer to account for the rotation. Therefore, we need to change the Z input for these equations. I'm going to call it Z 2D and it's just going to be Z divided by the cosine of theta 1. So, instead of using this length, we're going to feed this length to these equations for the 2D case.
These equations are still not accurate because in my mechanism, the X-axis is actually translated both in Y and Z axis. So the x-axis is about here and the whole mechanism rotates around this point. Until now we assumed that this mechanism just rotates around this axis but in reality the pivot point is actually here. So the axis is moved in both y and z coordinates. Before this 2D case was just a straight line and now this straight line is here. So this is the 2D mechanism. It's not rotating around this axis anymore. It's rotating around here. Therefore, we got R Y and RZ. This angle is now minus theta 1. We know R Y and RZ because that's just how we modeled the robot. We know the foot position Y and Z. And we want to calculate this angle theta 1. I'm going to call this R1 and I'm going to call this R23. We can easily calculate R1 because it's just going to be the Pythagoras for this points. We can also calculate R1 differently. We can instead of Y and Z, we can use R23, RZ and R Y.
So I'm going to do that. And this is also equal to R1 2. From this equation, we can get R23. Now we know all the lengths of this triangle and we can start calculating angles. So I'm going to call this angle beta 1 and that's just going to be the arc tangent of Y / Z. Then we can get this angle. I'm going to call it beta 2. To get beta 2, we can just use the cosine function. Since we know beta 1 and beta 2, we can get theta 1. So minus theta 1 is going to be beta 1 plus beta 2 minus this 90°. Again, going to write that in radians. Theta 1 is going to be this. And now we need to make another correction. So instead of this simplified case where the axis align, uh, now this length is r23. So for these equations instead of using Z we're going to use R23 and this way the full inverse kinematics are solved for this case. Now we're going to go through the code and implement these inverse kinematics equations. So L2 and L3 that's just the link length. The link length is always from the point of rotation to another joint which in this case is actually this one. And then we go again from the point of rotation uh to the center of the foot or to the end of the linkage. So L2 is 160 and L3 is 153. And that's what I've put in the code. These two lengths are the result of moving the X-axis. So this is the actual pivot point and this is the pivot point we assumed in our equations. It's just going to go through the center of this tube and through the axis of rotation of theta 2. We get that rz is 21 mm and r y is 48 mm. And that's exactly what's in the code. These are just the equations we derive for the 3D case. Then we change the coordinate system. So instead of using Z, we're going to use R23. Then we just use the 2D equations. Here we need to make a change because of the linkage we are using. So when I move this ser motor you can see that only theta 3 changes which is good. But when I move this motor both theta 2 and theta 3 change at the same time. And this is a problem because that's not how we derive the equations.
So whenever we move theta 2 we need to move theta 3 by the same angle. And that's why there's this plus in the equation. And in the end we just change the units from radians to degrees. And the last thing is to sort out the sero offsets. So instead of using the angles calculated from inverse kinematics to set the actual angles of the motors, we need to offset them. When the sero motor is at 0° in the code in reality, it's actually at the middle angle. That's just so that it can rotate both to the left and to the right. And then there's offset from the geometry. Even though these two servo motors are at 0°, this first link is at an angle of 22° and we need to subtract it from the offset.
So I created this move function.
Firstly, we used this inverse kinematic function to calculate the angles. Then we add the surro angle offsets and then we write the suro angles. And this write 270 function. Uh that's just this piece of code. If you have 180° so motors, you can use the default function and then you can use it in the code. You just select the show motors, select the coordinates you want the light to move to and update the angle variables. So solving the inner schematics, doing all of these corrections, writing the code.
It might seem like a lot of work and it is if you do it for the first time, but once you understand it, it's not actually that bad. Yeah, if this goes right, I'm going to be shocked.
Holy Yeah, it works. Let's go. I did all of this first try. My high school math teacher would be proud. So, as you can see now, if I want the Y-axis to be zero, it's not here because the pivot point is actually here at this bolt. So, that's why the leg is tilted when the Y position is set to zero.
[Music] If you want to support me or just build this like, I'm going to put the project files on my Patreon.
I'm not sure if I'm going to use this coroner system for the robot dog. Only a component of the force is being used to lift the robot up. So, I might actually use the configuration where the leg is just pointed straight down.
I really like that you can just take the whole leg out with three bolts. This mechanism is quite elegant, I think. The three heavy sero motors are positioned in this sero hub. The rest of the parts are made out of just plastic carbon fiber tube. So, it's really lightweight.
Oh 340 g only. Each ser motor weighs 70 gs, that's 210 g. All the 3D printed parts, the carbon fiber tubes, weigh 140 g.
So 60% of this leg is just the motors and 40% is this mechanism which I think is pretty good.
I want the leg to be able to walk.
Therefore, we need to make a steps trajectory. So I'm thinking it's going to start here, move in a straight line, and then do this top curve to get back to the starting position. So I want the curve to look like this. This is just a straight line. And this top curve we can just create by manually selecting a bunch of points. But you know what looks like a step curve? Cosine wave. So for the top curve, we're just going to choose cosine wave from minus pi / 2 to pi / 2. And the cosine wave goes from 0 to one in the y-axis. To make the leg follow this path, we need to do something called interpolation. Here in this straight line, you might think you only need two points, but this is not the case. If you have point one and tell the leg to move to point 2, the movement in between these points is basically random because of the complex linkage.
It doesn't move in a straight line. It's probably going to look something like this. So to make the leg move in a straight line, what you need to do is create a bunch of points in between.
That way you're giving the illusion that it moves in a straight line, although the movement in between the points is still random. So that's what we're going to do for this line segment. We're going to get a bunch of points. So it moves in a straight line. For the top curve, since we're going to use cosine wave, we can just take these points on the x-axis and use a cosine function to get the y values. So we got our general shape of the leg path. But now we need to modify it because I want to be able to control the step length and the step height.
First, we're going to create this line.
I want it to be symmetric over the y-axis. So this is going to be zero. And it's going to go from minus step length over two to step length over two. For example, if the step length is 200, this is going to go from - 100 mm to 100 mm.
Now, we need to use these x values to get the cosine function. I want to choose the height of the step trajectory. So, we're going to multiply the cosine wave by the step height. So, it's just going to be the step height time cosine. Now we can't truly feed these x values from the line to the cosine function directly because the cosine function needs values from minus p<unk> /2 to p<unk> /2. So we need to map these x values to this range and we're going to do that like this. So we take these x coordinates and we're going to divide them by the step length. That way we're going to get values from minus 1/2 to 1/2. And to get from this to minus p<unk> or 2 to p<unk> /2 we just going to multiply that by pi. And these are the values we're going to feed to the cosine function. When we add the line segment and the curve segment, we're going to get a L path that looks like this. The length of this curve is step length and the height of this curve is the step height. I chose I think 200 mm for the step length and 100 mm for the step height. Now, if you look at our leg, the origin is about here and we want the leg path to be here. Therefore, we need to add some constant value to all of the y values of the curve. And we're going to move the curve down.
Also, my life uses a different coordinate system. I think this is x, but instead of y pointing up, we got z pointing down. So, in the code, instead of y, I'm going to use minus z. Okay.
Now, we're going to implement this in the code. So, the like trajectory is going to look something like this. And our goal is going to be generating these points such that the leg follows this curve. So we got parameters like the step length and the step height. This is the step length and this is the step height. Then we got step dx. This is just the spacing of the points. So the x is this and I chose it to be 5 mm. We also got this ground height. So the ground height what it does it just moves this whole curve to the bottom. That way when you draw the leg, it's going to be stepping at the bottom like it should.
We're going to start with the ground trajectory, which is the simple one. Z is just going to be ground height. It's not going to change. And X is going to start at step length over two. So step length over two. It's going to be this point. And now I got this clock. I initialize it to be zero. And then I got this while cycle. Y is zero. Z is just going to be the ground height. And X is going to actually iterate. So it's going to start at step length over two. We move the leg to that point and we wait some delay maybe 10 milliseconds. Then we add one to n. So now n is one. And if we go through the cycle again x is going to be step length over two minus step dx * n. Step dx is 5 mm. N is one. So this is going to move 5 mm to the left and we got our next point. Then we wait maybe 10 millconds again and get the next point. And this is going to keep happening until we reach the end where x is going to be bigger than minus step length over two. So minus step length / two. That's here. And if x tries to get past that, it's going to terminate this while cycle. And we're going to move to this part of the code, which is the air trajectory. It's basically the same thing, but instead of moving from right to left, we move from left to right. So we start at minus step length over two and then instead of subtracting step dx * n we add that in the x-axis we get the same coordinates but in the y-axis we use the cosine function. So we get cosine of x but we can't really use this x because the cosine needs to get values from minus<unk> /2 to p<unk> / 2. So we need to map the x values to the correct range. We do this by dividing x by the step length. That way we get values from minus 1/2 to 1/2 and then we multiply it by pi. So we get values from minus p<unk> /2 to p<unk> /2. We feed this into the cosine and we get the correct trajectory. Then we also multiply it by the step height and the ground height.
That way the x values are going to be the same and the y values is going to be the cosine wave and the leg is going to move forward like this. So I just finished coding this step trajectory and it works pretty well.
I was watching YouTube and I found this guy called Noek Ponto. To test the lack of his export, he attached it to a skateboard and let it push around. I want to do the same thing. This guy printed some bars and used a string to attach it to the skateboard. I actually studied mechanical engineering, so I'm going to use some duct tape.
No.
No. No. No.
Check the skateboard.
I hope you enjoy this video. If you want to support me, you can do that on Patreon and you will also get the files for this like. Next video is probably going to be on my master thesis since I'm behind on that
Up Next

Trajectory Generation Methods for Robot Path Planning
@mehran1384
23.1K views•2021-07-24

MathWorks Virtual RoboSub Simulation Environment | Webinar 2026
@RoboNationInc
209 views•2026-03-10

DIY Hexapod Robot Build: Mechanics, Electronics, and Code
@TazerTechnical
36.5K views•2024-10-25

Micromouse: The Fastest Maze-Solving Robots on Earth
@veritasium
23.5M views•2023-05-24
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Robotics






















![Quadrupedal Gait Generation [Simulation and Real] - MSc Robotics, final presentation.](https://i.ytimg.com/vi/Er3Omq9u-pI/sddefault.jpg?sqp=-oaymwEmCIAFEOAD8quKqQMa8AEB-AH-CYAC0AWKAgwIABABGF0gXShdMA8=&rs=AOn4CLAqLh0aicetzpuqab0a82OwbLQFEg)
















