-
PDO
過程數據對象用於在節點之間傳送過程數據,如I/O模塊I/O狀態讀取和設定,模擬量采集和模擬量輸出等等,協議考慮從機硬件限制最多支持4組PDO,每組包含一個RPDO和一個TPDO。The Gold drive supports 4 TPDO and 4 RPDO. Each PDO contains up to 8 bytes of data.
現在以I/O模塊為例進行說明:設I/O模塊有24路輸入,24路輸出。24輸入通過TPDO傳給監控終端或其他節點,24輸出通過RPDO由控制節點對其進行設定,采用發送和接收PDO1組,即標識符TPDO:0x180+NODE_ID,RPDO:0x200+NODE_ID,用3個字節就可以表示24個I/O量,因此發送和接收PDO可以表示如下(假設NODE_ID=1):
I/O節點→監控終端(TPDO)
I/O節點←監控終端(RPDO)
PDO Mapping
PDO只是個載體,它好比一輛貨車,車廂里裝什么貨,是可以配置的,這些由PDO映射來完成。PDO映射用來指定把對象字典的那些對象裝進PDO,或者從接收的PDO中將數據放到那些對象中。PDO mapping is a convention that maps an object from the object dictionary (data payload) to a PDO. Once mapped, the PDO can carry the assigned data items without explicit reference to the object dictionary, thereby saving on communication and CPU overhead. Some of the objects in the object dictionary can be mapped to a PDO, which can either receive or transmit. The mapping of an RPDO enables reception of commands and variables — for example, efficient transmission of high-speed online motion commands to the drive — whereas the mapping of a TPDO enables the drive to send a predefined message in response to an event such as end of motion.
An RPDO is buffered upon reception; it is sent for interpretation immediately (when defined as asynchronous) or upon receipt of the next SYNC signal (when defined as synchronous). 即當RPDO設為異步時(transmission type=254/255),節點接收到后會立刻處理,不用等待同步信號。
Objects 0x1A00 – 0x1A03 contain the objects mapped to TPDOs. Objects 0x1600 – 0x1603 contain the objects mapped to RPDOs. The data type of PDO mapping is described in object 0x21. 由下表可知,對子索引0對應要映射對象的數目,子索引1~8分別對應要映射的對象。
Transmission Type
PDO通訊具有三種觸發模式:內部事件驅動或內部定時器觸發、同步觸發、遠程請求觸發。
1) 同步觸發。同步觸發PDO是指CANopen節點收到由管理節點發出的同步報文(同步對象SYNC)之后,根據觸發報文條件向總線發出PDO報文。同步傳輸又分為周期性和非周期性,周期性是指CANopen節點接收到一定數量的同步報文之后才開始發送;非周期性PDO是指PDO觸發條件成立之后,當收到下一個同步對象后馬上發送PDO。同步傳輸在實際應用中的優勢很多,它能提供一致的系統節拍,使得總線的數據盡量保證同步。同步傳輸的最重要應用是多軸同步控制,沒有這種同步機制,多軸傳動功能是沒有辦法實現的。
SYNC就相當於一個網絡節拍,數據根據節拍來進行固定周期的過程數據傳輸。比如網絡中有一個壓力傳感器,一個溫度傳感器,一個物位傳感器,網絡中有一個監控終端來實時監控三個傳感器采集的數據。壓力傳感器可能檢測的是一個快速的壓力變化,那可以每隔200ms更新一次數據,溫度可能需要1s更新一次數據,物位可能5s更新一次數據。現在我可以設置一個200ms周期的SYNC消息,壓力傳感器每收到一個SYNC就傳輸一次數據,溫度傳感器可以每隔5個SYNC傳輸一次數據,同樣物位傳感器就是每收到25個SYNC發送一次數據。這種通訊方式顯得比較規矩,好管理,系統運行效率高,適合周期性數據更新的應用。
2) 內部事件驅動或內部定時器觸發。通訊由某一事件觸發。例如數字I/O口狀態改變,超過預先設定的值、定時器中斷等都會觸發節點發送一個PDO。這種模式可使總線負載達到最小,在相對低的波特率下獲得比較高的通訊特性。內部定時發送有別於SYNC同步觸發,它是在本節點上實現周期發送,通過設置PDO參數,確定一個周期,每隔固定的時間向網絡上發送一次PDO,它與SYNC無關。在網絡設計中主要按照傳感器的數據采集速度和數據更新要求來設定定時周期.
3) 遠程請求觸發。PDO消費者可以給PDO生產者發送遠程PDO請求,相應PDO生產者將對遠程幀做出響應,向總線上發送相應的PDO數據。
PDO傳輸類型定義表:
If the RPDO transmission type is 1, the received message is buffered but actually transmitted for execution at the next SYNC message. With TPDOs, the message is transmitted according to transmission type value, which can range from 1 to 240, where 1 indicates on each single SYNC, 2 means every second SYNC message,and so on.
Communication Parameter
每個PDO在對象字典中由兩個對象描述:通信參數和映射參數。PDO通信參數指明使用哪個COB-ID、傳輸類型、禁用時間和定時時間;PDO 映射參數用於設定PDO報文中的數據的映射關系,確定要傳輸的數據在 CAN 報文數據域中的定位。
一個PDO可以指定一個禁止時間,即定義兩個連續PDO傳輸的最小間隔時間,避免由於高優先級信息的數據量太大,始終占據總線,而使其它優先級較低的數據無力競爭總線的問題。禁止時間由16 位無符號整數定義,單位為100us。If sub index 3 is set to 0, then the minimum time interval to transmit TPDO is disabled.
一個 PDO可以指定一個事件定時周期,當超過定時時間后,一個PDO傳輸可以被觸發。事件定時周期由16位無符號整數定義,單位為1ms。When a TPDO transmission type is 254 or 255, an event timer defined by sub index 5 can be used. The timer defines the maximum interval for TPDO transmission. The event occurs when the time is elapsed. The event timer resolution is 1ms. The event causes the transmission of this TPDO in addition to other asynchronous events. The occurrence of an event sets the timer again. A value of 0 disables this function.
在開始PDO傳輸前要先配置好PDO通信參數,在0x20處描述了其格式。Transmit PDO communication parameter:Objects 0x1800 - 0x1803;Receive PDO communication parameter:Objects 0x1400 - 0x1403
=====================================================================================
PDO 映射事例:將下表中3個對象映射到PDO1-Transmit, 為異步周期性類型,周期時間 10ms,禁止時間 2ms
1)① Clear mapping TPDO1(To change the PDO mapping, sub-index 0 must be set to 0 (mapping is deactivated). Only then can the objects be remapped)
number_of_mapped_objects(1A00 h: 00 h) = 0
② Disable TPDO1
為了設置通信參數,必須要先將通信參數對象子地址1h的第31位置1,即要先使TPDO1失效才能配置其通信參數,否則會產生錯誤。It is not allowed to change bit 0 to 30 while the PDO exists and is valid (bit 31 = 0b). In this case, when attempting to change the values from bit 0 to bit 30, the devise responds with the SDO abort transfer service. 發送如下指令使TPDO1失效:
2)設置映射對象參數(Modify mapping by changing the values of the corresponding sub-indices.)
Index = 6041h Subindex = 00h Length = 10h ⇒ 1st_mapped_object(1A00 h: 01 h) = 60410010 h
Index = 6061h Subindex = 00h Length = 08h ⇒ 2st_mapped_object(1A00 h: 02 h) = 60610008 h
Index = 6064h Subindex = 00h Length = 20h ⇒ 3st_mapped_object(1A00 h: 03 h) = 60640020 h
注意:The sub-indexes from 1 to number of entries contain the information about the mapped application variables. These entries describe the PDO contents by their index, sub-index and length. 即設置映射對象參數時要按照如下所示的格式(映射對象地址+對象子地址+映射數據的長度,按小端模式發送)
假設設備節點ID為1,則發送一幀完整的SDO報文配置PDO,需要發送的格式如下:
3)設置 number_of_mapped_objects(Enable mapping by setting sub-index 0 to the number of mapped objects.)
number_of_mapped_objects(1A00 h: 00 h) = 3
注意:When sub-index 0 is set to a value greater than 0, the device may validate the new PDO mapping before transmitting the response of the SDO service. If an error is detected, the Elmo drive transmits the Abort SDO Transfer Service with abort codes.
4)設置 PDO 通訊參數
PDO1-Transmit為異步周期性類型 ⇒ transmission_type (1800 h: 02 h)= FF h (TPDO1傳輸類型默認值為0xFF,即默認異步傳輸)
禁止時間 2ms(20×100us) ⇒ inhibit_time (1800 h: 03 h) = 14 h
周期時間 10ms(10×1ms) ⇒ event_time (1800 h: 05 h) = 0A h
設置COB-ID(PDO1-Transmit) ⇒ COB-ID (1800 h: 01 h) = 0181 h
通信參數對象子地址1h處包含了COB-ID,但其數據類型為32位(參照0x20描述),其它幾位定義如下:
The bit valid (bit 31) enables TPDOs. There may be TPDOs configured but not used, and therefore set to not valid.
則發送如下指令來Enable TPDO1:
5)PDO 映射完成(Finally, the PDO is created by writing to its communication parameter COB-ID.)
=====================================================================================
PDO 映射事例:將Controlword對象0x6040和Interpolated data record對象0x60C1:1h映射到RPDO1,傳輸類型為同步類型
1) Disable RPDO1(COB-ID 0x201),client sends:
0x601 0x22 0x00 0x14 0x01 0x01 0x02 0x00 0x80
Clear mapping RPDO1,client sends:
0x601 0x22 0x00 0x16 0x00 0x00 0x00 0x00 0x00
2) Set CW, object 0x6040, 16 bit length in sub index 1 of RPDO1
0x601 0x22 0x00 0x16 0x01 0x10 0x00 0x40 0x60
Set Interpolated data record, object 0x60C1, Sub index 1, 32 bit length in sub index 2 of RPDO1
0x601 0x22 0x00 0x16 0x02 0x20 0x01 0xC1 0x60
3) Set transmission type synchronous, every SYNC (RPDO默認傳輸類型值為255,即默認異步傳輸)
0x601 0x22 0x00 0x14 0x02 0x01 0x00 0x00 0x00
4)Set 2 objects are mapped
0x601 0x22 0x00 0x16 0x00 0x02 0x00 0x00 0x00
Enalbe RPDO1
0x601 0x22 0x00 0x14 0x01 0x01 0x02 0x00 0x00
- SYNC
SYNC主節點定時發送 SYNC 對象,SYNC從節點收到后同步執行任務。SYNC報文的COB-ID固定為080h,SYNC報文可以不傳送數據以使報文盡可能短(注意:數據幀的數據段可以發送0~8個字節的數據,控制段表示數據段的字節數。而SDO報文數據段長度始終為8字節,不夠的要補0)
參考: