首页 > 代码库 > CANopen笔记2
CANopen笔记2
-
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 assigns (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(RPDO) or transmit(TPDO). 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).
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
禁止时间 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.)
参考:
http://blog.csdn.net/iamplane/article/details/49931319
CANopen笔记2