3D Printed Robotics Development Platform With Nvidia Jetson Nano

by shubham_bhatt in Circuits > Arduino

7647 Views, 113 Favorites, 0 Comments

3D Printed Robotics Development Platform With Nvidia Jetson Nano

DJI was expensive so I made my own robotics platform 😊
DSC00019.JPG
DSC00016.JPG
DSC00184.JPG
DSC00199.JPG
DSC00207.JPG

"3D printed robotics development platform" or 3DPRDP a completely 3D printable development platform. Powered by Nvidia jetson nano and Arduino nano board runs on ubuntu. AI and machine learning models can be implemented easily on this. I designed this to test out prototypes and new ideas quickly. Instead of starting from scratch for every project, this will help in testing critical stuff early on the project like code and algorithms. I wanted to design an affordable and accessible system. This is completely 3D printed no funky assembly or nuts and bolt required.

The main program is written in python and uses flask and socket io to run a webserver on board. You can connect to the interface using the IP address. This project is modular, you don't need all the components to make it work. I have highlighted the components which can replaced or their alternatives along with this article...

Supplies

  • 3D printed parts
  • Nvidia Jetson nano
  • CSI cam
  • Go pro session(optional)
  • Arduino nano
  • 2 X Motor drivers
  • 2 X MG90S servo
  • 0.92 inch oled
  • PCA9685 servo driver
  • USB cables
  • 4 X 16850 Li-on battery
  • Power bank for jetson nano

Relax and Hear Me Out

NO...png

This project might be a little advanced for beginners but don't worry if you are ready to put in some effort it will be fine. The design of this project might look a little intimidating to beginners but it is not. I am not a professional programmer or expert. I learnt all the code and other stuff while doing this project. So if I can do it so can you. I have also attached all the resources I used to learn.


Also, not every component is necessary to make this project. If you are on a tight budget you can leave some things out like GoPro don't worry I will explain along the way. I have also adjusted the code in case some components are not available just comment some lines out and it should work fine.

I have provided lots of hyperlinks in the project if you read through them it will make it easier for you to build this project. They will solve most of your problems.

Setting Up Nvidia Jetson Nano

jetsonano.png
Screenshot 2021-10-03 221737.png

We are going to use Nvidia jetson nano for this project. NVIDIA Jetson Nano Developer Kit is a small, powerful computer that lets you run multiple neural networks in parallel for applications like image classification, object detection, segmentation, and speech processing. All in an easy-to-use platform that runs in as little as 5 watts.

You can use raspberry pi also code for this project is not dependent on the hardware used. I chose Nvidia because of the lots of libraries and examples provided by them which will make it easier to add AI/ML features in the future.

Here is the complete official guide on how to set up jetson nano.

https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit

For visual learners

Digi-key tutorial


Tip:-

Here are some more learning resources about jetson nano. I used these to set up my jetson. This is the best and dedicated website for jetson devices.

https://www.jetsonhacks.com/

Assembly

Screenshot 2021-10-03 214013.png
20201010_140226.jpg
chassis2.png
motor.png
cahssis.png
chassis.png

This project is completely 3D printed and does not require any fancy assembly. Printed in PLA with 0.3mm layer height ender 3 pro. Reading the assembly instruction would be very boring so here is an interactive 3D model of the whole project that runs on your browser. There is a 3D model explode feature on grab cad please use that you will better understand which part goes where.

Grabcad interactive model

STL file for 3D printing


Raw Solidworks files for the project can also be download from the given link. Since these are original files and are parametric changing the design will be very easy.


Tip:-

If you don't have access to a 3D printer you can use any regular robot chassis or just an old plastic box. I have used many take-out plastic boxes when I started this hobby. Robotics is an expensive hobby but there are always ways to work around it like simulation and stuff. ROS is a free platform to experiment and build robots without spending a dollar. I will make a ROS package for this project in upcoming week will update here soon.

Arduino and Motor Setup

board.png
20201104_023617.jpg
DSC00236.JPG
DSC00232.JPG

We are using Arduino nano and two motor drivers to control each wheel. Setup is simple like any other Arduino-powered car nothing special. Arduino will be connected to jetson via USB.

Powering Arduino and Motor driver.

