이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.
사용자 지정 타깃에 대한 PIL(Processor-in-the-Loop) 구성
타깃 연결 API를 사용하여 타깃 연결 구성을 생성합니다. 대상 연결 구성을 사용하면 사용자 지정 임베디드 하드웨어에서 PIL(Processor-in-the-Loop) 시뮬레이션을 실행할 수 있습니다.
다음과 같은 방법을 배우게 됩니다:
PIL 시뮬레이션을 지원하도록 빌드 프로세스를 조정하십시오.
타깃 하드웨어에서 PIL 실행 파일을 다운로드하고 실행을 시작하도록 툴을 구성합니다.
타깃 하드웨어에서 PIL 시뮬레이션을 지원하기 위해 호스트와 타깃 간의 통신 채널을 구성합니다.
SIL(Software-in-the-Loop) 시뮬레이션에 맞게 구성된 모델부터 시작하십시오. 이 예제는 PIL 모드에서 모델을 시뮬레이션할 수 있도록 타깃 연결 구성을 설정하는 과정을 안내합니다. 이 예제는 전적으로 사용자의 개발 컴퓨터에서 실행됩니다. 동일한 단계를 따라 사용자 고유의 임베디드 타깃 하드웨어에 대한 연결 구성을 설정할 수 있습니다.
SIL 및 PIL 시뮬레이션을 통해 생성된 코드 테스트하기 및 Create a Target Communication Channel for Processor-in-the-Loop (PIL) Simulation도 참조하십시오.
예비 단계
openExample 명령어를 사용하여 이 예제를 열었다면, 현재 폴더에 sl_customization.m 파일이 생성되어 있습니다. 이 예제의 뒷부분에서 해당 폴더를 검색 경로에 추가하게 됩니다.
폴더 경로를 생성합니다.
sl_customization_path = pwd;
해당 폴더가 이미 검색 경로에 포함되어 있다면, 검색 경로에서 해당 폴더를 제거하십시오.
if contains(path,sl_customization_path) rmpath(sl_customization_path) end
사용자 지정 설정을 초기화합니다.
sl_refresh_customizations
SIL 시뮬레이션을 통해 생성된 코드 테스트하기
SIL용으로 구성된 모델을 시뮬레이션합니다. SIL 시뮬레이션 동작과 일반 시뮬레이션 동작을 비교하여, 개발 컴퓨터에서 컴파일된 생성 코드를 확인하십시오.
예제 모델이 새로 열려 있는지 확인하십시오.
close_system('SILModelBlock',0); close_system('SILCounter',0) open_system('SILModelBlock')
CounterA Model 블록에는 (SIL)이라는 텍스트가 표시되며, 이는 이 블록이 참조하는 모델이 SIL 시뮬레이션용으로 구성되어 있음을 나타냅니다.
시스템 시뮬레이션을 실행하십시오.
set_param('SILModelBlock','StopTime','10'); sim('SILModelBlock');
### Searching for referenced models in model 'SILModelBlock'. ### Total of 1 models to build. ### Searching for referenced models in model 'SILCounter'. ### Total of 1 models to build. ### Starting build procedure for: SILCounter ### Successful completion of build procedure for: SILCounter Build Summary Top model targets: Model Build Reason Status Build Duration ============================================================================================================= SILCounter Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 6.073s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 6.5175s ### Preparing to start SIL simulation ... Building with 'gcc'. MEX completed successfully. ### Updating code generation report with SIL files ... ### Starting SIL simulation for component: SILCounter ### Application stopped ### Stopping SIL simulation for component: SILCounter
타깃 연결 구성
PIL을 위한 타깃 연결 구성 작업을 시작합니다.
타깃 연결 구성 클래스의 로컬 사본을 만드십시오.
src_dir = ... fullfile(matlabroot,'toolbox','coder','simulinkcoder','+coder','+mypil'); if exist(fullfile('.','+mypil'),'dir') rmdir('+mypil','s') end mkdir +mypil copyfile(fullfile(src_dir,'Launcher.m'), '+mypil'); copyfile(fullfile(src_dir,'TargetApplicationFramework.m'), '+mypil'); copyfile(fullfile(src_dir,'ConnectivityConfig.m'), '+mypil');
복사한 파일에 쓰기 권한을 부여하십시오.
fileattrib(fullfile('+mypil', '*'),'+w');
파일의 새로운 위치를 반영하도록 네임스페이스를 업데이트하십시오.
coder.mypil.Utils.UpdateClassName(... './+mypil/ConnectivityConfig.m',... 'coder.mypil',... 'mypil');
현재 폴더에 +mypil 폴더가 생성되었는지 확인하십시오. 이 폴더에는 Launcher.m, TargetApplicationFramework.m, ConnectivityConfig.m 파일이 포함되어 있어야 합니다.
dir './+mypil'. .. ConnectivityConfig.m Launcher.m TargetApplicationFramework.m
PIL 실행 파일을 실행하기 위한 코드 검토
PIL 실행 파일을 실행하기 위한 툴을 구성하는 클래스는 mypil.Launcher입니다. 이 클래스를 편집기에서 엽니다.
edit(which('mypil.Launcher'))이 파일의 내용을 검토하십시오. setArgString 메서드는 실행 파일에 추가적인 명령줄 파라미터를 전달합니다. 이러한 파라미터에는 TCP/IP 포트 번호가 포함될 수 있습니다. 임베디드 프로세서 구현의 경우, 이러한 설정을 하드코딩할 수 있습니다.
전체 타깃 연결 구성 설정
mypil.ConnectivityConfig 클래스를 확인합니다.
edit(which('mypil.ConnectivityConfig'))이 파일의 내용을 검토하십시오. 다음 사항을 파악할 수 있어야 합니다:
TCP/IP 통신 채널의 호스트 측을 구성하는 rtw.connectivity.RtIOStreamHostCommunicator 인스턴스를 생성합니다.
Launcher의 setArgString 메서드를 호출하여 TCP/IP 통신 채널의 타깃 측을 구성합니다.
실행 시간 측정을 위해 타이머를 설정하는 setTimer 호출
실행 시간 프로파일링을 위해 타깃별 맞춤형 타이머를 정의하려면, 코드 대체 라이브러리(Code Replacement Library)를 사용하여 code_profile_read_timer 함수의 대체 함수를 지정해야 합니다. 명령줄 API 또는 crtool 사용자 인터페이스를 사용하십시오.
타깃 측 통신 드라이버 검토
rtiostream_tcpip.c 파일을 확인합니다.
rtiostreamtcpip_dir=fullfile(matlabroot,'toolbox','coder','rtiostream','src',... 'rtiostreamtcpip'); edit(fullfile(rtiostreamtcpip_dir,'rtiostream_tcpip.c'))
이 파일의 맨 아래까지 스크롤합니다. 이 파일에는 rtIOStreamOpen, rtIOStreamSend 및 rtIOStreamRecv 함수의 TCP/IP 구현이 포함되어 있음을 확인할 수 있습니다. 이 함수들은 타깃 하드웨어가 개발 컴퓨터와 통신하는 데 필요합니다. 이러한 각 함수에 대해, 타깃 하드웨어 및 통신 채널에 맞는 구현을 제공해야 합니다.
연결 구성에 타깃 측 통신 드라이버 추가
빌드에 포함할 추가 파일을 구성하는 클래스는 mypil.TargetApplicationFramework입니다. 이 클래스를 편집기에서 엽니다.
edit(which('mypil.TargetApplicationFramework'))sl_customization를 사용하여 타깃 연결 구성을 등록합니다.
새로운 타깃 연결 구성을 사용하려면 sl_customization.m 파일을 제공해야 합니다. 이 파일은 새로운 타깃 연결 구성을 등록하고, 이를 사용하기 위해 필요한 조건을 명시합니다. 이 파일에 명시된 조건에는 시스템 타깃 파일의 이름과 하드웨어 구현 설정이 포함될 수 있습니다.
제공된 sl_customization.m 파일을 확인합니다. 이 예제의 경우, 파일을 수정할 필요는 없습니다.
edit(fullfile(sl_customization_path,'sl_customization.m'))sl_customization.m 파일이 들어 있는 폴더를 검색 경로에 추가한 다음 사용자 지정을 새로 고침하십시오.
addpath(sl_customization_path); sl_refresh_customizations;
PIL 시뮬레이션을 통해 생성된 코드 테스트하기
PIL 시뮬레이션을 실행하십시오.
close_system('SILModelBlock',0) open_system('SILModelBlock') set_param('SILModelBlock/CounterA','SimulationMode','processor-in-the-loop (pil)'); set_param('SILModelBlock','StopTime','10'); sim('SILModelBlock');
### Searching for referenced models in model 'SILModelBlock'. ### Total of 1 models to build. ### Searching for referenced models in model 'SILCounter'. ### Total of 1 models to build. ### Starting build procedure for: SILCounter ### Generated code for 'SILCounter' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for: SILCounter Build Summary Top model targets: Model Build Reason Status Build Duration =================================================================================== SILCounter Compilation artifacts were out of date. Code compiled. 0h 0m 1.0005s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 1.2737s ### Connectivity configuration for component "SILCounter": My PIL Example ### EXECUTING METHOD SETARGSTRING SETARGSTRING called from line 65 of ConnectivityConfig.m ### Preparing to start PIL simulation ... Building with 'gcc'. MEX completed successfully. ### Updating code generation report with PIL files ... ### Starting application: 'SILCounter_ert_rtw/pil/SILCounter' Starting PIL simulation Started new process, pid = 50057 Stopping PIL simulation Terminated process, pid = 50057
앞선 메시지들을 다시 확인합니다. 시뮬레이션이 오류 없이 실행되었는지 확인하십시오. 이제 PIL에 대한 타깃 연결 구성을 완료했습니다. 동일한 API를 사용하여 임베디드 프로세서, 다운로드 툴 및 통신 채널을 원하는 대로 조합하여 연결 구성을 구현할 수 있습니다.
정리
이 예제에서 검색 경로를 제거하십시오.
rmpath(sl_customization_path)
사용자 지정 설정을 초기화합니다.
sl_refresh_customizations
모델을 닫습니다.
close_system('SILModelBlock',0) close_system('SILCounter',0)