Current section
Files
Jump to
Current section
Files
examples/01_ethercat_introduction.livemd
# EtherCAT Introduction
```elixir
Mix.install([
{:kino_ethercat, "~> 0.4.0"}
])
```
## The Ring
One master. Three slaves.
```mermaid
%%{init: {'deterministicIds': true, 'deterministicIDSeed': 'ethercat-intro-ring'}}%%
flowchart LR
M[Master] --> C
subgraph S[Slaves]
C[Coupler]
I[Inputs]
O[Outputs]
C --> I
I --> O
end
```
## One Cycle
The master uses cyclic EtherCAT frames.
```mermaid
%%{init: {'deterministicIds': true, 'deterministicIDSeed': 'ethercat-intro-cycle'}}%%
sequenceDiagram
participant M as Master
participant R as EtherCAT ring
M->>R: cyclic EtherCAT frame
R-->>M: inputs + working counter
M->>M: check the cycle
```
## Start The Simulator
Evaluate the simulator cell, then follow the short instructions in the `Introduction` tab.
<!-- livebook:{"attrs":"eyJjb25uZWN0aW9ucyI6W3sic291cmNlX2lkIjoiMyIsInNvdXJjZV9zaWduYWwiOiJjaDEiLCJ0YXJnZXRfaWQiOiIyIiwidGFyZ2V0X3NpZ25hbCI6ImNoMSJ9XSwiZXhwZXJ0X21vZGUiOmZhbHNlLCJzZWxlY3RlZCI6W3siZHJpdmVyIjoiS2lub0V0aGVyQ0FULkRyaXZlci5FSzExMDAiLCJpZCI6IjEiLCJuYW1lIjoiY291cGxlciJ9LHsiZHJpdmVyIjoiS2lub0V0aGVyQ0FULkRyaXZlci5FTDE4MDkiLCJpZCI6IjIiLCJuYW1lIjoiaW5wdXRzIn0seyJkcml2ZXIiOiJLaW5vRXRoZXJDQVQuRHJpdmVyLkVMMjgwOSIsImlkIjoiMyIsIm5hbWUiOiJvdXRwdXRzIn1dfQ","chunks":null,"kind":"Elixir.KinoEtherCAT.SmartCells.Simulator","livebook_object":"smart_cell"} -->
```elixir
alias EtherCAT.Simulator
alias EtherCAT.Simulator.Slave
simulator_ip = {127, 0, 0, 2}
_ = Simulator.stop()
devices = [
Slave.from_driver(KinoEtherCAT.Driver.EK1100, name: :coupler),
Slave.from_driver(KinoEtherCAT.Driver.EL1809, name: :inputs),
Slave.from_driver(KinoEtherCAT.Driver.EL2809, name: :outputs)
]
{:ok, _supervisor} = Simulator.start(devices: devices, udp: [ip: simulator_ip, port: 34980])
:ok = Slave.connect({:outputs, :ch1}, {:inputs, :ch1})
Kino.Layout.tabs(
Introduction: KinoEtherCAT.introduction(),
Simulator: KinoEtherCAT.simulator(),
Faults: KinoEtherCAT.simulator_faults()
)
```
```mermaid
%%{init: {'deterministicIds': true, 'deterministicIDSeed': 'ethercat-intro-loopback'}}%%
flowchart LR
O[outputs.ch1] --> I[inputs.ch1]
```
This is the small path we will use later:
* `outputs.ch1 -> inputs.ch1`
## Use The Setup Cell
Now do what the simulator `Introduction` tab tells you:
1. Add an `EtherCAT Setup` smart cell below.
2. Keep the default ring names: `coupler`, `inputs`, `outputs`.
3. Evaluate the generated setup code.
That starts the real EtherCAT master session.
## Use The Visualizer
After setup is running, add an `EtherCAT Visualizer` smart cell.
Select only:
* `outputs.ch1`
* `inputs.ch1`
Evaluate the generated widget cell.
## Try ch1
Now use the visualizer.
When you toggle the output, `inputs.ch1` should change too.
```mermaid
%%{init: {'deterministicIds': true, 'deterministicIDSeed': 'ethercat-intro-ch1-sequence'}}%%
sequenceDiagram
participant M as Master
participant O as outputs.ch1
participant I as inputs.ch1
M->>O: write output bit
O->>I: loopback wiring
I-->>M: input bit in next cycle
```