Download - ScicosLab and CANopen - SUPSI
![Page 1: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/1.jpg)
CAN SCICOS CAN200 Example
ScicosLab and CANopen
Ing. Roberto Bucher
Scuola Universitaria Professionale della Svizzera Italiana (SUPSI)
Manno - July 1. 2009
![Page 2: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/2.jpg)
CAN SCICOS CAN200 Example
Objectives
See how CANopen devices can be integrated in a Scicos blockdiagram
Learn how to implement new CANopen devices
Introduce the CAN200 interface dongle
![Page 3: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/3.jpg)
CAN SCICOS CAN200 Example
Outline
1 CAN and CANopen
2 Scicos and CANopen
3 The CAN200 card
4 Example
![Page 4: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/4.jpg)
CAN SCICOS CAN200 Example
CAN
Controller Area Network
Controller area network (CAN or CAN-bus) is a vehicle busstandard designed to allow microcontrollers and devices tocommunicate with each other within a vehicle without a hostcomputer.
It was designed specifically for automotive applications but isnow also used in other areas.
Development of the CAN-bus started originally in 1983 atRobert Bosch GmbH.
![Page 5: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/5.jpg)
CAN SCICOS CAN200 Example
CAN
Interface
![Page 6: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/6.jpg)
CAN SCICOS CAN200 Example
CANopen
CANopen
CANopen is a communication protocol and device profilespecification for embedded systems used in automation.
In terms of the OSI model, CANopen implements the layersabove and including the network layer.
The lower level protocol implementing the data link andphysical layers is usually Controller Area Network (CAN).
![Page 7: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/7.jpg)
CAN SCICOS CAN200 Example
Device model
Device model
Every CANopen device must implement:
A Communication unit (protocol for messaging)
A state machine (Initialization, Pre-operational, Operational,Stopped)
An object dictionary used for configuration and non-realtimecommunication with the device.
The application part
![Page 8: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/8.jpg)
CAN SCICOS CAN200 Example
Communication objects
Communication objects
![Page 9: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/9.jpg)
CAN SCICOS CAN200 Example
Protocol
Network management (NMT) protocol
The NMT protocols are used to issue state machine changecommands (ie. to start and stop the devices), detect remote devicebootups and error conditions.
![Page 10: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/10.jpg)
CAN SCICOS CAN200 Example
Protocol
Service Data Object (SDO) protocol
The SDO protocol is used to set and read values from the objectdirectory of a remote device.
![Page 11: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/11.jpg)
CAN SCICOS CAN200 Example
Protocol
SDO
Master (PC) CAN dev 1 CAN dev 2
CMD
ACK
DATA
REQ
CMD
ACK
REQ
DATA
![Page 12: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/12.jpg)
CAN SCICOS CAN200 Example
Protocol
Process Data Object (PDO) protocol
Process Data Object protocol is used to process real time dataamong various nodes.
Synchronous
On change
TX and RX PDO’s
More values in the same message
![Page 13: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/13.jpg)
CAN SCICOS CAN200 Example
Protocol
PDO
ENCODER CURRENT SPEED
![Page 14: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/14.jpg)
CAN SCICOS CAN200 Example
Protocol
PDO
Master (PC) CAN dev 1 CAN dev 2
SYNC
SYNC
SYNC
SYNC
PDO’s
PDO’s
PDO’s
PDO’s
![Page 15: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/15.jpg)
CAN SCICOS CAN200 Example
Protocol
Others
Synchronization Object (SYNC) protocol
Time Stamp Object (TIME) protocol
Emergency Object (EMCY) protocol
![Page 16: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/16.jpg)
CAN SCICOS CAN200 Example
Integration in Scicos
Integration in Scicos
device
CANopen
Initialization
CAN
device
CANopen
Initialization
CAN
device
Receive
CANopen
Thread
![Page 17: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/17.jpg)
CAN SCICOS CAN200 Example
Integration in Scicos
Integration in Scicos
device
CANopen
Initialization
CAN
device
CANopen
Initialization
CAN
device
Receive
CANopen
Thread
![Page 18: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/18.jpg)
CAN SCICOS CAN200 Example
Integration in Scicos
Integration in Scicos
device
CANopen
Initialization
CAN
device
CANopen
Initialization
CAN
device
Receive
CANopen
Thread
![Page 19: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/19.jpg)
CAN SCICOS CAN200 Example
The “canopen.c” file
canopen.c
Initializes the RTDM driver
Contains a function to register the TX PDO
Starts a high priority thread for receiving the CAN messages
Handles TX PDO1 and TX PDO2, but can be easy extendedto handle more PDO’s
![Page 20: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/20.jpg)
CAN SCICOS CAN200 Example
The “canopen.c” file
canopen.c
The canopen.c file
![Page 21: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/21.jpg)
CAN SCICOS CAN200 Example
The “canopen.c” file
PDO handling
.....
127 for TX PDO1
.....
127 for TX PDO2
.....
127 for TX PDO1
.....
127 for TX PDO2
![Page 22: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/22.jpg)
CAN SCICOS CAN200 Example
The “canopen.c” file
PDO handling
.....
127 for TX PDO1
.....
127 for TX PDO2
.....
127 for TX PDO1
.....
127 for TX PDO2
![Page 23: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/23.jpg)
CAN SCICOS CAN200 Example
The “canopen sync” file
The “canopen sync.c” file
Simply sends a SYNC (0x80) message to all CANopen devices
All the devices handle the SYNC message as follow:
Devices with configured TX PDO’s send the requested valuesto the masterDevices with configured RX PDO’s set the last received value
![Page 24: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/24.jpg)
CAN SCICOS CAN200 Example
Reading PDO’s
Reading from the CAN Bus
A real-time thread scheduled with SCHED FIFO and priority“1” is responsible to get the messages from the CAN bus.
The receiving procedure runs using the interrupt of the CANbus RTDM driver.
The registered PDO’s are saved into the two PDO matrices.
8 procedures allow to extract the values from the PDOmessages (1,2,4 bytes, signed, unsigned)
![Page 25: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/25.jpg)
CAN SCICOS CAN200 Example
The palette
Additional palettes
out.txtsignal means
01sINIT ENC
0x3782Pport_out
0x37815Pport_in
10Switch
0x08encoderEpos
0x08motor IEpos
10x08Epos Analog
synccanopenEpos
0x08motXEpos
![Page 26: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/26.jpg)
CAN SCICOS CAN200 Example
Implementing a new block
The interface
1
gain_x
00.01sINIT ENC
11 11
11
synccanopenEpos
0x08encoderEpos
0x08motor IEpos
![Page 27: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/27.jpg)
CAN SCICOS CAN200 Example
Implementing a new block
The interface
1
gain_x
00.01sINIT ENC
11 11
11
synccanopenEpos
0x08encoderEpos
0x08motor IEpos
![Page 28: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/28.jpg)
CAN SCICOS CAN200 Example
Implementing a new block
The implementation
The Implementation file
![Page 29: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/29.jpg)
CAN SCICOS CAN200 Example
The card
The CAN200 dongle
![Page 30: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/30.jpg)
CAN SCICOS CAN200 Example
The card
Details
based on the SJA1000 chip
Little modifications on the original CAN200 board
16 Mhz quarzScmhitt trigger chip instead of a nand
Quite simple
PCB and scheme are provided
![Page 31: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/31.jpg)
CAN SCICOS CAN200 Example
Hardware
The CAN200 dongle - Scheme
6/23/2009 15:45:44 /home/bucher/eagle/can200/can200.sch (Sheet: 1/1)
+
1
23
IC1A
4
56
IC1B
9108
IC1C
12
1311
IC1D
1 62 73 84 95
X111421531641751861972082192210231124122513
X2
VCC
3
GND
2
TXD1RS8
RXD4
VREFOUT5
CANH 7
CANL 6
AD023
AD124
AD225
AD326
AD427
AD528
AD61
AD72
ALE/AS3
CS4
RD/E5
WR6
CLK_OUT7
MODE11
INT16
XTAL1 9
XTAL2 10
VDD1 22
VSS1 8
VDD3 12
VSS3 15
TX0 13
TX1 14
RX0 19
RX1 20
VSS2 21
VDD2 18
RESET 17
21
Q1
X4-1
X4-2
R1
R3
R2
C3
C1
C2
C4
R4
1
JP12
R5
C6
LED1
R6
74HC132
74HC132
74HC132
74HC132
8MHz
GNDGND
VCC
VCC
VCC
GND
47k
270
10k
100n
33p
33p
220p
470
GND
120
47uF
470
![Page 32: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/32.jpg)
CAN SCICOS CAN200 Example
Software
The Driver
RTDM driver
Modified peaks dongle driver
Few lines changed
![Page 33: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/33.jpg)
CAN SCICOS CAN200 Example
Example
The Servo motor
![Page 34: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/34.jpg)
CAN SCICOS CAN200 Example
Example
The Servo motor
![Page 35: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/35.jpg)
CAN SCICOS CAN200 Example
Example
The Servo motor
![Page 36: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/36.jpg)
CAN SCICOS CAN200 Example
Example
Features
Motor Output
Hall sensor+Incremental encoder
2 Analog inputs −10V ÷ +10V
1 Analog output 0V ÷ 10V
10 Digital inputs
5 Digital outputs
![Page 37: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/37.jpg)
CAN SCICOS CAN200 Example
Example
Motor equations
Differential equation
Jm · ϕ̈m = −Dm · ϕ̇m + Kt · I
In Laplace
Φ(s) =KtJm
s2 + DmJm
· s· I (s)
![Page 38: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/38.jpg)
CAN SCICOS CAN200 Example
Example
Motor equations
Φ(s) =KtJm
s2 + DmJm
· s· I (s)
can be rewritten as
Φ(s) =K
s2 + α · s· I (s)
where
K =Kt
Jm, α =
Dm
Jm
![Page 39: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/39.jpg)
CAN SCICOS CAN200 Example
Example
Motor equations
With I (s) as step signal we obtain:
Φ(s) =K
s2 + α · s· I0
s
that in time domain becomes
ϕ(t) = −K · I0α2
+K · I0α
· t +K · I0α2
· eα·t
![Page 40: ScicosLab and CANopen - SUPSI](https://reader036.vdocuments.us/reader036/viewer/2022062504/62b057039a408a3e0325d3e4/html5/thumbnails/40.jpg)
CAN SCICOS CAN200 Example
Example
Example
Controller
ScicosLab