Swervebot: 3d-Printed Lego-compatible Omnidirectional Robot

by alex_le2014 in Circuits > Robots

74 Views, 1 Favorites, 0 Comments

Swervebot: 3d-Printed Lego-compatible Omnidirectional Robot

Screenshot 2025-01-12 195043.png
IMG_0121.JPEG
IMG_6661.JPEG
IMG_6660.JPEG
IMG_6655.JPEG
IMG_6656.JPEG

Hello and welcome!

My name is Alex Le, and I am a freshman mechanical engineering student at the University of Houston Honors College. I’d like to present to you my first personal project: Swervebot!



Swervebot is an omnidirectional robot built from a combination of real Lego pieces and custom 3D-printed Lego-compatible parts. With the help of the Arduino Nano ESP32 board’s WiFi capabilities, Swervebot can be remote-controlled through a web browser to swerve around your home or workspace with its expressive and animated eyes!

This Instructable will teach you how to print the parts and assemble Swervebot. In addition, I have attached some example code at the end of the Instructable to get your Swervebot started.

Supplies

IMG_6506.JPEG
IMG_6234.JPEG

As I mentioned earlier, Swervebot is made from both Lego technic pieces and custom 3D-printed Lego-compatible parts.

Here are the Lego pieces required to build Swervebot. In addition, I attached the Rebrickable part list if you would like to export it into a CSV file. Rebrickable Link

Note: Price figures are per piece. Total value for all new parts ordered from Lego Pick-A-Brick is $25.05, although you can find much cheaper prices at Bricklink.

The hardware components needed for the Swervebot are:

  1. Arduino Nano ESP32
  2. 2 Half-size Breadboards
  3. 2 TB6612FNG Motor Drivers
  4. 4 200RPM Gearbox N20 Motors w/ Encoders
  5. Regular N20 motors work fine too, this project does not use the encoders.
  6. Jumper Wires
  7. 12 AAA Batteries
  8. In this project, I used 1.2V AAA NiMH rechargeable batteries.
  9. 1.3” SH1106 128x64 OLED Screen
  10. If you already have an 128x64 OLED screen with the SSD1306 driver, it is possible to change the code to make it work with the SSD1306 driver.
  11. 2 6AAA Battery Holders

A brief comment about the battery holders: The battery holders I used are made from AAA battery holders from old flashlights I had lying around in my house. I soldered a pair of them together in series to achieve 9V.

This is not an ideal solution because it isn’t always easy to get a good solder connection on to the nickel-plated steel contacts. Using a lot of flux and sanding down the contacts can help the surface better receive the solder, but it is ultimately much safer to go with sourcing 6AAA battery holders.

Recommended battery holder.

Tools that you will need are:

  1. 3D-printer
  2. Dupont Crimper:
  3. The crimper is used to crimp 2.54mm dupont connectors to the end of the motor’s wires. If your N20 motors already have a breadboard-friendly connections on the ends of the wires, you don’t need this.
  4. Alternatively, you can also “tin” the wires with a little bit of solder so you can insert them securely into the breadboard.

How Does It Work?

Before we go delve into the assembly instructions, I’d like to discuss how the Swervebot can move omnidirectionally. As a MechE major, this is my favorite aspect of the project. If you are familiar with robotics, you might already be familiar with the different ways for a robot to move omnidirectionally.

Some examples use special wheels to achieve omnidirectional movement:

Mecanum wheels

Credit: Wikipedia

Omni-wheels

Proper credit to maker.moekoe's cool ESP32 project using three motors and omniwheels.

Another way to achieve omnidirectional movement is by using special mechanisms that can change the actual orientation of the wheels. If you participated in First Robotics Competition or First Tech Challenge, you already know what I am talking about: swerve drive.

One cool design for swerve drive is differential swerve drive:

Proper credit to WildWillyRobots: An example of an elegant design and execution of differential swerve drive.

This project uses a more common swerve drive design: co-axial swerve drive:

How this particular swerve drive design for this project works is that there are two main axle inputs that drive the mechanism. One axle has a gear that controls the orientation of the wheel. The other axle is responsible for spinning the wheel. When we connect each axle to a motor, we have independent control over the direction the wheel faces and the speed at which it rotates.

Left axle drives a series of gears that drives the wheel, right axle drives the orientation of the swerve module.

Ideally, every swerve module should have two motors each for a combined total of eight motors for four swerve modules. However, due to time and cost constraints, I compromised for using only four motors, two motors for each swerve module. This means that the speed and orientation of the two adjacent swerve modules are coupled together.


Note that the swerve modules are only coupled in pairs. Now if we couple the motion the of B steering motors together, we can keep the orientation of all the swerve modules the same without having to use encoders to align all of the swerve modules.

Now that you understand how the swerve modules work, time to get into the actual Instructable!

3D-Printing Out the Custom Lego Parts

IMG_6504.JPEG

