發表文章

(Black Line) Path Tracking Sensors (2022 - 2023)

圖片
  The path sensors are 8 pairs of IR emitter and detector. It provides an 8-bit data which to be translated to the position of the line. There are so many ways to do it. I did it manually by intuition as there are only 256 cases. RES 255 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Put table in flash memory const unsigned char loop_up_table[]= { 0, 1, 2, ... }; Without the keyword const the table will be stored in RAM. But it won't save you flash memory as the initialization data are stored in FLASH. Using const saves RAM and the table is read directly from flash. However, reading flash on AVR is different. In AVR, flash and RAM are on different address buses. It is required to include <pgmspace.h> in order to read program flash.

STM32F103 Blue Pill Adapter Board (MCU Adaptor Board on the Robot Car)

圖片
  Soldering Sequence 1. Resistor 100 ohm (R10, R11) 2. Hearder 4-pin right angle (UART1) 3. LED red x 8 pieces (D0 - D7) 4. LED green (B6) 5. Capacitor (C1, C2) 6. Socket 20-pin x 2 pieces (BD1) 7. Socket 4-pin x 2 pieces (J2, J8) 8. Header 4-pin straight (UART3) 9. Tactile switch (A12) 10. Socket, 4-pin x 2pc (J5, J6), 7-pin (J7)

STM32F103 Black Pill (MCU Board of JoyPad)

圖片
  Component Order in Soldering 1) right angle header 2) 3-pin headers 3) 17-pin headers (fixture required) MCU Pinouts The on-board LED is connected to PB12. Pull it  LOW to turn it on . It can be programmed either through the 4-pin header or through UART1. To program through UART1, set the jumpers to SERIAL PROGRAMMING before powering up. Normally the jumpers should be set in NORMAL MAIN FLASH. Schematic

USB to TTL (RS232) Module

圖片
  The primary use of this USB to TTL module is uploading program to the robot car. Secondly, it helps communication between robot car and a personal computer via the UART interface. The wifi modules can also be connected to PC through this device. Uploading program When connecting to UART of robot car, use the 3.3 volts line. Connecting to UART 2   Connecting to UART 3 Connecting to HC-05 / HC-06 The input voltage of the WiFi modules is 5 volts.

Robot Car Line Track Drawings

圖片
  Arena width = 3 ft, height = 3 ft Download SVG file width="2460mm" height="1320mm"

Programming The Robot Car

圖片
    When connecting the USB2TTL to the control board, NEVER USE THE 5 VOLT LINE . It will burn the microcontroller. You must not power up the control board (inserting USB2TTL to PC will power up the 3.3 volt line) unless all connections are properly established. That is, connect the USB2TTL to the control board first.  Connect the USB2TTL to PC afterward. Blink the LEDs There are three controllable LEDs. A blue LED comes with the MCU module. The control board bears a green LED and a yellow LED. The first program to write is to blink the LEDs in the background and control them in the main() function. /* main.cpp */ oi ai u i e i ; a ou o a e ei e i e ou i u io e u e a e O O O A A O }; e u e o o UE EE E O }; oi e e o o e a e ; i ai oi e UE O ; ai ; ai o 1 e o u i a i e e EE O ; ai ; a o...

PID Speed Control

圖片
    In this post, all codes are NOT tested. the PIDs are not tuned yet. Derived wheel rotation speed from Wheel Count Have you ever calibrated the wheel counter? Let me give you some data. 1. one revolution = 60 counts 2. wheel diameter = 56 mm 3. sampling time = 2.5 ms What do you think about the MAXIMUM change in count per 2.5 ms? Doing a simple arithmetic, you will learn that it is not likely to exceed 15 counts per 2.5 ms. In fact, 1 count per 2.5 ms is equivalent to 1.17 m/s. So 2.5 ms is not suitable for deriving the car speed. 20 ms will give a lowest controllable speed of 15 cm/s. My plan to obtain a speed would be: 1. get the change in count every 2.5 ms and save it for at least 8 cycles. 2. sum up 8 consecutive readings every 2.5 ms to obtain speed as counts per 20 ms. I will use 1 integer to hold 8 samples. Recall that each sample's value would not exceed 15, so 4 bits is enough. Integer is 32 bits long  (stm32f103 is 32-bit MCU), so it can hold 8 samp...