Knightrider::kitty

About the project

An autonomous vehicle in scale 1:18 powered by two independent electric engines and steering by using servo. Our car is adapt to race in EMEA NXP CUP competition. The goal is use a PIXI CAM 2 camera to give our car eyes and to write perfect algorithm to be the fastest.

Project info

Difficulty: Difficult

Platforms: Arm MbedMATLABNXP

Estimated time: 7 months+

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

MKV58F1M0VLQ24 MKV58F1M0VLQ24 Main microcontroller x 1
MKL25Z128 MKL25Z128 Microcontroller for detecting obstacles using laser sensors or ultrasonic sensors x 1
Pixy2 CMUcam5 Sensor Pixy2 CMUcam5 Sensor x 1
LPC4330-Xplorer Board LPC4330-Xplorer Board x 1
Servo Motor Servo Motor x 1
DC Motors DC Motors x 2
Battery Pack - 14 Aaa Cells Battery Pack - 14 Aaa Cells x 1
Ultrasonic Sensor Hc-sr04 Ultrasonic Sensor Hc-sr04 x 1
VL53L0X V2 VL53L0X V2 Laser Ranging Sensor Module x 1

View all

Software apps and online services

Clion Clion Smart easy C and C++ editor
Visual Studio Code Visual Studio Code Main IDE for C++ language
CMake CMake Tools designed to build our projects for MKV58F1M0VLQ24 , LPC4330 and MKL25Z128
GNU Make and Ninja GNU Make and Ninja Tools which controls the generation of executable
Matlab app Matlab app Control car from PC using bluetooth
LPCXpresso LPCXpresso Create basic code examples for PIXY camera microcontroller
MCUXpresso MCUXpresso Create basic code examples for mainboard
PixyMon v2 PixyMon v2 PixyMon v2 is the configuration utility for Pixy2
PrusaSlicer PrusaSlicer
SOLIDWORKS SOLIDWORKS
Altium Designer Altium Designer To create own PCB

View all

Hand tools and fabrication machines

Soldering satation Soldering satation x 1
3D printer 3D printer x 1
Oscilloscope Oscilloscope x 1
Logic analyzer Logic analyzer x 1
Basic mechanical tools Basic mechanical tools x 1

Story

About the project

The project contains multiple hardware, software and mechanical elements, combined together in order to create an autonomous car, capable to move on the track without any human control. Vehicle is programmed to move on the track and support some features defined by the NXP Cup competition rules.

The project is maintained using the Git repository system. Navigate to the following location to find our embedded firmware and software libraries, as well as hardware platform and mechanical parts designs.

Story

Mechanical platform

As expected, the vehicle needs to have a chassis that will ensure a stable fixation of all components. There are several chassis models recommended by the NXP Cup competition organizers and the Landzo Alamak chassis is the one selected for this project.

The Alamak set contains chassis, servo steering system and motors, but the last two elements were replaced in order to reduce response time of the steering system, provide better durability and allow car to reach higher velocity.

There are also plenty of elements that were created using 3D printing technology in order to enhance the car chassis by adding holders, stabilizers and reinforcement elements.

The steering system

System consists of a few elements, which goal is to fix servo to the chassis and allow turning the wheels by moving swingarms. Additionally, the servo holder is combined with the camera mast holder and the microcontroller board holder, what provides durable and stable fastening of all elements. The 3D models and photos were presented below:

Whole system:

Servo holder:

Element attaching the wheel to the swingarm:

Front bumper

Alamak chassis is equipped with a small front bumper, but it does not provide sufficient protection against damaging steering system in case of hitting some obstacles. That is why the vehicle was supplied with the bigger bumper, having additional holders for the distance measuring sensors. Those are planned to be used for detecting obstacles on the car way and allowing to avoid them.

ray Bumper top view:

Battery holder

The holder is simple element to stabilize the battery on the car chassis and allow replacing it in the comfortable way.

Holder model view:

PIXY camera holder

The holder goal is to attach a PIXY camera to the mast in a way allowing to easily adjust camera tilt. Moreover, thanks to the special holder ring, it is possible to mount additional camera lens in order to widen the viewing angle.

Camera holder model:

Encoder disc

The controlling system and tracking algorithm take advantage from the encoders, getting the actual rotation speed of the wheels. This information is used as a kind of feedback for the algorithm to know whether desired velocity is achieved or not and adjust controlling signals depending on it.

Currently used encoders are optical, which means that they measure rotation speed basing on the reflection of the laser beam. The optical encoder needs to have a disc reflecting laser beam in a way representing current velocity and for this reason, an encoder disc covered with evenly distributed holes was created. Those holes cause that laser beam is periodically reflected or not and the sensor is able to measure frequency of such blinking.

Encoder disc model:

Mounted encoder disc:

Rear camera holder

The holder was created in order to allow mounting in the future a second camera on the vehicle rear. Using two cameras might enable sensor data fusion and introducing controlling optimization to the algorithm. Additionally holder is stabilizing the rear part of the car and making the chassis more stiff.

Hardware

It was decided that the project will not use the default FRDM-KL25Z microcontroller platform, provided by the NXP Cup organizers, but the custom one, designed and made especially for the application purposes. Creating own platform allowed not only using more advanced and powerful microcontroller unit, but also integrating most of the components on one board, providing comfortable connectors and interfaces, introducing electronic protection circuits and avoiding using lots of connection cables.

