Você está na página 1de 39

Simulação e desenvolvimento de algoritmos de

tempo real usando Matlab/Simulink através de


bibliotecas externas

Eloy M. de Oliveira Jr.


Agenda

• Introdução
• Biblioteca True Time
• Algoritmo de Sincronização Desenvolvido
• Desenvolvimento de suas próprias bibliotecas
• Simscape
• Conclusão
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO
MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS EXTERNAS

INTRODUÇÃO
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

Complexidade
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

– INDUSTRIA 4.0

– SISTEMA CIBERNÉTICOS-FÍSICOS :

» Integra computação, comunicação e controle em tempo real em diferentes níveis de operação,


usando um grande número de atuadores, sensors e controladores implementados em processadores
que se comunicam.

» Demandam alto desempenho, precisão, acuracia, modularidade, integração, dependabilidade,


segurança e outras habilidades.

» Requerem previsibilidade no dominio lógico e no domínio TEMPORAL.


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS
Sistemas Complexos e Altamente Integrados
INTRODUÇÃO (SAE-ARP4754a)

– INDUSTRIA 4.0

– SISTEMA CIBERNÉTICOS-FÍSICOS :

» Integra computação, comunicação e controle em tempo real em diferentes níveis de operação,


usando um grande número de atuadores, sensors e controladores implementados em processadores
que se comunicam.

» Demandam alto desempenho, precisão, acuracia, modularidade, integração, dependabilidade,


segurança e outras habilidades.

» Requerem previsibilidade no dominio lógico e no domínio TEMPORAL.


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

– Exemplo: Steering-by-wire

– Sistemas Automotivos

Fonte:
Authors: Dilger, E.; Führer T. ; Müller, B.
Paper: The X-By-Wire Concept: Time-Triggered
Information Exchange and Fail Silence Support
by new System Services

Site:
http://www.vmars.tuwien.ac.at/projects/xbywire/
projects/new-bosch.htm
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

– Exemplo: Fly-by-Wire

– Sistemas Aeronáuticos

Fonte:
CONCORDE FLY-BY-WIRE SYSTEM

Site: http://heritageconcorde.com/?page_id=878
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

– Exemplo: Orion Spacecraft

– Sistemas Espaciais

Source:
Orion Mission - http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20100040584.pdf
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

– Exemplo: Cadeia de processo têxtil

– Sistemas Industriais

Source:
“Cyber-Physical Systems in textile production – the next industrial revolution? “ - Yves-
Simon Gloy, Anne Schwarz, Thomas GrieInstitut für Textiltechnik, RWTH Aachen University,
Aachen, GermanyCorresponding Author. Email: yves.gloy@ita.rwthaachen.de
https://www.textile-future.com/textile-manufacturing.php?read_article=1829
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

INTRODUÇÃO

Domínio de
Domínio Domínio
Controle
Computacional Computacional
(Físico)

Domínio de
Comunicação
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO
MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS EXTERNAS

TRUETIME
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

TRUETIME

• Simulador baseado no Matlab/Simulink para sistemas de controle em tempo real.

• Desenvolvida por Henriksson, Cervin e Arzén (2002) – Universidade de Lund – Suécia;

• Desenvolvida na linguagem C/C++;

• Open Source;

• Integrada ao Matlab/Simulink – Com ela é possível usar outras toolboxes e capacidades do Matlab/Simulink
para o desenvolvimento das simulações.
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

TRUETIME

• Com o TrueTime é possível:


– Simular a execução de tarefas em núcleos (kernel) de tempo real
– Simular a transmissão por redes de comunicação
– Integrar tudo a uma planta dinâmica
• O Simulador inclui ainda:
– Possibilidade de similuar controles complexos e as influencias temporais sobre agendamento de
tarefas, redes de comunicação;
– Possibilidade de escrever tarefas utilizando arquivos .M ou funções C++;
– Usar blocos do Simulink junto aos blocos do truetime
– Simular as redes Ethernet, CAN, TDMA, FDMA, Round Robin, Switched Ethernet, FlexRay and
PROFINET)
– Wireless network block (802.11b WLAN and 802.15.4 ZigBee
– Simulação de dispositivos com bateria, Dynamica Voltage Scaling e relógios locais.
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

TRUETIME
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO
MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS EXTERNAS

ALGORITMO DESENVOLVIDO
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Sistema de Controle por Rede

Digital PID

1) Bias Inicial: 2) Derivas: 3) MMCF:


