A robotic, walking, 3D-printed crab
The goal of this project is to design, program, and prototype a working robot crab that can successfully scuttle and wirelessly communicate to demonstrate how a complex organism can be modeled through engineering and technological pursuits.
Now that I had the means to efficiently code my crab, I was only limited by my creativity, and after lots and lots of trial and error, I finally got something I liked. Below and to the right are a couple videos of the crab moving, both slowly and quickly.
When it comes to any project, the first thing I like to do is have some kind of end-goal, something to work towards, and then work my way backwards from there. From the beginning, I knew that I wanted to make a crab robot that could move around, but I also wanted it to be able to carry a potted plant on its back. I got inspiration for that from this article. I wanted to make my own and like many projects, I wanted to do it so I could learn more about robotics and programming and the associated challenges.
I began my journey researching other animal-like robots that others had designed and started reading up on how creatures move, also known as gaits. After talking to a friend of mine about my idea, he suggested I look into how ants move. As it turns out, most insects use what's known as "tripod configurations," where they always have 3 points of contact on the ground at all times: 2 points on one side, and 1 on the other. Hexapods, creatures with 6 legs, use this to pivot on the 1 point to move forward. Then the other 3 legs move down and touch the ground while the original 3 move up, and pivot forward again, repeating the cycle.
So now I had an idea of how the crab should move, but I still didn't have any physical robot to try this on, so I opened up OnShape, a free CAD (computer aided design) software to start modeling (I learned how to use this program in my high school's engineering class). I put at least 50 hours of effort into the CAD alone. There was a lot of thought that had to go into it. For example, I had to think about the placement of the legs on the main body, where the legs can pivot to, how to make the joints able to be driven only by the motors and not backdrive and cause damage, etc. You can see the final draft of my design to the left. One of the main reasons for this design was its simplicity in assembly, I was able to 3D print all of the parts for this project with my Creality Ender 3 Pro at home, including the bolts that act as pivots for the joints as seen in greater detail below.
The very first assembly I designed was this leg above. I spent at least 2 weeks making lots and lots of designs for the legs of the crab before deciding on one that was light, easy to make, durable, and able to be pivoted on. It was simply enough to print with the individual components to the entire leg, and because of Onshape's built in functions, I could actually test that the leg could be assembled within the program itself.
After making one leg, I could make them all. I printed out and assembled all 6 legs and then printed out the body that holds all of the components together. This process ended up being very easy to do, and was incredibly satisfying seeing over a month's work assembled before my eyes. Now that it was done, I needed to program it.
After I had successfully 3D printed the leg assembly (from above) I wanted to jump into the programming. My language of choice is Python because it is easy to work with, and I have the most experience with it, but I really didn't have much experience working with servo motors (a motor that can be programmatically controlled to move to a fixed angle). To start, I began using example code from the creator of the library (a way of organizing functions that someone else already wrote, like a real library with books) and then modified it slightly to work with my leg. To the left is a video I took of three of the legs moving for the first time.
To control the servo motors, I used a Raspberry Pi 3b+ microcontroller, which is a credit-card-sized computer with built-in Bluetooth and WIFI. Through my desktop PC, I was able to connect to the Raspberry Pi and program it through an SSH (a remote connection to a computer), named PuTTY. This gave me access to the command line of the Pi and I was able to edit files directly from my computer, but for ease of programming, I used another service called WinSCP for sending files back and forth between my PC and the Pi.
I began programming the servo motor positions for the legs by hand, meaning I would type something like this to move a servo to an angle. every. single. time:
You don't have to understand the code, but the basic premise behind it is that the number in the brackets [] represents which servo motor I'm controlling. So kit.servo[1].angle = 90 controls the angle of the 1st motor and sets it to 90 degrees. Since there were 6 legs and 2 motors per leg, that means that there were 12 servos altogether. Trying to remember which number corresponds with what leg seemed inappropriately tedious, so instead, I decided it would be more beneficial to put my time into creating a graphical user interface, or a GUI.
The GUI below helps with the development and testing process of making the crab able to move.
I had some experience making GUI's in the past, but I had never really done anything as complicated, nor as useful, as this. In my experience, most of the effort that went into making the GUI wasn't the programming, it was actually placement of things on screen for ease of development. I originally designed the GUI to have 12 text fields to type in angles for each of the motors, and then when the user hit the "SAVE AND PRINT" button, the program would write a python script that corresponded to the angles put in and save the file to my desktop. From there, I could use WinSCP to send the files over to the Pi and then use PuTTY to remotely run the scripts.
To speed up the process of testing even more, I added a button called "PUSH CODE." The point of this button was to show me what a certain configuration of angles would look like on the crab and I could see this change in real time, saving me several hours of headache. On launch of the GUI, a webserver (like a website) was running locally on my home network that simply had a JSON file (an easy way of representing data) with 12 angles for the 12 servos. When the user hit "PUSH CODE," the values of the angles on the webserver would update to what was put in. On the crab's side, the Pi was constantly checking this webserver to see the values that the motors should be set to, so any change in the webserver would reflect on the crab itself. This process took a long time to figure out, but once they were set up, it became so much easier to program gaits.