3d-printed Part List:

  1. 4 x N20 Lego Pinion
  2. 4 x N20 Lego Main Housing (enable support)
  3. 4 x N20 Lego Lower Housing
  4. 8 x 11T Gear 0.5 mm Backlash
  5. 4 x Googleplex1
  6. 2 x Googleplex2
  7. 12 x Inserts
  8. 4 x 7668 Part (enable support)
  9. 4 x 5416 Part
  10. 4 x 5417 Part
  11. 4 x 5418 Part
  12. 4 x 5419 Part
  13. 4 x 0.8mm Spacer
  14. 4 x Small Lego Wheel

Optional:

  1. 2 x Battery Holder
  2. 1 x OLED Screen Holder

Most of the parts are designed to be printed out flat with supports. If you are slicing the parts yourself, if the model has hole features, be sure to orient the holes facing upwards. The parts that need support enabled are:

  1. N20 Lego Main Housing and 7668 Part

In addition, the printing process for the Googleplex1 and Googleplex2 parts (don’t ask me how I came up with these names 😅) is a little unique because they have side holes that are printed separately. The neat thing about these parts is that they avoid 3d-printing hole features perpendicular to the z-axis.

Early testing with pin hole inserts. As you can see on the right, the recess for the pin hole is less defined in comparison to the insert technique.

To make the Googleplex1 and Googleplex2 parts, you will first need to print out all of the necessary inserts before the Googleplex1 and Googleplex2 parts. During the slicing step, you will need to set a pause in your slicer software to initiate before the overhang. When the part prints, this pause will give you the chance to put the insert parts into the corresponding slots.

[If you own and use a Bambu Lab 3d-printer, I have the sliced .3mf files with all the print settings and user pauses taken care of available on MakerWorld.]

During the actual printing process of Googleplex 1 and Googleplex 2, it is important to orient the inserts with their bottom layer facing inwards and the top layer outwards. The reason why this is crucial is because the inserts have different top & bottom geometries; putting the inserts the other way around will cause the insert be not flush with the surface of the main part.

Bottom layer facing inwards, top layer facing outwards.

After all the parts have been printed, some additional post-processing may be needed. This is the “mileage may vary” crux of 3d-printing. It may very well be the case that your parts print out perfectly and each axle rotates smoothly in the pin holes. However, it may also be the case that part seams and other printing artifacts impact the smoothness of the pin hole – in that case, post-processing may be needed. In any case, I’ll discuss post-processing. Here is a picture highlighting where post processing may be needed:

There are definitely better ways to ensure these pin holes are smooth (possibly using a dremel tool or using a 4.8mm drill bit), but here was my process.

Tape a small piece of 100 grit sandpaper to a Lego bar piece.

Wrap said sand paper around said bar piece.

Insert sand paper into part.

Sand until smooth by twisting sandpaper in pin hole.

After this, you should have all the necessary 3d-printed pieces for this Lego-swerve design!


Assembly!!

Now it’s time for the fun part: building the robot! This step will be mainly pictures, with a few notes and pointers along the way.

Motor Module:


Battery Module:


Swerve Module:

Make sure that the 4L axle goes in the circle hole, not the axle hole.

Be sure to put the longer axle inside of the circular hole, not the axle hole!

Build a mirrored version of the swerve module.

Now build one more swerve module and its mirror (for a total of four swerve modules).


Full Robot Assembly:

Be careful not to accidentally short the battery when threading the battery leads through the hole!

Connect the swerve modules to motor modules. During this step, ensure that the orientation of the swerve modules are as closely aligned with each other as possible.

Now its time for wiring!

One side down.

The other side down.

I originally intended to use the encoders, but due most of the pins already occupied by the Nano ESP32 and time constraints, I didn’t use the encoders. I’ll likely revisit using them in future projects.

Cover the loose ends of the encoder wires together with masking tape.

Make four of these.

And four of these.

Mirror the opposite side and attach the other swerve drive modules.

Thread the battery leads through the other pin hole of the gray technic piece.


Coupling the Orientation of the Swerve Modules Together

By coupling the motion of steering motors together, we can essentially keep the orientation of all the swerve modules the same without having to use encoders. However, this makes it even more important to have the wiring for the motors correct. If we expect both steering motors to turn CW, but our incorrect wiring causes one of the motors to turn CCW, both motors will stall against each other, leading to potential damage.

During this step, you will want to make sure that all the swerve modules will be aligned with each other as much as possible.


If you don’t want the OLED screen, use this configuration.

If you want to use the OLED screen, remove the previous brown axles and replace them with 4L axles with an extra 12T gear on top. This will give the proper clearance for the wiring.


OLED Screen:

To secure the wires, attach the OLED screen to the 3d-printed mount and firmly push the jumper wires down.

With the female connectors of the jumper wires at the correct distance, add a dab of superglue the dupont connectors to the 3d-printed mount to secure the plastic connectors in place.

Now they are secured in place!


Breadboard & Wiring

VM.png

Now that we assembled most of the Swervebot, it's time to wire everything up. This project will use breadboards to connect the components together. We can begin by sticking two half-size breadboards together on to the 11x15 Technic frame.

Use the adhesive backing of two short breadboards to attach on to the 11x15 Technic Frame.

With the breadboards secured, it’s time for wiring! Here is a wiring diagram to help you wire the components together.

