Basic Motion Detection

Lab 3: ตรวจจับการเคลื่อนไหว

วัตถุประสงค์

  • Activity Detection: ตรวจจับว่าอุปกรณ์เคลื่อนไหวหรือไม่

  • State Classification: แบ่งประเภทการเคลื่อนไหว

  • Event Triggering: ทำ action เมื่อตรวจพบ motion

จะได้เรียนรู้อะไร

  • Threshold Logic: ใช้ค่า threshold ในการตัดสินใจ

  • Enum States: สร้าง motion states

  • fabsf(): คำนวณค่า absolute

Concept: Motion Detection

หลักการ:

  • เมื่อนิ่ง: Magnitude ≈ 1g (9.81 m/s²)

  • เมื่อเคลื่อนไหว: Magnitude เบี่ยงเบนจาก 1g

ใช้ Threshold:

  • threshold = 0.3g (ประมาณ 3 m/s²)

  • ถ้าค่า absolute ของ |magnitude - 1g| > threshold แสดงว่า Motion Detected!

ระดับ:

  • < 0.1g: STATIONARY

  • < 0.3g: LIGHT

  • < 0.6g: MODERATE

  • >= 0.6g: INTENSE

โหลด Project Code จาก AIC Github Repo เพื่อเปิดบน VSCode IDE

3.1 เปิดโปรเจกต์ aic-psoc-edge-epc2-imu-motion

เปิดไฟล์ proj_cm33_ns/sensor_hub_daq_task.c และศึกษาโครงสร้าง:

เพิ่ม Include

Important Macros and Variables

สร้างฟังก์ชัน Raw accelerometer Conversion ชื่อ lsb_to_mp2()

สร้างฟังก์ชัน Magnitude Calcuation ชื่อ calculate_magnitude()

สร้างฟังก์ชัน Motion Detection ชื่อ detect_motion()

สร้างฟังก์ชัน Motion State Conversion ชื่อ get_motion_string()

3.2 เขียน Main Task Loop

Create Sensor Hub DAQ Task Function

3.3 Build และ Flash

3.4 Output ที่คาดหวัง

State Diagram


✍️ Exercise

  1. Free Fall Detection - เพิ่มฟังก์ชันตรวจจับการตกอิสระ (magnitude < 0.3g)

circle-info

Hint

  1. Impact Detection - เพิ่มฟังก์ชันตรวจจับการกระแทก (magnitude > 3g)

circle-info

Hint


จบ Session 2 | ต่อไป: Session 3: LVGL Display

Last updated

Was this helpful?