Arduino takes its power from Jetson nano via USB cable. While the motor driver takes its power from Li-ion batteries. They run on two separate power sources. The motor driver has separate + - pins for power input. We just need to connect the ground of Arduino nano to the ground of the motor driver. Never give power to Arduino nano with battery and USB at the same time you will blow up the board.


(DO NOT CONNECT ARDUINO TO BATTERY AND JETSON AT THE SAME TIME.

ONLY CONNECT GROUND WIRE OF BATTERY TO THE GROUND OF ARDUINO NANO)


Motor Driver

Motor driver has input pins (A1,A2,B1,B2) or (INT1,INT2,INT3,INT4) labelling might be different but they do the same thing. Take signals from Arduino pins and change the motor direction based on that.

The driver also has 4 output pins each labeled Motor A and Motor B. You attach your motor wires here. There is no separate power supply for motors. they take their power from the motor driver

Pin used :- 3,6,4,5

Wiring

Driver 1

IN1 = 3; IN2 = 6; IN3 = 4; IN4 = 5;

Driver 2

IN5 = 7; IN6 = 8; IN7 = 9; IN8 = 10;

Connect GND of Arduino nano with GND( negative) of the motor driver.

Arduino_program.ino


Tip:-

You might be uncomfortable with this setup of Arduino it's ok. There are alternatives I used this setup to make my bit look clean. We can also use regular Arduino UNO with the motor driver shield. This is the reason why I made everything a separate system.

How our current system works.

Arduino nano gets commands from python file vis USB.

f - forward

b - backward

l - left

r - right

c - stop

Based on these commands it will run a function.

Example:-

If received 'f' it will run Forward(Speed,0); which will move the bot forward.


We can replace our current setup with Arduino UNO and motor driver shield without changing anything in the python code. Just make the changes in the Arduino code. You can actually use the same Arduino code and just change the pin declaration in the beginning of the code.

Here is the reference code from one of my previous projects. It runs on Bluetooth use this code to learn how to declare the pins.

S.M.A.R.S

https://github.com/sastejugaad/SMARS

Turret System

turret.png
oled.png
20201104_045105.jpg
jetson-oled.jpg
Jetson_Nano_I2C_bus-1.jpg
JetsonNano-expansion-pinout.png
20200406173225.jpg

The purpose of the turret is to turn the camera around. It is made up of 2 X Servo motors, OLED, and CSI cameras. Oled screen just displays stats about jetson nano and it is not required for the bot to run. If you leave it out everything will still work fine.

Servos are to be controlled by PCA9685 servo driver which will be connected to SDA and SLC pins of jetson nano. Same for the OLED screen connect it to SDA and SLC pins on jetson nano. Check images for better understanding.

Oled

Guide to connect Oled

Python library for OLED

PCA9685

Installation

Python library for PCA9685

https://www.youtube.com/watch?v=8YKAtpPSEOk


Tip:-

Both Oled and PCA9685 libraries work on raspberry pi also. So if you get stuck anywhere you can search for a raspberry pi tutorial also.

Oled for raspberry pi

More pi

Camera System

csicam.png
Gopro.png
aru.png
aruco.png

We have a GoPro hero session(not needed) and CSI camera. CSI cam is our primary cam all computer vision stuff will be done here. Use raspberry pi cam 2 older ones are not supported on the jetson. It's going to be tricky to set up the camera the first time below is a brief guide. I suggest after setting up jetson nano please do a simple camera test with the python file.

Everything you need is given below.

Guide on CAM,s for jetson

USB CAM guide

CSI CAM guide


You can use a USB cam also support for USB cam is already built into the code but it is commented out. So comment on the lines for the CSI cam and uncomment the line for the USB cam it should be good to go.

Example:- #video_capture = cv2.VideoCapture(1)


Tip:-

There are two python files for handling computer vision camera.py and ARcamera.py . Both are almost the same except ARcamera.py has aruco marker support. You can do cool AR stuff with it. I did not want to make this tutorial complicated so we will use camera.py simple one for now.

Here is an example from one of my older projects. Tracking distance between two markers and Augmented reality demo.

Augment reality demo

Finding distance

Powering Everything

power.png
DSC00017.JPG
DSC00015.JPG

Well, the power system is a mess. Here is how I made it power bank for jetson nano and 4 x 16850 batteries for motors and turret system. Two batteries go to Arduino and DC motors and the other two to servo motors on the turret.