The red wires coming from the battery are secured on the orange pin connectors when not powered on. When I want to turn on the Nano, I plug the red wire into the 9V rail that leads to the VIN pin of the Nano. Likewise, when I want to turn on the motors, I plug the other red wire into the 9V rail that leads to the VM pins of the motor drivers.

When wiring between the Nano ESP32 and the motor drivers, remember that the motor driver's AIn2 pin is above the Ain1 pin. There were times when I accidentally confused which pins were which, resulting in the polarity of the motors being reversed. If you plan on changing the wiring going towards the Nano, be sure to change the code to reflect your changes.

In addition, be sure to wire the motors properly. Although the motors can run regardless, wiring them consistently ensures all the motors have the same polarity (which is important since we are coupling the two steering motors together.)

Picture showing how to connect OLED screen. Tuck extra length of the wires under the breadboard.


Upload Example Sketch

Screenshot 2025-01-13 184956.png

One last step before getting your swervebot up and running! Download the code for this project here: 

https://github.com/captnchopsticks/swervebot/tree/main

In addition, you will need to download the following libraries if you don’t already have them installed.

  1. AsyncTCP.h - https://github.com/me-no-dev/AsyncTCP
  2. ESPAsyncWebServer.h - https://github.com/me-no-dev/ESPAsyncWebServer
  3. SparkFun_TB6612.h - https://github.com/sparkfun/SparkFun_TB6612FNG_Arduino_Library
  4. Adafruit_GFX.h (available through library manager)
  5. Adafruit_SH110X.h (available through library manager)

Once you have downloaded the code, copy and paste the “swervedrive_example_code” folder into your sketchbook folder with all of your Arduino sketches.

After doing so, you will find the file in the sketches tab in the Arduino IDE:

Open the sketch, and then enter your SSID and password into the code so the Arduino Nano ESP32 can connect to your local WiFi. After this, you should be able to compile and upload the code to the board.

After you have the uploaded the sketch, go to the serial monitor to record the IP address of your board. If you don’t see the IP address in the serial monitor, copy Serial.println(WiFi.localIP()); from void setup and paste it into void loop. Then, upload the code again and you should see the IP address printed, where you can record the address once and revert the code back to the original.

Type in the IP address on your web browser, and you should see the web page that lets you control the swervebot!

FW and BW moves the entire swervebot forward and backward respectively.

CCW and CW turns the orientation of the swerve modules, allowing you to strafe in any direction.

CCW orbit and CW orbit drives the swervebot in a orbital path. The orbit slider sets how tight the orbit is. Smaller setting = greater orbit radius. Larger setting = tighter & smaller orbit radius


With this simple example code, you should be all set to use your Swervebot!

Unleash Your Creativity!

IMG_6668.JPEG

The best part about this project being Lego-compatible is that the possibilities are endless!

Want a omnidirectional forklift to carry stuff around? Build it!

Want a robot dinosaur for no particular reason? Build it!

Want a robot dog companion to follow you around the house? Build it!

Bluey ???

These are just some quick builds that I managed to do in an under an hour, but the real fun starts when you take this design and make it your own. I highly encourage you to tinker and customize this design into your own MOC. The only limit is your imagination!

Reflection & Future Directions

This step isn't really a step, more of a personal ramble. Feel free to skip and ignore!

Swervebot is my first personal project and first time working with arduinos and hobby electronics. For the longest time, I’ve irrationally avoided working with electronics. Even when I was doing First Robotics in high school where I had to do some work with electric motors and coding, I never really sunk my teeth into nitty gritty of it. (As a humble mechE major, I enjoy designing in CAD and working with physical mechanisms that I can grasp and see.). Therefore, this was a golden opportunity for me overcome my irrational fear for circuits and coding. And now, after having worked with the Arduino ecosystem, I realize that it wasn’t that bad after all – in fact, I enjoyed it quite a lot! So if you happen to be on the same boat as past-me was, this project might convert you over to liking electronics. (no promises)

All in all, I feel that I’ve learned so much through the course of this project. Admittedly, using an ESP32 isn’t the most beginner-friendly place to start. But by throwing myself into the deep end, I’ve learned a little bit about IOT, web servers, and HTML on top of the basics like coding Arduino C++ and building circuits. Plus, now I have more head room to implement new features to take advantage of all of the ESP32 chip’s potential.

Speaking of which, I hope to keep this project ongoing and continually add new features. My future directions for this project are:

  1. Websocket protocol for communicating with the Nano ESP32 rather than HTTP GET requests.
  2. Using a bluetooth controller! I have actually already begun looking into the Bluepad32 library by Ricardo Quesada.
  3. Incorporating encoders to find the actual velocity of the motors and using PID!
  4. Using more motors. Luckily, I designed the swerve modules and the motor mounts to be modular, giving me the potential to add more motors!!

If you made it to the end of this Instructable, thank you for reading and listening to what I have to say! This Instructable is a culmination of countless hours of design and research and coding, and so I hope that you found value in what I had to share. If you plan on making this project, I hope you have as much fun building and tinkering with it as I had designing and coding it.

Thank you

-Alex