yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ROS Robot Chassis📖
1. Installation Video
  • Ackerman structure chassis
  • Crawler chassis
  • Mecanum Wheel Chassis
  • 4WD chassis
  • Mecanum Wheel Chassis with Robotic arm
2.Robot car driving tutorial
  • 2.1 Control motor
  • 2.2 Timer captures the encoder data
  • 2.3 PID control robot movement
  • 2.4 Mecanum wheel kinematic analysis
  • 2.5 Ackerman kinematic analysis
  • 2.6 4WD kinematic analysis
3.Motor hardware parameters
  • 520Motor parameters
Download
  • 3D Model File
  • ROS Drive Code
Download ZIP

Welcome to ROS Robot Chassis repository

2.2 Timer captures the encoder data

Timer capture encoder data

Timer capture encoder data1. Experiment purpose2. Configuration pin information3. Analysis of experimental flow chart4. Explanation of the core code5. Hardware connection6. Experimental effect

1. Experiment purpose

Use the timer encoder mode function of STM32 to capture the encoder data.

2. Configuration pin information

  1. Import the ioc file from the Motor project, name it Encoder, and then the related driver of serial port 1.

According to the schematic diagram, the two encoders of the four motors are respectively connected to channel 1 and channel 2 of timer 2 3 4 5. The motor M1 corresponds to the timer TIM2, M2 corresponds to TIM4, M3 corresponds to TIM5, and M4 corresponds to TIM3.

image-20220311152029633

  1. Taking the timer TIM2 as an example, the setting methods for TIM3, TIM4, and TIM5 are the same. Select Combined Channels mode as Encoder Mode.

image-20220311154406375

  1. In the settings, change the Encoder Mode to Encoder Mode TI1 and TI2, set it to quadruple frequency, and other parameters are shown below.image-20220311154534666

The final chip configuration pins are as shown below:

image-20220311154742986

3. Analysis of experimental flow chart

image-20220311162249277

4. Explanation of the core code

1.Create new bsp_encoder.h and bsp_encoder.c, and add the following to bsp_encoder.h:

image-20220311154905298

2.Create the following content in the bsp_encoder.c file:

Encoder timer initialization.

image-20220311155015828

3.Read the encoder data.

image-20220311155118686

4.Update the count value of the encoder. It needs to be called every 10 milliseconds.

image-20220311155203831

5.Return to boot up to now the total count of the encoders counted,Encoder_Get_Count_Now returns one-channel, Encoder_Get_ALL returns four-channel.

image-20220311155324653

6.Add the content of encoder initialization in the Bsp_Init() function.

image-20220311160927305

7.The new encoder array is used to save the encoder data, and show_encoder is used to print the encoder count.

image-20220311161423196

8.On the basis of the original control motor, add the function of printing encoder data every 100 milliseconds.image-20220311161403382

5. Hardware connection

The motor connecting line needs to be connected to the corresponding motor as shown below, otherwise it may cause the problem that the program does not match the phenomenon. Motor 1 corresponds to the motor in the upper left corner of the body, Motor 2 corresponds to the motor in the lower left corner, Motor 3 corresponds to the motor in the upper right corner, and Motor 4 corresponds to the motor in the lower right corner.

image-20220311143208773

Due to the relatively large power of the motor, the expansion board should not be powered by USB 5V directly, and must be powered by DC 12V.

Then connect the micro-USB cable to the expansion board and computer.

6. Experimental effect

Since the motor will turn when started, please stand up the car before the experiment, and the motor wheels are suspended to avoid rampage.

After programming the program, the LED light flashes every 200ms. Open the serial port assistant, you can see the encoder data. Press the first time to go forward, the second time to free stop, the third time to reverse, and the fourth time to brake to stop.image-20220311161944101

Control motor
PID control robot movement

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文