2. The role and importance of the CANopen object dictionary

Article 2: CANopen Object Dictionary: Deep Dive into Data Management and Communication

Recently, I started to learn CANOpen-related knowledge, and with the help of AI assistant tools, I can learn more with less effort. Welcome to visit: http://airight.fun/.
In the process of learning canopen, I treasured some materials and shared them for your reference. Link: https://pan.baidu.com/s/1SRg5YrQjvpzXEIi_fOmxQg?pwd=20v4
Extraction code: 20v4

In the CANopen protocol, the object dictionary is a core concept, which plays a key role in data management and communication. The object dictionary is the core storage area of ​​the CANopen node, which is used to manage the configuration parameters and status information of the node. In this article, we will deeply discuss the role and importance of the CANopen object dictionary, understand the data structure of object index, sub-index and object dictionary, introduce common object types such as PDO, SDO, NMT, and discuss how to use object dictionary to realize data communication and device configuration. Meanwhile, for better understanding, we will provide some sample source codes for demonstration.

1. The role and importance of the CANopen object dictionary

Object dictionary is the core of CANopen network, it is a data storage area, used to manage configuration parameters and status information of nodes. In the CANopen network, each node has its own object dictionary, and other nodes can exchange data and configure with the node by accessing the object dictionary.

The role and importance of the object dictionary are as follows:

a. Data management: All configuration parameters and status information of nodes are stored in the object dictionary, including device identification information, communication parameters, working mode, error status, etc. Through the object dictionary, nodes can easily manage their own data.

b. Data communication: The data in the object dictionary can be exchanged with other nodes through the CANopen network. Nodes can encapsulate data as PDO (Process Data Object) or use SDO (Service Data Object) to request and respond to realize real-time data transmission and configuration.

c. Device configuration: The configuration parameters stored in the object dictionary can be read and written through SDO to realize online configuration of nodes. This makes parameter adjustment of the device more flexible and convenient.

2. Understand the data structure of object index, sub-index and object dictionary

In the CANopen object dictionary, each data item consists of a unique object index (Index) and optional sub-index (Sub-index). Object indexes are used to identify different data items, while sub-indexes are used to distinguish different data under the same object index. For example, an object dictionary item can be OD (Object Dictionary) 1000h, and the sub-index can be 01h, indicating a specific data item.

The data structure of the object dictionary can be compared to a collection of key-value pairs, where the key is a unique identifier composed of an object index and sub-index, and the value is the corresponding data. Data in the object dictionary can be accessed and modified through the object index and sub-index.

3. Common object types: PDO, SDO, NMT

CANopen defines some commonly used object types, which are used for different data communication and management tasks.

a. PDO (Process Data Object): PDO is used for real-time data transmission, which sends data from one node to another. PDOs can be configured for different transmission types, including synchronous and asynchronous transmissions. In the object dictionary, the index range of PDO is usually between 1400h and 17FFh.

b. SDO (Service Data Object): SDO is an object type used to configure and manage node parameters. Through SDO, a node can request the object dictionary data of other nodes, and perform read and write operations on it. SDO uses requests and responses for data exchange. In the object dictionary, the index range of SDO is usually between 1200h and 12FFh.

c. NMT (Network Management): NMT is used to control the status of nodes, such as start, stop, restart, etc. Through NMT, the entire CANopen network can be managed centrally. In the object dictionary, NMT has index 0 and sub-index 0.

4. Use object dictionary for data communication and device configuration

In the CANopen network, using the object dictionary to realize data communication and device configuration involves two main aspects: the use of PDO and the use of SDO.

a. Use PDO to realize data communication: PDO is a common data communication method in CANopen network, especially suitable for real-time data transmission. Nodes can configure the transmission type and mapping relationship of PDO, so that data can be transmitted on demand in the network. Here is a simple sample code showing how to configure and send PDO data:

// 配置PDO映射关系
// 将对象字典中的数据映射到PDO数据
// 这里假设PDO的索引为0x180h,子索引为1
configure_PDO_mapping(0x180, 1, "数据对象1");

// 发送PDO数据
uint8_t data[] = {
    
    0x01, 0x02, 0x03, 0x04};
send_PDO_data(0x180, data, sizeof(data));

b. Use SDO to implement device configuration: SDO is an important way to configure node parameters in the CANopen network. Nodes can use SDO requests and responses to read and write object dictionary data from other nodes. Here is a simple sample code showing how to read and write data using SDO:

// 读取其他节点的对象字典数据
uint32_t data;
if (SDO_read_data(0x201, 0x02, &data)) {
    
    
    printf("读取节点0x201的对象0x02数据成功:0x%x\n", data);
} else {
    
    
    printf("读取节点0x201的对象0x02数据失败\n");
}

// 写入其他节点的对象字典数据
uint8_t data_to_write = 0x55;
if (SDO_write_data(0x202, 0x01, &data_to_write, sizeof(data_to_write))) {
    
    
    printf("写入节点0x202的对象0x01数据成功\n");
} else {
    
    
    printf("写入节点0x202的对象0x01数据失败\n");
}

Thank you for reading, welcome to discuss CANOpen-related issues, and welcome to use the AI ​​assistant AIRight to answer any questions during the learning process, visit the link: http://airight.fun/.

Guess you like

Origin blog.csdn.net/Jake_cai/article/details/132201286