์๋ฎฌ๋ ์ด์ ์๋ฒ
Python FastAPI ๊ธฐ๋ฐ ์๋ฎฌ๋ ์ด์ ์๋ฒ์ ๊ตฌ์กฐ, ํ๋์จ์ด ํต์ ์ค์ , ์๋ํ ํ์ดํ๋ผ์ธ์ ์ค๋ช ํฉ๋๋ค.
์๋ฒ ๊ตฌ์กฐ
ev-motor-reliability/
โโโ simulation/
โ โโโ domain/ # ์์ ์ํ/๋ฌผ๋ฆฌ ๋ก์ง (numpy, scipy)
โ โโโ runner.py # ์๋ฎฌ๋ ์ด์
์คํ ์ง์
์
โโโ analysis/
โ โโโ domain/ # Weibull ๋ถ์, ์ ๋ขฐ์ฑ ๊ณ์ฐ
โโโ automation/
โ โโโ infrastructure/ # ์๋ฆฌ์ผ, JTAG, ํ์ผ I/O
โ โโโ pipeline.py # ์๋ํ ํ์ดํ๋ผ์ธ ์ค์ผ์คํธ๋ ์ดํฐ
โโโ firmware/
โ โโโ src/
โ โโโ algorithm/ # PID, FOC ์๊ณ ๋ฆฌ์ฆ (C)
โ โโโ hal/ # PWM, ADC, UART ๋๋ผ์ด๋ฒ (C)
โโโ config.yaml # ์ฅ๋น ์ฐ๊ฒฐ ์ค์ (.gitignore)
โโโ requirements.txt๊ณ์ธต ๊ตฌ์กฐ
| ๊ณ์ธต | ๋๋ ํ ๋ฆฌ | ์ญํ | ์์กด์ฑ |
|---|---|---|---|
| Domain | simulation/domain/, analysis/domain/ | ์์ ๊ณ์ฐ ๋ก์ง | numpy, scipy, reliability |
| Application | simulation/runner.py, automation/pipeline.py | ์ํฌํ๋ก์ฐ ์กฐํฉ | Domain ๊ณ์ธต |
| Infrastructure | automation/infrastructure/ | ์ธ๋ถ ์์คํ ํต์ | pyserial, subprocess |
Domain ๊ณ์ธต์ ์ธ๋ถ ์์กด์ฑ์ด ์๋ ์์ ํจ์๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. ํ๋์จ์ด ํต์ ๋ฑ ์ธํ๋ผ ๋ก์ง์ Infrastructure ๊ณ์ธต์ ๊ฒฉ๋ฆฌ๋ฉ๋๋ค.
์๋ฆฌ์ผ ํต์ ์ค์
SMC300 ๋ชจํฐ์ ์ด ํจํค์ง์ UART๋ก ํต์ ํฉ๋๋ค. pyserial์ ์ฌ์ฉํ๋ฉฐ, ์ค์ ์ config.yaml์์ ๊ด๋ฆฌํฉ๋๋ค.
config.yaml ์๋ฆฌ์ผ ์น์
serial:
port: /dev/ttyUSB0 # Windows: COM3
baudrate: 115200
bytesize: 8
parity: none
stopbits: 1
timeout: 3 # ์ฝ๊ธฐ ํ์์์ (์ด)
write_timeout: 3 # ์ฐ๊ธฐ ํ์์์ (์ด)ํต์ ํ๋กํ ์ฝ
DSP(TMS320F2838x)์ ํธ์คํธ PC ๊ฐ UART ํ๋กํ ์ฝ:
| ํ๋ | ํฌ๊ธฐ | ์ค๋ช |
|---|---|---|
| STX | 1 byte | ์์ ๋ฐ์ดํธ (0x02) |
| CMD | 1 byte | ๋ช ๋ น ์ฝ๋ |
| LEN | 2 bytes | ํ์ด๋ก๋ ๊ธธ์ด (Little Endian) |
| PAYLOAD | N bytes | ๋ฐ์ดํฐ |
| CRC | 2 bytes | CRC-16/MODBUS |
| ETX | 1 byte | ์ข ๋ฃ ๋ฐ์ดํธ (0x03) |
์ฃผ์ ๋ช ๋ น ์ฝ๋
| CMD | ๋ฐฉํฅ | ์ค๋ช |
|---|---|---|
| 0x10 | PC โ DSP | ์ํ ์์ |
| 0x11 | PC โ DSP | ์ํ ์ค์ง |
| 0x20 | PC โ DSP | ํ๋ผ๋ฏธํฐ ์ค์ (์๋, ํ ํฌ ๋ช ๋ น) |
| 0x30 | DSP โ PC | ์ค์๊ฐ ๋ฐ์ดํฐ ์ ์ก (์ฃผ๊ธฐ์ ) |
| 0x40 | DSP โ PC | ์๋/๊ณ ์ฅ ์ฝ๋ |
| 0xF0 | ์๋ฐฉํฅ | ํธ๋์ ฐ์ดํฌ (์ฐ๊ฒฐ ํ์ธ) |
์ฐ๊ฒฐ ํ์ธ
# ์๋ฆฌ์ผ ํฌํธ ํ์ธ (Linux/WSL)
ls /dev/ttyUSB*
# ์ฐ๊ฒฐ ํ
์คํธ
python -m automation.infrastructure.serial_test --port /dev/ttyUSB0JTAG ์ฐ๊ฒฐ
SDS200i JTAG ์๋ฎฌ๋ ์ดํฐ๋ฅผ ํตํด DSP ํ์จ์ด๋ฅผ ํ๋์ํ๊ณ ๋๋ฒ๊น ํฉ๋๋ค.
config.yaml JTAG ์น์
jtag:
emulator: SDS200i
connection: usb # USB ์ฐ๊ฒฐ
target: TMS320F28388D
ccs_path: /opt/ti/ccs # Code Composer Studio ์ค์น ๊ฒฝ๋ก
uniflash_path: /opt/ti/uniflash์๋ ํ๋์ (UniFlash CLI)
automation/infrastructure/ ๋ชจ๋์ด UniFlash CLI๋ฅผ ๋ํํ์ฌ ์๋ ํ๋์๋ฅผ ์ง์ํฉ๋๋ค.
# ํ์จ์ด ๋น๋ ํ ์๋ ํ๋์
python -m automation.pipeline --mode flash --firmware firmware/build/motor_control.out๋ด๋ถ์ ์ผ๋ก ๋ค์ UniFlash CLI ๋ช ๋ น์ด ์คํ๋ฉ๋๋ค:
dslite.sh --config=config.ccxml --flash --verify firmware/build/motor_control.outCCS ํ๋ก์ ํธ ๋น๋
์๋ํ ํ์ดํ๋ผ์ธ์์ CCS ํค๋๋ฆฌ์ค ๋น๋๋ฅผ ์ง์ํฉ๋๋ค:
python -m automation.pipeline --mode build --project firmware/์๋ํ ํ์ดํ๋ผ์ธ
automation/pipeline.py๋ ์ํ์ ์ ์ฒด ์ํฌํ๋ก์ฐ๋ฅผ ์ค์ผ์คํธ๋ ์ด์
ํฉ๋๋ค.
ํ์ดํ๋ผ์ธ ๋จ๊ณ
ํ์จ์ด ๋น๋ โ ํ๋์ โ ์๋ฆฌ์ผ ์ฐ๊ฒฐ โ ์ํ ์คํ โ ๋ฐ์ดํฐ ์์ง โ ๋ถ์ โ ๋ณด๊ณ ์| ๋จ๊ณ | ๋ชจ๋ | ์ค๋ช |
|---|---|---|
build | --mode build | CCS ํ๋ก์ ํธ ๋น๋ |
flash | --mode flash | DSP์ ํ์จ์ด ํ๋์ |
acquire | --mode acquire | ์๋ฆฌ์ผ๋ก ์ค์๊ฐ ๋ฐ์ดํฐ ์์ง |
analyze | --mode analyze | Weibull ๋ถ์ ์คํ |
report | --mode report | HTML ๋ณด๊ณ ์ ์์ฑ |
full | --mode full | ์ ์ฒด ํ์ดํ๋ผ์ธ ์์ฐจ ์คํ |
์ ์ฒด ํ์ดํ๋ผ์ธ ์คํ
# ์ ์ฒด ์๋ํ (๋น๋ โ ํ๋์ โ ์์ง โ ๋ถ์ โ ๋ณด๊ณ ์)
python -m automation.pipeline --mode full --config config.yaml
# ๋ฐ์ดํฐ ์์ง + ๋ถ์๋ง
python -m automation.pipeline --mode acquire,analyze --config config.yaml
# ํน์ ๋จ๊ณ๋ถํฐ ์ฌ๊ฐ
python -m automation.pipeline --mode analyze,report --input data/raw/20260308_test.csvํ์ดํ๋ผ์ธ ์ค์
pipeline:
data_dir: data/raw/ # ์์ง ๋ฐ์ดํฐ ์ ์ฅ ๊ฒฝ๋ก
results_dir: results/ # ๋ถ์ ๊ฒฐ๊ณผ ์ ์ฅ ๊ฒฝ๋ก
acquisition:
duration: 3600 # ์์ง ์๊ฐ (์ด)
sample_rate: 1000 # ์ํ๋ง ์ฃผํ์ (Hz)
analysis:
method: mle # ์ถ์ ๋ฒ (mle, rr)
confidence: 0.90 # ์ ๋ขฐ ์์ค
report:
template: templates/default.html
format: html # html, pdfconfig.yaml ์ ์ฒด ๊ตฌ์กฐ
config.yaml์ .gitignore์ ํฌํจ๋์ด ๋ฒ์ ๊ด๋ฆฌ์์ ์ ์ธ๋ฉ๋๋ค. ์ฅ๋น IP, ํฌํธ ๋ฑ ํ๊ฒฝ๋ณ ์ค์ ์ ๋ด์ต๋๋ค.
# config.yaml ์ ์ฒด ์์
serial:
port: /dev/ttyUSB0
baudrate: 115200
bytesize: 8
parity: none
stopbits: 1
timeout: 3
write_timeout: 3
jtag:
emulator: SDS200i
connection: usb
target: TMS320F28388D
ccs_path: /opt/ti/ccs
uniflash_path: /opt/ti/uniflash
pipeline:
data_dir: data/raw/
results_dir: results/
acquisition:
duration: 3600
sample_rate: 1000
analysis:
method: mle
confidence: 0.90
report:
template: templates/default.html
format: html
logging:
level: INFO # DEBUG, INFO, WARNING, ERROR
file: logs/pipeline.log
max_size: 10485760 # 10 MB
backup_count: 5config.example.yaml์ด ์ ์ฅ์์ ํฌํจ๋์ด ์์ผ๋ฏ๋ก, ์ด๋ฅผ ๋ณต์ฌํ์ฌ ํ๊ฒฝ์ ๋ง๊ฒ ์์ ํฉ๋๋ค:
cp config.example.yaml config.yaml