C1: 0; C1: 0; C1: 1;
C2: 0.1 sec; C2: 1%; C2: 2;
CSMA/CD C3: 0.01 sec; C3: 0.01%; C3: 2;
C4: -0.1 sec; C4: -0.01%. C4: 2.

1000
G(s)  2
s s
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS
Diferença
Macrotick Difference Macrotick

ALGORITMO DESENVOLVIDO
0.15
C1 - C2
C1 - C3
C1 - C4
0.1 C2 - C3

(seconds)
macrotick (segundos)
C2 - C4

• Algoritmo FTM
C3 - C4

0.05

DiferençaDifference
Macrotick 0
0.6

Macrotick
C1
C2
0.5 C3 -0.05
C4 Precisão ≈ 50 ms
(macrotick)

0.4
Local(macrotick)

-0.1
0 0.2 0.4 0.6 0.8 1
Relógio deClock
Reference Referência
(seconds) (segundos)
0.3
Algoritmo FTM
FTM Algorithm
RelógioClock

0.08
0.2 C2
C3
Local

0.06 C4
0.1

(seconds)
FTM (segundos)
0.04
0

Correction
0.02
-0.1
0 0.2 0.4 0.6 0.8 1

Correção
Relógio de Referência (segundos)
Reference Clock (seconds) Initial offsets values: 0

FTM
C1: 0;
C2: 0.1 sec; -0.02
Initial De-synchronization C3: 0.01 sec;
C4: -0.1 sec;
-0.04
0 0.2 0.4 0.6 0.8 1
Relógio de Referência (segundos)
Reference Clock (seconds)
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Algoritmo FTM.

Overshoot > 50% Dynamics PID Controller


Controle PID
Dinâmica 4
2
Controle
Controller
Referência
Reference

Resposta
Response 3
1.5

2
1
Resposta Dinâmica (graus)

1
0.5

Controle
Dynamic Response

Controller
0

-0.5
-1
(degree)

-1 -2

-1.5 -3

-2 -4
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Relógio de Referência (segundos) Relógio de Referência (segundos)
Reference Clock (seconds) Reference Clock (seconds)
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO

• O Algoritmo FTM sincroniza o sistema!

• Em contrapartida degrada a resposta do sistema de controle!

• Causa Principal:

– Viés Inicial do Relógio!


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
Algoritmo PReS

STM – DEADBEAT CONTROLLER


STM

T1
NOMO mode -
T4

NOMO NOMO - FTM ALGORITHM


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Projeto do Controlador

Controlador Modelo do Relógio

R(z) + E(z) D(z) μT(z) C(z)

-
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Modelo de Recorrências do Relógio Clock Model:

MICROTICK (mt) LOCAL TIME (LT)

MACROTICK (MT) GLOBAL TIME (GT)

Controlador Deadbeat
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Projeto do Controlador

R(z) + E(z) D(z) μT(z) C(z)

u(k): valor de ajuste no instante k;


ρ: deriva do relógio;
μt(0): offset inicial;
e(k): erro entre o relógio local e de referência.

Função de Ajuste para modo STM:


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Algoritmo PReS

Deadbeat
10 FTM Algorithm
Macrotick
Algoritmo FTM
C2 0.050.6
C1
C2
C3 C2
0.040.5 C3
C4 C3
C4
5 C4
0.03
Correção Deadbeat(segundos)

0.4

FTM Correction (seconds)


Relógio Local(macrotick)
Correção FTM (segundos)
0.02
0 0.3
Deaheat Correction

0.01

0.2
0
-5
(seconds)

-0.010.1

-0.02
0
-10
-0.03
-0.1
0 0.2 0.4 0.6 0.8 1
-0.04
0 0.2 Relógio0.4
de Referência0.6
(segundos) 0.8 1
-15 Relógio de Referência (segundos)
0 0.2 0.4 0.6 0.8 1 Reference Clock (seconds)
Relógio de Referência
Reference (segundos)
Clock (seconds)
Transição
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Algoritmo PReS

Overshoot << 50% Dynamics


Dinâmica PID Controller
Controle PID
1.5
4
Referência
Controle
Resposta
1 3
Resposta Dinâmica (graus)

2
0.5
Dynamic Response

