---
# System prepended metadata

title: 'Nano Model Simulation, Mark 1'
tags: [NTURT, electrical_system, driverless]

---

# Nano Model Simulation, Mark 1
###### tags: `driverless` `electrical_system` `NTURT`

Nano Modle Simulation, Mark 1 (NMS1) is both ths size down model for a driverless vehicle as well as the simulation for it.
The intension here is to first experiment and gain some experiment of the autonomous algorithm in a size down model first brefore deploying to a full size race car.

The source code for NMS1 can be found here: [NTURacingTeam/nturt_nms1](https://github.com/NTURacingTeam/nturt_nms1).

## Installation

TBD

## Simulation

The simulation is based on `F1TNEHT Gym`. And inspired by `f1tenth_gym_ros` package that bridge the OpenAI Gym interface to ROS2, we also created our own version for NMS1 that better suits our need.

### Usage

You can run the simulation by:

```bash
ros2 launch nturt_nms1_sim f1tenth_gym.launch.py
```

## Physcial Car

### Software

#### Odometry

It is required by ROS Navigation stack that odometry data (in both tramsform from `odom` frame to `base_link` frame and a topic publishing `nav_msgs/Odometry` messages) is provied by the user.

Here for NMS1, we are using Ackerman steering, hence in order to generate odometry data, both wheel speed an steering angle is required. The [ros2_control/ackermann_steering_controller](https://control.ros.org/master/doc/ros2_controllers/ackermann_steering_controller/doc/userdoc.html) is designed to handle such case and fulfill the odometry data requirements from ROS2. Please check it out for how to set it up.

Since we can get the steering angle directly from the steering command, the only thing left is to get wheel speed. In order to do so owe have to add encoders to our modle. A reference setup can be found here: [Donkey Car/Odometry](https://docs.donkeycar.com/parts/odometry/).

### Hardware

#### SBC - Jetson Nano

##### Pinout

![](https://i.stack.imgur.com/VPnmR.png)

##### Commincation via Serial

Tutorial: [Jetson Nano – UART](https://jetsonhacks.com/2019/10/10/jetson-nano-uart/)

:::warning
Since UART is used as serial console on Jetson Nano by default, it has to be disabled in order to not collide with the application.

```bash=
systemctl stop nvgetty
systemctl disable nvgetty
udevadm trigger
```

:::

#### Microcontroller - ESP32 dev kit

##### Pinout

![](https://lastminuteengineers.com/wp-content/uploads/iot/ESP32-Pinout.png)

##### Quadrature Encoder

- [qdec example](https://docs.zephyrproject.org/latest/samples/sensor/qdec/README.html)
- [qdec example github](https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/sensor/qdec)
- [espressif,esp32-pcnt binding](https://docs.zephyrproject.org/latest/build/dts/api/bindings/sensor/espressif,esp32-pcnt.html)
- [pcnt pinctrl pinmux](https://github.com/zephyrproject-rtos/hal_espressif/blob/zephyr/include/dt-bindings/pinctrl/esp32-pinctrl.h#L4746C19-L4746C19)

#### Steering servo

![](https://components101.com/sites/default/files/component_pin/Servo-Motor-Wires.png)

#### Sensor Brushless Motor

Motor sensor connector type: JST ZH 1.5mm.

![](https://community.robotshop.com/forum/uploads/default/original/3X/2/6/2603ac3ef51ebabd1ed005fe74ec14cda6a3eb52.png)

> Note: The connector type shown in the picture about seems to be wrong.

#### ESC

T-Rax 120A ESC

[Vender Site](https://item.taobao.com/item.htm?spm=a1z0d.6639537/tb.1997196601.45.3d3858866ZKCpm&id=548158666715)
[Documentation of a similar ESC](https://p11.secure.hostingprod.com/@hobbypartz.com/ssl/ibuyrc/manual/07E-C-XERUN.pdf)

#### IMU

CMP10A

![](https://hackmd.io/_uploads/HJhDqpZQT.jpg)

Documentation: [github](https://github.com/YahboomTechnology/10-axis_IMU_Module)
Module datasheet: [JY901B](https://wit-motion.yuque.com/wumwnr/docs/sozgn8)
I^2 registor map: [I^2 protocol](https://wit-motion.yuque.com/wumwnr/ltst03/pppv1g)

#### PCB

##### PIN Connection

- Power: From Jetson Nano 5V(pin 2), GND(pin 6)
- Reset: Jetson Nano pin 12 -> ESP32 EN pin
- Serial: Jetson Nano Tx(pin 8), Rx(pin 10) -> ESP32 UART 2
- IMU SDA, SCL -> ESP32 SDA(pin 21), SCL(pin 22)
- Steering servo (typical servo PWM) -> ESP32 any PWM except pin 2
- ESC control (typical servo PWM) -> ESP32 any PWM except pin 2
- Motor hall sensor 1, 2 -> ESP32 any pin except pin 2
    > Note: The sensor from motor is first connected to PCB then to the ESC.
#### Connector type

- Steering servo -> Dupont
- ESC control -> Dupont
- Other -> JST XH 2.54mm
