forked from bggardner/canopen-rpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canopen-node-pdo.py
executable file
·138 lines (132 loc) · 5.19 KB
/
canopen-node-pdo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/python3
import CAN
import CANopen
CAN_INTERFACE = "vcan0"
can_bus = CAN.Bus(CAN_INTERFACE)
node_id = 0x02
canopen_od = CANopen.ObjectDictionary({
CANopen.ODI_DEVICE_TYPE: CANopen.Object(
parameter_name="Device type",
object_type=CANopen.ObjectType.VAR,
access_type=CANopen.AccessType.RO,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED32,
default_value=0x00000000
),
CANopen.ODI_ERROR: CANopen.Object(
parameter_name="Error register",
object_type=CANopen.ObjectType.VAR,
access_type=CANopen.AccessType.RO,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED8,
default_value=0x00
),
CANopen.ODI_HEARTBEAT_PRODUCER_TIME: CANopen.Object(
parameter_name="Producer heartbeat time",
object_type=CANopen.ObjectType.VAR,
access_type=CANopen.AccessType.RW,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED16,
default_value=1000 # 16-bit, in ms
),
CANopen.ODI_IDENTITY: CANopen.Object(
parameter_name="Identity object",
object_type=CANopen.ObjectType.RECORD,
data_type=CANopen.ODI_DATA_TYPE_IDENTITY,
sub_number=1,
subs={
CANopen.ODSI_VALUE: CANopen.SubObject(
parameter_name="number of supported entries",
access_type=CANopen.AccessType.CONST,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED8,
low_limit=0x01,
high_limit=0x04,
default_value=0x01
),
CANopen.ODSI_IDENTITY_VENDOR: CANopen.SubObject(
parameter_name="Vendor-ID",
access_type=CANopen.AccessType.RO,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED32,
default_value=0x00000000
)
}
),
CANopen.ODI_SDO_SERVER: CANopen.Object(
parameter_name="SDO server parameter",
object_type=CANopen.ObjectType.RECORD,
data_type=CANopen.ODI_DATA_TYPE_SDO_PARAMETER,
sub_number=2,
subs={
CANopen.ODSI_VALUE: CANopen.SubObject(
parameter_name="number of supported entries",
access_type=CANopen.AccessType.CONST,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED8,
low_limit=0x02,
high_limit=0x02,
default_value=0x02
),
CANopen.ODSI_SDO_SERVER_DEFAULT_CSID: CANopen.SubObject(
parameter_name="COB-ID client -> server (rx)",
access_type=CANopen.AccessType.RO,
default_value=(CANopen.FUNCTION_CODE_SDO_RX << CANopen.FUNCTION_CODE_BITNUM) + node_id
),
CANopen.ODSI_SDO_SERVER_DEFAULT_SCID: CANopen.SubObject(
parameter_name="COB-ID client -> server (rx)",
access_type=CANopen.AccessType.RO,
default_value=(CANopen.FUNCTION_CODE_SDO_TX << CANopen.FUNCTION_CODE_BITNUM) + node_id
)
}
),
CANopen.ODI_SYNC: CANopen.Object(
parameter_name="COB-ID SYNC",
object_type=CANopen.ObjectType.VAR,
access_type=CANopen.AccessType.CONST,
data_type=CANopen.ODI_DATA_TYPE_UNSIGNED32,
default_value=(CANopen.FUNCTION_CODE_SYNC << CANopen.FUNCTION_CODE_BITNUM)
),
CANopen.ODI_TPDO1_COMMUNICATION_PARAMETER: CANopen.Object(
parameter_name="TPDO1 communication parameter",
object_type=CANopen.ObjectType.RECORD,
data_type=CANopen.ODI_DATA_TYPE_PDO_COMMUNICATION_PARAMETER,
sub_number=2,
subs={
CANopen.ODSI_VALUE: CANopen.SubObject(
parameter_name="number of supported entries",
access_type=CANopen.AccessType.CONST,
low_limit=0x02,
high_limit=0x06,
default_value=0x02
),
CANopen.ODSI_TPDO_COMM_PARAM_ID: CANopen.SubObject(
parameter_name="COB-ID used by TPDO",
access_type=CANopen.AccessType.CONST,
default_value=(CANopen.FUNCTION_CODE_TPDO1 << CANopen.FUNCTION_CODE_BITNUM) + node_id
),
CANopen.ODSI_TPDO_COMM_PARAM_TYPE: CANopen.SubObject(
parameter_name="transmission type",
access_type=CANopen.AccessType.CONST,
default_value=0x01 # Synchronous every SYNC
)
}
),
CANopen.ODI_TPDO1_MAPPING_PARAMETER: CANopen.Object(
parameter_name="TPDO1 Mapping",
object_type=CANopen.ObjectType.RECORD,
data_type=CANopen.ODI_DATA_TYPE_PDO_MAPPING_PARAMETER,
sub_number=0x01,
subs={
CANopen.ODSI_VALUE: CANopen.SubObject(
parameter_name="number of supported entries",
access_type=CANopen.AccessType.CONST,
low_limit=0x00,
high_limit=0xFE,
default_value=0x01
),
0x01: CANopen.SubObject(
parameter_name="1st application object",
access_type=CANopen.AccessType.CONST,
default_value=(CANopen.ODI_DEVICE_TYPE << 16) + (CANopen.ODSI_VALUE << 8) + 32
)
}
)
})
node = CANopen.Node(can_bus, node_id, canopen_od)
while True:
pass # Run forever