1. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
1
Utilizing Scilab and Xcos
for real-time control
and measurement applications
Grzegorz Skiba
Embedded Solutions
skiba.g@embedded-solutions.pl
2. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
2
Agenda
MicroDAQ device and software overview
MicroDAQ toolbox for Scilab
Features overview
Code generation for MicroDAQ DSP core
Tools
Examples
Q&A
3. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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,...
4. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
5. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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 range
166ksps, 8 channel, 16-bit, ±10V range
600ksps, 8 channel, 12-bit, ±10V range
600ksps, 16 channel, 12-bit, ±10V range
500ksps, 16 channel, 16-bit, ±10V range
4000ksps, 2 channel, 16-bit, ±10V range
8 channel, 12-bit, 0-5V range
8 channel, 12-bit, ±10V range
8 channel, 16-bit, ±10V range
Simultanious sampling ADCs
C6000 DSP
375/456MHz
Floating/fixed
point
ARM
375/456MHz
with Linux
PRU0
187/228MHz
32-bit RISC
PRU1
187/228MHz
32-bit RISC
6. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
Host
MLink library
Linux/Windows
UDP/TCP
Ethernet
Wi-Fi
Scilab/Xcos
LabVIEW
Matlab/Simulink
C/C++ application
7. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
7
MicroDAQ toolbox features
Automatic code generation for MicroDAQ DSP
Xcos 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
8. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
9. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
9
MicroDAQ toolbox components
Texas Instruments
Code Composer Studio 5
C6000 DSP compiler
SYS/BIOS RTOS
MicroDAQ
Toolbox
Loading DSP binary
TCP data communication
MLink
DSP drivers for MicroDAQ
TCP data communication
DSPLib
Precompiled Scilab
libraries for DSP core
Scilab libs
10. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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_ping
Connecting to MicroDAQ@10.10.1.1...OK!
Ready to go!
11. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
11
MicroDAQ toolbox blocks
MicroDAQ blocks for
hardware access
Special MicroDAQ blocks for
setup model parameters
Standard Xcos blocks
compiled for DSP
Host simulation mode
and code generation
12. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
13. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
14. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
14
Model execution modes
Model
(Real-time task)
TCP communication
(Idle task)
DSP application
MLink
TCP communication
Xcos
Model
(Real-time task)
DSP application
Ext mode
Standalone mode
16. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
16
Running DSP application with Xcos
simulation
MicroDAQ DSP Xcos
Code generation
Loading DSP on targetInitialize model execution
create TCP server
Wait for connection
Xcos Start button action
connects to MicroDAQ and
starts Xcos simulation
Create connection with host
Execute model
and send data with
SIGNAL block
Xcos simulation
receive data with SIGNAL block
Xcos diagram
17. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
18. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
19. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
19
Execution profiling
Measure model execution time
Optimization
How 'fast' we can run model
Execution profiling macros
mdaq_exec_profile
mdaq_exec_profile_show
20. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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 );
21. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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) */
}
22. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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 hardware
without code generation
Example
IP settings managment
Switching from Ethernet to Wi-Fi
mdaq_pwm_write
mdaq_pwm_init
mdaq_pru_set
mdaq_pru_get
mdaq_led_write
mdaq_key_read
mdaq_hs_ai_read
mdaq_hs_ai_init
mdaq_enc_read
mdaq_enc_init
mdaq_dio_write
mdaq_dio_read
mdaq_dio_func
mdaq_dio_dir
mdaq_ao_write
mdaq_ai_read
Scilab macros: mdaq_ping, mdaq_set_ip
mdaq_set_ip('10.10.2.1');
23. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
23
Model utilization
LabVIEW
Scilab script
Xcos
C/C++
application
24. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
24
Utilizing DSP model in Scilab script
// Start DSP application
result = dsp_start('fft_demo_scigfft_demo.out');
// Register signal ID and signal size
dsp_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))';
end
end
// Stop DSP execution
dsp_stop();
25. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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 );
26. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
26
Utilizing model with LabVIEW
Analog loop
SIGNAL block
MEM read block for model parameter change
27. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
27
Utilizing model with LabVIEW
● Real-time processing
● Live DSP data
● Parameter change during DSP
execution
28. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
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
29. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
29
Q&A
30. Utilizing Scilab and Xcos for real-time control and measurement applications – ScilabTEC 2015
Embedded Solutions; Skiba Grzegorz; skiba.g@embedded-solutions.pl
30
Thnak you!