Skip to Content

시뮬레이션 서버

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

계층 구조

계층디렉토리역할의존성
Domainsimulation/domain/, analysis/domain/순수 계산 로직numpy, scipy, reliability
Applicationsimulation/runner.py, automation/pipeline.py워크플로우 조합Domain 계층
Infrastructureautomation/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 프로토콜:

필드크기설명
STX1 byte시작 바이트 (0x02)
CMD1 byte명령 코드
LEN2 bytes페이로드 길이 (Little Endian)
PAYLOADN bytes데이터
CRC2 bytesCRC-16/MODBUS
ETX1 byte종료 바이트 (0x03)

주요 명령 코드

CMD방향설명
0x10PC → DSP시험 시작
0x11PC → DSP시험 중지
0x20PC → DSP파라미터 설정 (속도, 토크 명령)
0x30DSP → PC실시간 데이터 전송 (주기적)
0x40DSP → PC알람/고장 코드
0xF0양방향핸드셰이크 (연결 확인)

연결 확인

# 시리얼 포트 확인 (Linux/WSL) ls /dev/ttyUSB* # 연결 테스트 python -m automation.infrastructure.serial_test --port /dev/ttyUSB0

JTAG 연결

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.out

CCS 프로젝트 빌드

자동화 파이프라인에서 CCS 헤드리스 빌드를 지원합니다:

python -m automation.pipeline --mode build --project firmware/

자동화 파이프라인

automation/pipeline.py는 시험의 전체 워크플로우를 오케스트레이션합니다.

파이프라인 단계

펌웨어 빌드 → 플래시 → 시리얼 연결 → 시험 실행 → 데이터 수집 → 분석 → 보고서
단계모드설명
build--mode buildCCS 프로젝트 빌드
flash--mode flashDSP에 펌웨어 플래시
acquire--mode acquire시리얼로 실시간 데이터 수집
analyze--mode analyzeWeibull 분석 실행
report--mode reportHTML 보고서 생성
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, pdf

config.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: 5

config.example.yaml이 저장소에 포함되어 있으므로, 이를 복사하여 환경에 맞게 수정합니다:

cp config.example.yaml config.yaml
Last updated on