A self driving car project. Pt 1.

Stefano C
8 min readDec 27, 2023

--

This time i want to talk about self driving cars. I was looking for a robust, generic, low cost platform for making some self drive based projects. I was not looking for a ready to go solution because my goal is mainly didactic: learn how to assemble pieces, how to integrate them, how to put them into communication, write some low level code, etc.

In the multitude of things you can find on internet, some devices from Waveshare, Yahboom, Geekworm caught my attention.

In this first part, I am going to explain the architecture from a top level point of view, showing the single boards, explaining why i chose them and how they have been assembled together.

The car with unconnected boards

Some Notes before moving forward:

  • Arduino Nano Ble Sense will be simply called Arduino.
  • Jetson Nano will be called simply Jetson.
  • This page wants to be a sort of a reference page to consult in case of need so i will be updating this page frequently. Consider it a sort of a work in progress because i will add more and more informations in this and in the next stories.

History and revisions

  • 2–5–2024 Added section 1.3.1- Lidar.
  • 1–5-2024 Second document version. (section 1.2.1 updated)
  • 12–27–2023 First document version.
Added motor connections from driver to arduino
Top Level Architecture

As you can see from the figure, the heart of the platform is a Jetson Nano from Nvidia. The Jetson will be responsible of analyzing data, taking decisions and making actions towards various controllers / actuators. At the same time, Arduino will receive commands from Jetson and will forward them to the motors (velocity, steering angle) but also will acquire data (velocity from encoder, acceleration from imu sensor) and will forward them to Jetson. Why is important to retrieve velocity information if i know the value sent to motors? Simply, because there is no guarantee that the imposed velocity is the actual car velocity, so checking the encoder information is the first step to be sure that the car is moving at the expected velocity. We will talk about control theory in the next stories, so stay tuned! In summary we have that:

  • Lcd display, camera and lidar will be connected to Jetson.
  • Motors (left and right wheel) and servo (turning car left and right) will be connected to Arduino.

Data will be exchanged with Jetson trough an serial connection. ROS protocol will be used to create, manage and send communication packets.

The Shopping list

Here is a list of components i am using to build the car:

1.1.1 Jetson Nano board

The NVIDIA® Jetson Nano™ Developer Kit is a small AI computer for makers, learners, and developers. I’m not going deeper cause there are tons of tutorials and guides on Nvidia website but basically you can run (inference) deep learning models for computer vision tasks such as image classification and object detection. You can write your own code in C++ or python and benefit the NVIDIA cuda acceleration through Nvdia TensorRT.

1.1.2 Arduino board.

The Arduino Nano Ble Sense rev 2 is a tiny board with different environment sensors (accelerometer, gyroscope, magnetometer, microphone) and the possibility to run AI using TinyML and TensorFlow™ Lite.

Arduino Nano Ble Sense Pinout
The Arduino board connected on the top of the car

1.1.3 The Ackerman Steering Chassis

I bought this Ackerman Steering chassis from Amazon. For 100 euros more or less you buy a strong alluminium alloy chassis with one servo to control the steering system, two 12V DC motors and four rubber wheels, etc. You can mount everything you want because it comes with several holes and the spacing is compatible with the most common robotic products.

1.1.4 The Motors

The motor i am going to use is the 520 Motor from Yahboom. It’s a 6 pins DC Motor with encoder (2 x motor drive signals, 2 x encoder signals, 1 x ground, 1 x 3v3 hall encoder power supply).

Product specifications for 520 Motor

1.1.5 The motor driver

The AT8236 module is a motor driver that can manage up two 12V DC motors with encoder. I chose this module mainly because is made from the chassis manufacturer, so it has a perfect integration with the motors. Motors are connected through a custom interface PH2.0 Motor Interface. Also, it provides several pins for 3.3V and 5V power supply.

Motor driver pinout

1.1.6 The servo driver board

The servo driver board allows you to debug servos without writing any programs. You can just simply move the knob to tune your servo. It has a power supply connector and usb input to power it. The Servo has a three pin connector (black for Power Supply -, red for Power Supply +, yellow for servo digital signal) connected on the board, the yellow pin also connected to the arduino pin 12 which is set in read mode.

The servo driver.

1.1.7 Ups Battery Pack for Jetson

The ups battery pack is a power supply for the Jetson. Mine came in bundle when i bought the JetBot , but you can buy it separately too. My version is slightly different: 3x 18650 LI battery vs 4x 18650 LI battery, so it seems that the latter has more capacity. Anyway, both have a lcd screen with a i2c connection where some important informations can be displayed.

The UPS power supply for Jetson Nano

1.1.8 The Additional Power Board

This additional power board from Geekworm is used to power the motor driver module AT8236, the servo driver module and the Arduino. With this board you can decide to use a 2 x 18650 battery pack or a li-po battery pack. I personally took a li-po battery from a power bank i did not use and it runs perfectly. This board has 6A max output current which i think would cover worst case scenarios ( dc motors and servo stall current can go up to 3A each). Obviously it can manage battery charging through 5V jack or Usb-C connector and showing battery status through some leds. For a detailed guide check the wiki.

The additional power supply board, below the motor driver.

1.2.1 Arduino to Jetson Connection

I am going to connect the Arduino to Jetson through a serial connection using one of the multiple usb ports of the Jetson. The reason on why i am using the usb port is keep it simple. With usb you can power and communicate with the arduino without using other external connectors. Good! Using ROS with the serial protocol rosserial we will exchange messages about car velocity, steering angle, position, battery voltage, ecc. I will talk later but briefly ROS (robot operating system), as you would expect by an operating system, provides tools, services, libraries to create, build packages, manage exchange of messages between processes, control in a simple way any kind of ros compatible device thanks to an abstraction layer provided by the system.

The Arduino connected to Jetson with an USB cable
Jetson Nano pinout

1.2.2 Arduino to Motor Driver Connection

Dc motors are controlled by digital PWM (pulse width modulation) signals. At the same time, velocity is proportional to the encoder signal. These connections make possible to send velocity commands and acquire encoder data from motors. We need 8 cables (4 for each motor):

  • Motor 1 drive signal 1 ( AIN1) to Pin 9 (digital pwm write pin)
  • Motor 1 drive signal 2 (AIN2) to Pin 10 (digital pwm write pin)
  • Motor 1 encoder signal A ( E1A) to Pin 8 ( dig. reading Encoder)
  • Motor 1 encoder signal B (E1B) to Pin 7 (dig. reading Encoder)
  • Motor 2 drive signal 1 ( BIN1) to Pin 5 (digital pwm write pin)
  • Motor 2 drive signal 2 (BIN2) to Pin 6 (digital pwm write pin)
  • Motor 2 encoder signal A ( E2A) to Pin 4 (dig. reading Encoder)
  • Motor 2 encoder signal B (E2B) to Pin 3 (dig. reading Encoder)

1.3.1 Lidar

The lidar is a device capable of measuring distances by calculating the round trip time it takes for a laser pulse to hit an object. If the laser is allowed to rotate at certain speed (note the motor-belt system in the picture) it can scan the entire environment in one roration (360 degree). The number of points (think about the number of measures it can do in one rotation) and the frequency rotation ( how many rotations it can do in a second) vary depending on the models and on their cost.

Slamtech Rplidar A1

One of the biggest manufacturers in lidar technology is Slamtech. Slamtech provides a complete range of lidars depending on what you are looking for. I have choosen a very basic 2D lidar- i am still at the very beginning so i don’t need more expensive devices- but enough to be able to carry out autonomous navigation experiments. I leave here for reference some useful pages:

What’s next ?

This story is a part of a series of lectures called A self driving car project.

And if you like my content, please consider to follow me on Medium :)

Happy reading, Stefano.

--

--

Stefano C

Master Degree in Physics, work in audio industry. Passion for C++, python, audio, robotics, electronics and programming. Modena, italy.