Controller
Controle
0
0
(degree)

-0.5
-1

-1
-2

-1.5 -3
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Relógio de Referência (segundos) Relógio de Referência (segundos)
Reference Clock (seconds) Reference Clock (seconds)
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

ALGORITMO DESENVOLVIDO
• Algoritmo PReS
Em comparação com o algoritmo FTM, ao incluir o modo STM
utilizando o controlador deadbeat, o algoritmo PreS melhora a lei
de controle reduzindo o overshoot sobre a resposta dinâmica.

• Melhor Paper Nacional Congresso SAE Brasil 2015


• Apresentado no Congresso Internacional do SAE 2016 – Detroit – MI - EUA

A New Clock Synchronization Algorithm to Compensate the Initial


De-Synchronization of Clocks Based on a Deadbeat Controller for
Networked Control Systems
Eloy M. Oliveira Jr e Marcelo L. O. Souza
Congresso SAE Brasil 2015
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO
MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS EXTERNAS

DESENVOLVIMENTO DE SUAS
PRÓPRIAS BIBLIOTECAS
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

DESENVOLVIMENTO DE SUAS PRÓPRIAS BIBLIOTECAS

• O Matlab/Simulink permite você criar suas próprias bibliotecas

• Você pode, opcionalmente, inclusive adicionar ao Simulink® Library Browser e usar em seus modelos
quando quiser.
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

DESENVOLVIMENTO DE SUAS PRÓPRIAS BIBLIOTECAS

• Vantagens:

– Reuso de código e simulações.

– Integrar em simulações mais avançadas.

• Desvantagens:

– Geração de Código pode não ser possível

– Você precisa validar o resultado.


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO
MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS EXTERNAS

SIMSCAPE
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

SIMSCAPE

• O Simscape provê uma conjunto de biblioteca de components que cobrem mais de 10 domínios físicos
diferentes;
– Mecânico
– Elétrico
– Hidráulico
– Pneumático,
– Entre outros
• A biblioteca é especialmente projetada para ajudar o usuário a criar components personalizados..
• Todos os components são definidos usando a linguagem Simscape.
• Permite você balancear fidelidade e velocidade de simulação.
• Você pode converter modelos Simscape em Código C, utilizando o Simulink Coder..
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

SIMSCAPE

• Linguagem Simscape:

• Linguagem textual para modelar sistemas físicos

• Contém construções especificas para modelagem física

• Incorpora-se dentro da interface de modelagem Simscape

• Não é focado no desenvolvimento do algoritmo


SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

SIMSCAPE
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO
MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS EXTERNAS

CONCLUSÃO
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

CONCLUSÃO

• Os sistemas estão cada vez mais integrando elementos de pelo menos três domínios de conhecimento, tais
como controle, comunicação e computação.

• A implementação distribuída, a integração de sistemas, a complexidade e o aumento do requisito de


confiabilidade tornam relevantes diversos problemas que antes não o eram, demandando o desenvolvimento
de novas tecnologias, técnicas e algoritmos.

• Com isso, vem de encontro com a necessidade de simulações cada vez mais complexas;

• O ambiente Matlab/Simulink esta se tornando cada vez mais uma ótima ferramenta para se fazer a
modelagem e simulação deste tipo de sistema;
SIMULAÇÃO E DESENVOLVIMENTO DE ALGORITMOS DE TEMPO REAL USANDO MATLAB/SIMULINK ATRAVÉS DE BIBLIOTECAS
EXTERNAS

CONCLUSÃO

• O ambiente Matlab/Simulink esta se tornando cada vez mais uma ótima ferramenta para se fazer a
modelagem e simulação deste tipo de sistema;

• O conjunto de toolboxes e o fácil uso de bibliotecas de terceiros e também de criação de suas próprias
bibliotecas, torna o Matlab/Simulink cada vez mais atrativos;

• O algoritmo desenvolvido, como parte da minha Tese de Doutorado no INPE, só foi possível graças ao uso
da biblioteca TrueTime, desenvolvida pela Universidade de Lund na Suécia.
– Pois requeriu um conjunto de simulações e conhecimento dos três domínios: Controle, Computação e
Comunicação;

• Neste trabalho, explorou-se a sincronização de relógios, mas outras áreas podem ser facilmente exploradas
com a simulação desenvolvida.
OBRIGADO

Você também pode gostar