This is totally unnecessary whole system can be powered by Li-on and DC converters only but I wanted to be safe so I decided to split the power supplies.

16850 battery

Xiaomi power bank 3 ultra compact


Tip:-

A normal 9V battery can also be used in place of 16850 but won't last long probably 8-10 min. Any power bank will work I just went for the smallest one. There is a better way to design the power system also if you want to try it. I will implement this in the next version.

Better power system

Code Setup

interface.png
DSC00219.JPG

It's all written in python 3. We will use HTML, CSS, and javascript to Handel the web UI. But don't worry you won't have to deal with it unless you want to change something in the UI. There is a separate guide to deal with UI on the Github page


File hierarchy

main.py - Main file controls all other systems. Run this file to use the robot

turret.py - Controls the turret

camera.py - Opens camera and send back frames to main.py which are displed as video feed on the web browser

ARcamera2.py- Same as camera.py but with aruco marker

Oled_disp.py- Shows stats about the jetson nano system.

Simplecameratest.py - top check camera is installed properly or not.

arduino_control.py - Communicated with Arduino. Receives command from main.py and send then to Arduino through a USB connection

Arduino_program.ino - Upload this to Arduino. Controls motors.


How the code works

Run main.py this will start all the other functions like camera and web server. We are using flask and socket io library to communicate to our robot using a web browser. Mobile devices and our robot should be connected to the same network. Then go to your web browser and type <ipdressofjetsonnnao>:5000 you should get the interface.

Code is heavily commented line by line so you know which parts do what. I have also explained the code in more detail on GitHub because it's much easier there.

Download from here:

Github repository


Tip:-

Please don't rename or move around the files unless you change the reference in the code also otherwise you will get an error.

How to Run It!!!

DSC00056.JPG
DSC00049.JPG
DSC00221.JPG
  • Install python3 and all the required libraries
  • Connect bot and your mobile device to the same wifi network.
  • Get the IP address of the bot or jetson nano.
  • Run the main.py (use - sudo python3 main.py)
  • open your web browser on your mobile and go to <ipadressofjetsonnano>:5000
  • You should get the live feed.
  • The right stick controls the turret left stick controls the bot movement


Little Demo


Tip:-

You can see the UI in your PC web browser also although you will not be able to control it. This is because it only works on touch devices. Make the joystick bigger using the CSS file for better control. Everything about the joystick, CSS, and HTML is covered in a separate guide present on Github.

While experimenting with CSS and HTML clear your browser cache or use it in incognito mode and restart the browser after every time you make changes to your code. Browsers save some of the data to reload quickly although you might make changes to your code when you reload it you will not see the changes. I learned this the hard way.

Annoying Problems

DSC00217.JPG
DSC00211.JPG

Below is a list of few commands that will make your life easier. This will save you hours of research time. These are general commands and are not specific to this project.


Restart camera demon

This is important because sometimes you might restart the main program and will get an error camera not working r there is no live video feed. Run this command to fix it.

sudo service nvargus-daemon restart


Check CSI camera is working or not

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM),width=3820, height=2464, framerate=21/1, format=NV12' ! nvvidconv flip-method=0 ! 'video/x-raw,width=960, height=616' ! nvvidconv ! nvegltransform ! nveglglessink -e


create hot spot on jetsonano

# Create a connection

sudo nmcli connection add type wifi ifname '*' con-name my-hotspot autoconnect yes ssid my-local-hotspot

# Put it in Access Point

sudo nmcli connection modify my-hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared

# Set a WPA password (you should change it)

sudo nmcli connection modify my-hotspot 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk 12345678

# Enable it (run this command each time you want to enable the access point)

sudo nmcli connection up my-hotspot


Check I2C connection (Oled and Servo driver)

sudo i2cdetect -y 1

or

sudo i2cdetect -r -y 1


List video devices

ls /dev/video0


List supported video formats by CSI camera

v4l2-ctl -d /dev/video0 --list-formats


Tip:-

Use sudo

Conclusion

DSC00173.JPG
DSC00176.JPG
DSC00177.JPG

This project is still evolving. I am still trying to improve the code for this project that's the reason why I decided to explain code on the Github page because making and tracking changes in the code is easier.

I have already linked most of the resources I have used to make this project but please don't hesitate to ask questions. This is not the end of this project I want to make it more robust. All your questions and queries will help me reach my goal.