๐Ÿ’พ
EC
  • Introduction
  • EC Course
    • Syllabus
    • Preparation for EC
    • Tutorial
      • Tutorial: arduino-stm32
        • Tutorial: arduino-stm32 Installation
        • Tutorial: arduino-stm32 Part1
        • Tutorial: arduino-stm32 Part2
      • Tutorial: MDK uVision
        • Tutorial: Installing MDK uVision
        • Tutorial: Create a Project with uVision
        • Tutorial: Adding library header in uVision
        • Tutorial: Re-using Project Configuration
        • Debugging in uVision
      • Tutorial: PlatformIO in CLion
      • Tutorial: PlatformIO in VSCode
      • Tutorial: Repository Management
      • Tutorial: Managing library header files
      • Tutorial: PinName Configuration
      • Tutorial: Bitwise Macro
      • Tutorial: Custom initialization
      • Tutorial: Documentation
      • Tutorial: Creating Application API
      • Tutorial: 7-Segment Display
      • Tutorial: DC motor driver connection
      • Tutorial: USART with TeraTerm
      • Tutorial: Finite State Machine programming
      • Tutorial: Bluetooth
      • Tutorial: Zigbee with Nucleo board
    • LAB
      • LAB Report Template
      • LAB: Smart mini-fan with STM32-duino
      • LAB: Portable Fan with mbed
      • LAB: GPIO Digital InOut
      • LAB: GPIO Digital InOut 7-segment
      • LAB: EXTI & SysTick
      • LAB: Timer & PWM
      • LAB: Stepper Motor
      • LAB: Input Capture - Ultrasonic
      • LAB: USART - LED, Bluetooth
      • LAB: ADC - IR reflective sensor
      • LAB: Line Tracing RC Car
    • Sample code
      • Code Templates
    • Hardware
      • Nucleo-F411RE
      • LAB Hardware
        • Electronic Chips
        • HUINS Embedded Kit
    • Projects
      • Line Tracing Car Project
      • Design Project
        • Past Projects
      • Project Grading Criteria
    • Study Resource for MCU
      • Hexa-Decimal Table
      • Bitwise Op for Register
      • System Clock
      • Timer
      • USART
      • ADC
  • STM32 M4 Programming
    • Documentation
      • C++ API Docs
    • Firmware Library
      • PinName Configuration
      • GPIO Digital
      • RCC
      • EXTI_SysTick
      • TIMER
      • USART
    • Troubleshooting
    • mbed for STM32
      • Tutorial: mbed-Part 1
      • Tutorial: mbed - Part 2
      • Tutorial: mbed - Part 3
      • Using mbed API on uVision
    • mbed OS
  • Other Programming
    • Arduino
    • Socket Programming
      • Window Socket Programming
      • Arduino WiFi
    • Cube-MX
    • Github
    • Markdown
      • Example: API documentation
    • MATLAB
  • C Programming
    • C-Programming Lessons
      • Installing Visual Studio Community
        • Visual Studio Community 2022
      • Installing VS Code(Mac/Linux)
      • Creating Header Lib
      • Pointer
      • Array
      • 2D Array
      • Structure
      • Dynamic Alloc
      • Bitwise Operation
  • Numerical Programming
    • Syllabus
    • Preparation for NP
    • Math Review
    • Tutorial
      • TA Session Video
      • Tutorial: NP Library Header Files
      • Tutorial - Sine Taylor
      • Tutorial: Passing a Function, Function callback
      • Tutorial: Nonlinear solver
      • Tutorial: Differentiation
      • Tutorial: Integration
      • Tutorial: Matrix Structure
      • Tutorial: Eigenvalue problem
      • Tutorial: ODE-IVP
      • Tutorial: Curve Fitting
      • Tutorial: Create Github Repos of NP lib
      • Tutorial: Version Control in Github
      • Tutorial: Documentation with Markdown
      • Exercise: Version Control and Documentation
    • Example: MATLAB
    • Example: NP Library
    • Assignment
      • Assignment Factorial and Power
      • Assignment: Version Control and Documentation
    • Problem Bank
Powered by GitBook
On this page
  • Introduction
  • Requirement
  • Preparation
  • Tutorials:
  • LABS:
  • Problem Definition
  • Manual Mode
  • Automatic Mode
  • Procedure
  • Circuit Diagram
  • Code
  • Results
  • Reference
  • Troubleshooting
  • 1. motor PWM duty ratio for different DIR
  • 2. Print a string for BT (USART1)
  • 3. Motor does not run under duty 0.5
  • 4. Check and give different Interrupt Priority
  • 5. Ultrasoninc sensor does not measure properly when MCU is connected with motor driver

Was this helpful?

  1. EC Course
  2. LAB

LAB: Line Tracing RC Car

PreviousLAB: ADC - IR reflective sensorNextSample code

Last updated 6 months ago

Was this helpful?

Date: 2023-09-26

Author/Partner:

Github: repository link

Demo Video: Youtube link

PDF version:

Introduction

Design an embedded system to control an RC car to drive on the racing track. The car is controlled either manually with wireless communication or automatically to drive around the track. When it sees an obstacle on the driving path, it should temporarily stop until the obstacle is out of the path.

There can be more missions to complete.

Requirement

Hardware

  • MCU

    • NUCLEO-F411RE

  • Actuator/Sensor/Others: Minimum

    • Bluetooth Module(HC-06)

    • DC motor x2, DC motor driver(L9110s)

    • IR Reflective Sensor (TCRT 5000) x2

    • HC-SR04

    • additional sensor/actuators are acceptable

