Autonomous car

Remote control and autonomous car with ultrasonic proximity sensor.

Introduction

As part of one of my classes at UTN, an autonomous vehicle named "Cucatesla" was developed, named after its behavior of autonomously moving toward dark areas. (Cucaracha means cockroach in spanish)

The project consisted of designing and implementing an embedded system based on an NXP LPC845 microcontroller, capable of operating in two modes (remote control from a PC and autonomous operation), detecting obstacles through ultrasonic sensors, responding to ambient light variations, and maintaining bidirectional communication with a user interface.

Project Overview

The system architecture is organized around two entities: a base station (PC with a user interface) and the embedded node (LPC845).

  • Development tools: MCUXpresso IDE, standard C for embedded systems, and low-level CMSIS libraries.
  • Communication: Asynchronous serial link (UART) at 9600 baud, using a frame protocol with the structure #[ID][VALUE]$.
  • Input peripherals:
    HC-SR04: Two ultrasonic modules (front and rear) for distance measurement. Their operation was implemented using the CTIMER peripheral in pulse capture mode.
    LDR: Light sensor connected to the LPC845 ADC.
  • Output peripherals:
    DC Motors: Forward and reverse motion control through an H-bridge driven by GPIO signals.
    Servomotors: Two servos (wheel steering and front sensor scanning). PWM signal generation was implemented using the MRT (Multi-Rate Timer).

The control logic was structured around two main state machines: mde_mov (motion management) and mde_com (frame parsing and configuration). The system supports manual commands (movement and steering) as well as an autonomous mode that evaluates distance measurements to determine obstacle avoidance maneuvers.

Drivers

Since the standard NXP SDK was not used, low-level drivers were implemented for the following peripherals:

  • GPIO: Pin control abstraction (SetPIN, GetPIN) and electrical mode configuration (pull-up, push-pull) through the Switch Matrix (SWM).
  • UART0: Complete module with interrupt-driven circular buffers for transmission and reception. Includes string transmission primitives and a frame parser (leerTrama).
  • ADC: Analog-to-digital converter initialization for LDR measurements, including calibration routines and light level calculation with hysteresis.
  • MRT: Configuration of three Multi-Rate Timer channels to generate independent PWM signals for the servomotors in a non-blocking manner.
  • CTIMER: Timer implementation in capture mode to measure the duration of the ultrasonic sensor Echo pulse and calculate distances.

What Did This Project Mean to Me?

This project represented my first experience in embedded systems development, involving a significant learning curve. In particular, we faced two major technical challenges.

One challenge was that the vehicle responded correctly to every command except moving forward. Whenever it started moving, communication would be lost for a few seconds. After extensive trial and error, we discovered that the motors' startup current exceeded the power supply's capabilities, causing the system to momentarily shut down. This experience taught me the multidisciplinary nature of embedded system debugging, where software, mechanical, and electrical issues must all be considered before identifying the root cause.

Another challenge involved implementing the microcontroller's CTIMER peripheral. Despite following the few example codes we could find online and repeatedly reviewing the corresponding section of the reference manual, we ultimately got it working through trial and error, using a configuration that differed from the recommended approach. I remember that only a few weeks after completing the project, ChatGPT was released, and one of my teammates shared screenshots showing that it solved the CTIMER configuration exactly as we had done, but in just a few seconds.

This project was full of first experiences and helped consolidate skills in microcontroller programming, critical interpretation of documentation, firmware architecture design, and hardware-software integration troubleshooting.

Repository

Access to the source code repository can be found here.

Relacionado

Últimos proyectos