scicoslab and canopen - supsi
TRANSCRIPT
CAN SCICOS CAN200 Example
ScicosLab and CANopen
Ing. Roberto Bucher
Scuola Universitaria Professionale della Svizzera Italiana (SUPSI)
Manno - July 1. 2009
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
CAN SCICOS CAN200 Example
Outline
1 CAN and CANopen
2 Scicos and CANopen
3 The CAN200 card
4 Example
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.
CAN SCICOS CAN200 Example
CAN
Interface
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).
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
CAN SCICOS CAN200 Example
Communication objects
Communication objects
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.
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.
CAN SCICOS CAN200 Example
Protocol
SDO
Master (PC) CAN dev 1 CAN dev 2
CMD
ACK
DATA
REQ
CMD
ACK
REQ
DATA
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
CAN SCICOS CAN200 Example
Protocol
PDO
ENCODER CURRENT SPEED
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
CAN SCICOS CAN200 Example
Protocol
Others
Synchronization Object (SYNC) protocol
Time Stamp Object (TIME) protocol
Emergency Object (EMCY) protocol
CAN SCICOS CAN200 Example
Integration in Scicos
Integration in Scicos
device
CANopen
Initialization
CAN
device
CANopen
Initialization
CAN
device
Receive
CANopen
Thread
CAN SCICOS CAN200 Example
Integration in Scicos
Integration in Scicos
device
CANopen
Initialization
CAN
device
CANopen
Initialization
CAN
device
Receive
CANopen
Thread
CAN SCICOS CAN200 Example
Integration in Scicos
Integration in Scicos
device
CANopen
Initialization
CAN
device
CANopen
Initialization
CAN
device
Receive
CANopen
Thread
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
CAN SCICOS CAN200 Example
The “canopen.c” file
canopen.c
The canopen.c file
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
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
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
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)
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
CAN SCICOS CAN200 Example
Implementing a new block
The interface
1
gain_x
00.01sINIT ENC
11 11
11
synccanopenEpos
0x08encoderEpos
0x08motor IEpos
CAN SCICOS CAN200 Example
Implementing a new block
The interface
1
gain_x
00.01sINIT ENC
11 11
11
synccanopenEpos
0x08encoderEpos
0x08motor IEpos
CAN SCICOS CAN200 Example
Implementing a new block
The implementation
The Implementation file
CAN SCICOS CAN200 Example
The card
The CAN200 dongle
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
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
CAN SCICOS CAN200 Example
Software
The Driver
RTDM driver
Modified peaks dongle driver
Few lines changed
CAN SCICOS CAN200 Example
Example
The Servo motor
CAN SCICOS CAN200 Example
Example
The Servo motor
CAN SCICOS CAN200 Example
Example
The Servo motor
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
CAN SCICOS CAN200 Example
Example
Motor equations
Differential equation
Jm · ϕ̈m = −Dm · ϕ̇m + Kt · I
In Laplace
Φ(s) =KtJm
s2 + DmJm
· s· I (s)
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
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
CAN SCICOS CAN200 Example
Example
Example
Controller
ScicosLab