Software

  • Keil uVision, CMSIS, EC_HAL library

Preparation

Tutorials:

Complete the following tutorials:

Use ecSTM32F411.h and void MCU_init(void) in your project code.

LABS:

You should review previous labs for help

  1. LAB: ADC IR Sensor

  2. LAB: USART Bluetooth

  3. LAB: Timer & PWM

Problem Definition

Design your RC car that has the following functions:

  1. Line tracing on the given racing track

  2. has 2 control modes: Manual Mode to AUTO Mode

  3. stops temporally when it detects an object nearby on the driving path

On the PC, connected to MCU via bluetooth

  • Print the car status every 1 sec such as โ€œ ( โ€œ MOD: A DIR: F STR: 00 VEL: 00 โ€)

Manual Mode

  • Mode Change( MOD):

    • When 'M' or 'm' is pressed, it should enter Manual Mode

    • LD2 should be ON in Manual Mode

  • Speed (VEL):

    • Increase or decrease speed each time you push the arrow key โ€œUPโ€ or โ€œDOWNโ€, respectively.

    • You can choose the speed keys

    • Choose the speed level: V0 ~ V3

  • Steer (STR):

    • Steering control with keyboard keys

    • Increase or decrease the steering angles each time you press the arrow key โ€œRIGHTโ€ or โ€œLEFTโ€, respectively.

    • Steer angles with 3 levels for both sides: e.g: -3, -2, -1, 0, 1, 2, 3 // '-' angle is turning to left

  • Driving Direction (DIR)

    • Driving direction is forward or backward by pressing the key โ€œFโ€ or โ€œBโ€, respectively.

    • You can choose the control keys

  • Emergency Stop

    • RC car must stop running when key โ€œSโ€ is pressed.

Automatic Mode

  • Mode Change:

    • When 'A' or 'a' is pressed, it should enter AUTO Mode

  • LD2 should blink at 1 second rate in AUTO Mode

  • It should drive on the racing track continuously

  • Stops temporally when it detects an object nearby on the driving path

  • If the obstacle is removed, it should drive continuously

Procedure

  1. Discuss with the teammate how to design an algorithm for this problem

  2. In the report, you need to explain concisely how your system works with state tables/diagram or flow-chart.

    โ— Listing all necessary states (states, input, output etc) to implement this design problem.

    โ— Listing all necessary conditional FLAGS for programming.

    โ— Showing the logic flow from the initialization

    and more

  3. Select appropriate configurations for the design problem. Fill in the table.

Functions

Register

PORT_PIN

Configuration

System Clock

RCC

PLL 84MHz

delay_ms

SysTick

Motor DIR

Digital Out

โ€ฆ.

TIMER

TIMER1

TIMER2

Timer Interrupt

...

10msec

ADC

ADC

โ€ฆ.

DC Motor Speed

PWM2

ADC sampling trigger

PWM3

RS-232 USB cable(ST-LINK)

USART2

No Parity, 8-bit Data, 1-bit Stop bit 38400 baud-rate

Bluetooth

USART1

TXD: PA9 RXD: PA10

No Parity, 8-bit Data, 1-bit Stop bit 9600 baud-rate

  1. Create a new project under the directory \repos\EC\LAB\LAB_RCcar

  • The project name is โ€œLAB_RCcarโ€

  • You can share the same code with your teammate. But need to write the report individually

Circuit Diagram

You need to include the circuit diagram

Code

// YOUR MAIN CODE ONLY
// YOUR CODE with Comments

Results

Experiment images and results

Show experiment images /results

Reference

Complete list of all references used (github, blog, paper, etc)

Troubleshooting

1. motor PWM duty ratio for different DIR

When, DIR=0 duty=0.8--> PWM 0.8 // ์‹ค์ œ ๋ชจํ„ฐ์— ์ „๋‹ฌ๋˜๋Š” pwm

Whe, DIR=1 duty=0.8--> PWM 0.2 // ์‹ค์ œ ๋ชจํ„ฐ์— ์ „๋‹ฌ๋˜๋Š” PWM

*** a solution ***

float targetPWM;  // pwm for motor input 
float duty=abs(DIR-targetPWM); // duty with consideration of DIR=1 or 0

PWM_duty(PWM_PIN, duty);

2. Print a string for BT (USART1)

Use sprintf()

#define _CRT_SECURE_NO_WARNINGS    // sprintf ๋ณด์•ˆ ๊ฒฝ๊ณ ๋กœ ์ธํ•œ ์ปดํŒŒ์ผ ์—๋Ÿฌ ๋ฐฉ์ง€
#include <stdio.h>     // sprintf ํ•จ์ˆ˜๊ฐ€ ์„ ์–ธ๋œ ํ—ค๋” ํŒŒ์ผ

char BT_string[20]=0;

int main()
{
	sprintf(BT_string, "DIR:%d PWM: %0.2f\n", dir, duty);    // ๋ฌธ์ž, ์ •์ˆ˜, ์‹ค์ˆ˜๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ฆ
	USART1_write(BT_string, 20);
	// ...
}

https://dojang.io/mod/page/view.php?id=352 **

3. Motor does not run under duty 0.5

SOL) Configure motor PWM period as 1kHa

4. Check and give different Interrupt Priority

Check if you have different NVIC priority number for each IRQs

5. Ultrasoninc sensor does not measure properly when MCU is connected with motor driver

SOL) Give independent voltage source to motor driver. Giving DC power from MCU to motor driver is not recommended

image

image

Your code goes here:

Add

TU: Managing library header files
TU: Custom initialization
ADD Code LINK such as github
demo video link