Upload
others
View
34
Download
2
Embed Size (px)
Citation preview
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
1
Utilizing Scilab and Xcos for real-time control and measurement applicationsGrzegorz SkibaEmbedded Solutions [email protected]
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
2
Agenda
MicroDAQ device and software overview MicroDAQ toolbox for Scilab
Features overview Code generation for MicroDAQ DSP core Tools Examples
Q&A
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
3
MicroDAQ device
Real-time control and measurement system Dedicated DSP core for signal
and real-time processing Ethernet, USB2.0 and WiFi connectivity ADC, DAC, DIO, PWM, Encoder,...
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
4
MicroDAQ device
MicroDAQ E1100
375MHz CPU 4GB flash memory Ethernet Wi-Fi USB2.0 32 DIO lines 8 analog inputs 8 analog outputs Matlab/Simulink, LabVIEW
and Scilab support Price from 200€
MicroDAQ E2000
up to 456MHz CPU up to 32GB flash memory Ethernet Wi-Fi USB2.0 16 DIO lines up to 16 analog inputs 8 analog outputs Matlab/Simulink, LabVIEW,
Scilab support Price from 400€
MicroDAQ OEM
375MHz CPU 4GB flash memory Ethernet USB2.0 USB1.1 32 DIO lines 8 analog inputs 8 analog outputs Matlab/Simulink, LabVIEW,
Scilab support
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
5
MicroDAQ device Processing units
TI C6000 DSP core with floating/fixed point unit ARM core with Linux OS for handling communication,
file storage, web interface two PRU 32-bit RISC cores for real-time processing
Storage up to 32GB Digital I/O
16/32 DIOs, 6 PWMs, 2 Encoders, UART
Analog I/O
Analog input Analog output
166ksps, 8 channel, 12-bit, ±10V range166ksps, 8 channel, 16-bit, ±10V range
600ksps, 8 channel, 12-bit, ±10V range600ksps, 16 channel, 12-bit, ±10V range500ksps, 16 channel, 16-bit, ±10V range4000ksps, 2 channel, 16-bit, ±10V range
8 channel, 12-bit, 0-5V range8 channel, 12-bit, ±10V range8 channel, 16-bit, ±10V range
Simultanious sampling ADCs
C6000 DSP375/456MHzFloating/fixed
point
ARM375/456MHz
with Linux
PRU0187/228MHz32-bit RISC
PRU1187/228MHz32-bit RISC
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
6
MicroDAQ software
MLink software Windows/Linux support Access to MicroDAQ resources Loading DSP Scilab support functions
DSPLib LabVIEW support package Matlab/Simulink Embedded Coder target MicroDAQ toolbox for Scilab
Available at: https://github.com/microdaq
HostMLink library
Linux/Windows
UDP/TCP
EthernetWi-Fi
Scilab/XcosLabVIEW
Matlab/SimulinkC/C++ application
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
7
MicroDAQ toolbox features
Automatic code generation for MicroDAQ DSP Xcos blocks for MicroDAQ peripherals Live data access from generated DSP
application via Ethernet and WiFi with standard Xcos sinks
Application loading with Ethernet and WiFi Standalone mode Easy integration of custom user C code
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
8
MicroDAQ toolbox features
MicroDAQ hardware (ADC, DAC...) access macros
DSP model utilization with Scilab script, C/C++ application and LabVIEW
Execution profiling Toolbox as a part for Atoms installer Support for Linux and Windows
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
9
MicroDAQ toolbox components
Texas Instruments Code Composer Studio 5
C6000 DSP compiler SYS/BIOS RTOS
MicroDAQ Toolbox
Loading DSP binaryTCP data communication
MLink
DSP drivers for MicroDAQTCP data communication
DSPLibPrecompiled Scilab
libraries for DSP core
Scilab libs
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
10
Installation Atoms → Instrumentn Control → MicroDAQ Toolbox Install Code Composer Studio 5.5 – with C6000 DSP compiler
and SYS/BIOS RTOS microdaq_setup Code Composer Studio
installation paths SYS/BIOS RTOS compilation connect MicroDAQ device
and setup IP settings check connection
-->mdaq_pingConnecting to [email protected]!
Ready to go!
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
11
MicroDAQ toolbox blocks
MicroDAQ blocks for hardware access
Special MicroDAQ blocks forsetup model parameters
Standard Xcos blocks compiled for DSP
Host simulation mode and code generation
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
12
MicroDAQ special blocks
SETUP block Simulation duration Build type: debug/release Build mode: Ext/Standalone Execution profiling ODE solver type
SIGNAL block receive live data from DSP
STOP block
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
13
Xcos diagram for code generation
SETUP block Event generator to set step time Superblock for code generation Tools → MicroDAQ build
and load model Execution mode
Standalone – load and start model on DSP immediately
Ext – load model on DSP and wait for user action
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
14
Model execution modes
Model(Real-time task)
TCP communication(Idle task)
DSP application
MLinkTCP communication
Xcos
Model(Real-time task)
DSP application
Ext mode
Standalone mode
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
15
Code generation
### Generating block structure... ### Writing generated code... ### Generating Makefile... ### Generating binary file... "C:\ti\ccsv5\tools\compiler\c6000_7.4.4/bin/cl6x" -c -g -mv6740…"C:\ti\ccsv5\tools\compiler\c6000_7.4.4/bin/cl6x" -c -g -mv6740…"C:\ti\ccsv5\tools\compiler\c6000_7.4.4/bin/cl6x" -c -g -mv6740…"C:\ti\ccsv5\tools\compiler\c6000_7.4.4/bin/cl6x" -c -g -mv6740…<Linking>"MicroDAQ DSP application led_demo.out created successfully"
Xcosdiagram
mdaq_ext_main.c ormdaq_standalone_main.c
C code generation
C6000 DSP compiler
C6000 linker
SYS/BIOS RTOS
DSPLib
MicroDAQ blocks
Scilab libs
DSP binary
Makefile generation
SETUP block
Loading DSP binary
User blocks lib
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
16
Running DSP application with Xcos simulation
MicroDAQ DSP Xcos
Code generation
Loading DSP on targetInitialize model executioncreate TCP server
Wait for connection
Xcos Start button actionconnects to MicroDAQ and
starts Xcos simulationCreate connection with host
Execute model and send data with
SIGNAL blockXcos simulation
receive data with SIGNAL block
Xcos diagram
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
17
Running DSP application with Xcos simulation
Generated DSP code
int sin_demo_isr(double t){ int local_flag; int i; double *args[100]; /* Output computation */ /* Discrete activations */ /* Blocks activated on the event number 1 */ /* Call of 'mdaq_sinus' (type 4 - blk nb 2) */ block_sin_demo[1].nevprt = 1; local_flag = 1; mdaq_sinus(&block_sin_demo[1],local_flag); /* Call of 'mdaq_signal' (type 4 - blk nb 3) */ block_sin_demo[2].nevprt = 1; local_flag = 1; mdaq_signal(&block_sin_demo[2],local_flag); /* Call of 'cscope' (type 4 - blk nb 4) */ block_sin_demo[3].nevprt = 1; local_flag = 1; cscope(&block_sin_demo[3],local_flag); return 0;}
Xcos simulation
● When DSP is loaded SIGNAL input is ignored
● SIGNAL block receives data from MicroDAQ
● When DSP in not loaded copy SIGNAL block input to output
● mdaq_signal() funciton puts data to IDLE communication task
● cscope() function is empty
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
18
DC motor controller
● Sample time: 0.001s
● Discrite PD controller
● H-bridge for driving DC motor
● Live data with standard CSCOPE block
● Loging data to workspace with standard 'To workspace' block
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
19
Execution profiling
Measure model execution time Optimization How 'fast' we can run model Execution profiling macros
mdaq_exec_profile mdaq_exec_profile_show
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
20
Custom user code
For new user creating custom block is a tough task Block code and C code generation Created code can be compiled for debug and
release Block creation utility macros
mdaq_block(); mdaq_block_add(); mdaq_block_build( %t );
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
21
User custom code-->my_block = mdaq_block(); -->my_block my_block = name: "new_block" desc: "Set new_block parameters" param_name: [2x1 string] param_size: [2x1 constant] param_def_val: list in: 1 out: 1
-->my_block.param_name ans = !param1 !! !!param2 ! -->mdaq_block_add(my_block);
/* Generated with MicroDAQ toolbox ver: 1.0. */#include "scicos_block4.h"
extern double get_scicos_time( void );
/* This function will executed once at the beginning of model execution */static void init(scicos_block *block){ /* Block parameters */ double *params = GetRparPtrs(block);
/* param size = 1 */ double param1 = params[0]; /* param size = 1 */ double param2 = params[1];
/* Add block init code here */}
/* This function will be executed on every model step */static void inout(scicos_block *block){ /* Block parameters */ double *params = GetRparPtrs(block); /* param size = 1 */ double param1 = params[0]; /* param size = 1 */ double param2 = params[1];
/* Block input ports */ double *u1 = GetRealInPortPtrs(block,1); int u1_size = GetInPortRows(block,1); /* u1_size = 1 */
/* Block output ports */ double *y1 = GetRealOutPortPtrs(block,1); int y1_size = GetOutPortRows(block,1); /* y1_size = 1 */
/* Add block code here (executed every model step) */}
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
22
MicroDAQ hardware access macros
link_id = mdaq_open();
ai_data = mdaq_ai_read(link_id, [1 2 3 4 5 6 7 8], 10, 1)
mdaq_close(link_id);
Access to MicroDAQ hardwarewithout code generation
Example
IP settings managment
Switching from Ethernet to Wi-Fi
mdaq_pwm_writemdaq_pwm_initmdaq_pru_setmdaq_pru_getmdaq_led_writemdaq_key_readmdaq_hs_ai_readmdaq_hs_ai_initmdaq_enc_readmdaq_enc_initmdaq_dio_writemdaq_dio_readmdaq_dio_funcmdaq_dio_dirmdaq_ao_writemdaq_ai_read
Scilab macros: mdaq_ping, mdaq_set_ip
mdaq_set_ip('10.10.2.1');
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
23
Model utilization
LabVIEW
Scilab scriptXcos
C/C++application
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
24
Utilizing DSP model in Scilab script// Start DSP applicationresult = dsp_start('fft_demo_scig\fft_demo.out');
// Register signal ID and signal sizedsp_signal(123, 1);
first_time = 1; a = [];// Process data from DSP sample_count = 500;for i=1:500 [result, s] = dsp_signal_get(sample_count);
t = 0:1/sample_count:1; N=size(t,'*'); //number of samples y=fft(s');
f=sample_count*(0:(N/2))/N; //associated frequency vector n=size(f,'*') if first_time == 1 then clf() plot(f,abs(y(1:n))) first_time = 0; a = gca(); else a.children.children.data(:,2) = abs(y(1:n))'; endend
// Stop DSP executiondsp_stop();
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
25
Utilizing model with C/C++ application Embed Xcos generated model in Windows/Linux
application MLink interface functions
Example code
scilab_dsp_start("10.10.1.1", &port, "q:\\analog_loop.out", &link_id); scilab_signal_register(&link_id, &id, &size, &result); for (count = 0; count < 100; count++){
scilab_signal_read(&link_id, buf, &size, &result); /* process DSP data */ scilab_mem_write(&link_id, 1, param, 2);
}scilab_dsp_stop(&link_id, &result);
●
/* Scilab interface funcations */ EXTERNC MDAQ_API void scilab_dsp_start( const char *addr, int *port, const char *dspapp, int *link_id );EXTERNC MDAQ_API void scilab_dsp_stop( int *link_id, int *result );EXTERNC MDAQ_API void scilab_signal_register( int *link_id, int32_t *id, int32_t *size, int *result );EXTERNC MDAQ_API void scilab_signal_read( int *link_id, double *data, int32_t *count, int *result );EXTERNC MDAQ_API int scilab_mem_read( int *link_id, int start_idx, int len, float *data );EXTERNC MDAQ_API int scilab_mem_write( int *link_id, int start_idx, float data[], int len );
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
26
Utilizing model with LabVIEW
Analog loop SIGNAL block MEM read block for model parameter change
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
27
Utilizing model with LabVIEW● Real-time processing
● Live DSP data
● Parameter change during DSP execution
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
28
Conclusions
Code generation from Xcos diagram Real-time procesing Execution profiling DSP binary utilization with LabVIEW and
Windows/Linux C/C++ applications Different hardware options avaliable Easy to use Free alternative for commercial solutions
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
29
Q&A
Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015 Embedded Solutions; Skiba Grzegorz; [email protected]
30
Thnak you!