Electrical schematic describing connections between all the components and circuits:

Microcontroller board

The main microcontroller board consists of the many different components, but the most important ones are the following:

  • MKV58F1M0VLQ24 - main application microcontroller unit

  • MKL25Z128VLK4 - auxiliary microcontroller unit used for processing data from the sensors purposes

  • Two motor driver integrated circuits

  • Two connectors allowing to plug Bluetooth adapters HC05/HC06 in order to gather logs from the application during car movement

  • Multiple connectors for plugging ultrasonic sensors HC-SR04, laser sensors, encoders, line camera, PIXY camera and UART interfaces

  • Two JTAG connectors for programming and debugging both MCUs

  • 7 segment display

  • Buttons and switches used to customize current application settings and modes

  • ESD protection circuits - ferrites, capacitors, additional insulation layers and dedicated power supply circuit designed to make microcontroller board immune on the ESD

Main board project visualization:

Layout of the created PCBs:

Main board mounted on the car chassis:

Distance sensors extension board

Board contains an address expander allowing to plug and address up to six laser sensors. Communication with the extension board is done using the I2C interface. Moreover the board contains a connector compatible with PIXY J2 connector and connectors for external LEDs.

Detecting obstacles in the wide range caused the necessity of using multiple laser sensors. In order to avoid creating tangle of connection cables, a dedicated distance sensors extension board was made.

Extension board project visualization:

Layout of the created PCBs:

Ready to use extension board:

Firmware

In general firmware may be divided into two main categories regarding main board firmware and the PIXY camera firmware. The reason is that PIXY camera is device programmed with rather complex firmware, supported by the manufacturer and is maintained with a different approach from the actual main board project.

Main board firmware

Main board project firmware includes three build targets for the following platforms:

  • MKV58 - main application microcontroller unit

  • MKL25Z - auxiliary microcontroller unit for sensor data processing purposes

  • x86 - unit tests of the algorithms using Google Tests library

Project structure

The project is IDE agnostic, which means that its structure does not force users to use any specific IDE in order to build the targets. We believe that such an approach is desired and very common in modern programming projects, so IDEs like Visual Studio Code, CLion or Eclipse might be used just in a role of text editors and visual project wrappers, and building the targets is even possible by invoking compiler commands manually from the system command line. This was achieved through the use of the following tools:

  • GCC arm none eabi compiler

  • Ninja build system - generating the executables

  • CMake - playing the role of a cross-platform build environment and injecting files to build to the Ninja build system.

Language

The project source code is written in the C and C++ languages.

As usual, C is used for creating the low level part of the drivers. Drivers and configurations for some of the peripherals were generated using the MCUXpresso IDE from the NXP in order to simplify the development process and avoid configuring device registers manually.

The C++ language was used for implementing algorithms, instantiation of peripheral components and high level management of the application. The project uses C++ in the 20 version, what might seem unnecessary, but as the project is non-commercial and aims at learning new things, it was decided to familiarize with the fresh version of a standard.

Algorithms

PID

The commonly known problem is that some mechanical parts might not act exactly as they should and so the motors do. If some value of voltage is put on them, it is expected to achieve a specific result, but motors final value may differ from the expectation due to friction and strengths distribution during the motion. That’s why PID regulator algorithm was implemented in order to reduce occurring error and always get the proper value of motors. Such an algorithm uses output signal from optical encoders to get real value of motors, compares it with demanded one and performs some changes of controlling signal to bring real value as close as possible to the assumed one.

Example of the PID regulator's calculating method implementation:

PIXY camera firmware

In µVision IDE we redesigned some source code. Camera can detect black and white lines and communicate with main board. We got rid of given code for line detecting. We wrote our new, because it caused us less problems with calibration.

Software 

a) LPC PDF PARSER (lpc branch)

https://github.com/witek117/NXPCup_2020/tree/lpc/software/LPC_PDF_PARSERFor PIXY, LPCOpen was not enough, we needed some CMSIS-like registers description. It took long time to write it on our way, so we created pdf-table parser using C# and .NET with Visual Studio. 

b) MATLAB app for simple car control

https://github.com/witek117/NXPCup_2020/tree/lpc/software/matlab

Make Pixy great again

We also decided to rewrite PixyCam source code. In this project we only need to stream video via USB and detect edges to decide where the track is. Also we do not like using  µVision IDE. For us better is CMake with C++20. We bought a  LPC4330-Xplorer Board with the same microcontroller that is in Pixy.

Source code is on github in lpc branch and LCP directory (target):

https://github.com/witek117/NXPCup_2020/tree/lpc/firmware/car

We use LPCOpen library and old Pixy code. By now all pins are set, both cores (M4 and M0) are working and  USB is properly working with PC.

Plans

  • fully implement obstacle detection
  • design and print models for six  VL53L0X  
  • rewrite the rest of Pixy source code
  • finish and trim all algorithms 
  • design new main board with better H Bridges, build in VL53L0X  connectors and Pixy connector

Code

NXPCup_2021

Credits

Photo of arthrest

arthrest

Embedded software designer.

   

Leave your feedback...