Acceleration Magnitude

Lab 2: คำนวณ Acceleration Magnitude

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

  • Motion Detection: ขนาดของ acceleration บอกระดับการเคลื่อนไหว

  • Gravity Reference: วางนิ่ง = 1g (9.81 m/s²)

  • Impact Detection: ตกกระแทก = magnitude spike

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

  1. Vector Magnitude: √(x² + y² + z²)

  2. Math Functions: sqrtf()

  3. Physical Meaning: ความหมายของ magnitude

2.1 Concept: Vector Magnitude

magnitude=x2+y2+z2\text{magnitude} = \sqrt{x^2 + y^2 + z^2}
circle-info

เมื่อวางราบ:

  • x ≈ 0, y ≈ 0, z ≈ 9.81

  • Magnitude ≈ 9.81 m/s² (1g)

เมื่อเคลื่อนไหว:

  • Magnitude > 9.81 หรือ < 9.81

  • สามารถใช้ตรวจจับการเคลื่อนไหว!

เมื่อตกอิสระ:

  • Magnitude ≈ 0 (weightlessness)

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

2.2 เปิดโปรเจกต์ aic-psoc-edge-epc2-imu-magnitude-master

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

เพิ่ม Include

Important Macros and Variables

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

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

2.3 เขียน Main Task Loop

Create Sensor Hub DAQ Task Function

2.4 Build และ Flash

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

Physical Meaning

สถานะ
Magnitude
ความหมาย

วางนิ่ง

≈ 9.81 m/s²

1g จากแรงโน้มถ่วง

เคลื่อนไหวเบา

9.5-10.5 m/s²

±0.1g deviation

เคลื่อนไหวปานกลาง

8-12 m/s²

±0.3g deviation

ตกกระแทก

> 20 m/s²

> 2g (impact)

ตกอิสระ

≈ 0 m/s²

Weightlessness

Flowchart


✍️ Exercise

1. G-Force Display : แสดงค่า magnitude ในหน่วย g พร้อม visual indicator

circle-info

Hint

  1. Max/Min Tracking : เก็บค่า max และ min magnitude ที่เคยวัดได้

circle-info

Hint


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

Last updated

Was this helpful?