CANOPEN-based master and slave station synchronization method
By automatically synchronizing the dictionary parameters of the master-slave object, the data consistency management problem in the CANopen protocol is solved, synchronization efficiency and reliability are improved, and dynamic consistency management of master-slave data is realized.
Patent Information
- Application Number
- CN202411470862.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-01-03
AI Technical Summary
In the traditional CANopen protocol, the master-slave object dictionary parameter management requires manual processing, which is prone to errors and cannot be modified dynamically, resulting in inconsistent data.
A master-slave synchronization method based on CANOPEN is provided. Through step S1: synchronize the master object dictionary parameters to the slave, step S2: synchronize the TPDO and RPDO mapping parameters, step S3: synchronize the master configuration mapping area to the slave, and use the CANOPEN standard library and semaphore initialization and other technical means to automate the transmission and mapping of object dictionary data.
Improve the reliability and efficiency of master-slave data synchronization, ensure the consistency of object dictionary data, and avoid manual errors.
Smart Images

Figure CN119254569A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer control and relates to a master-slave station synchronization method based on CANOPEN. Background Art
[0002] CANopen communication is a form of communication based on the CAN data link layer. This communication method has relevant provisions for the application layer. The CANopen device model includes the communication part, object dictionary and application part. The communication part includes PDO objects, SDO objects and NMT objects. The object dictionary includes data types, communication objects and application objects.
[0003] The advantages of the CANOPEN protocol include high efficiency, precise positioning, anti-interference, versatility, easy configuration, high efficiency of data transmission, flexible configuration and status query functions, open standards, high data security, and secure communication constraints. Summary of the invention
[0004] 1. Technical issues to be resolved
[0005] The CANopen protocol performs parameter management based on the data managed by the object dictionary. Both the master and slave stations need to manage an object dictionary. The data in the parameter area of the master and slave object dictionaries should be consistent, while the PDO parameter area and data area are cross-mapped. The traditional synchronization method is to manually process the data of each index of the object dictionary and manually confirm that the master and slave data are consistent. This process is prone to errors and cannot be modified dynamically.
[0006] (II) Technical solution
[0007] In order to solve the above technical problems, the present invention provides a master-slave station synchronization method based on CANOPEN, which comprises the following steps:
[0008] S1: Synchronize the parameters of the master object dictionary to the slave;
[0009] S2: synchronize the master object dictionary TPDO mapping parameters to the slave object dictionary RPDO mapping parameters, and synchronize the master object dictionary RPDO mapping parameters to the slave object dictionary TPDO mapping parameters;
[0010] S3: Synchronize the master configuration map area to the slave.
[0011] Wherein, step S1 includes the following sub-steps:
[0012] S1_1 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters;
[0013] S1_2 determines whether the node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise it returns an error directly;
[0014] S1_3 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem;
[0015] S1_4 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing into the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission.
[0016] S1_5 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
[0017] In step S1_1, the incoming data are respectively the local object dictionary pointer master402_OD, the local object dictionary index master_index and the local object dictionary sub-index master_subindex; the pointer pdata where the value is stored, the value size size and the parameter type type are read.
[0018] In step S1_3, the node data writing function writeNetworkDictCallBack is used to write the slave object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and the data pointed to by the pointer pdata is written.
[0019] Wherein, step S2 includes the following sub-steps:
[0020] S2_1 sets the slave station index number slave_master value according to the master station index number master_index of the data to be synchronized;
[0021] S2_2 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters;
[0022] S2_3 determines whether the node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise it returns an error directly;
[0023] S2_4 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem;
[0024] S2_5 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing into the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission.
[0025] S2_6 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
[0026] In step S2_1, if the value range of master_index is greater than or equal to 0x1600 and less than or equal to 0x17FF, the slave station index number slave_master is set to master_index+0x400; if the value range of master_index is greater than or equal to 0x1A00 and less than or equal to 0x1BFF, the slave station index number slave_master is set to master_index-0x400; if master_index is not in the range of greater than or equal to 0x1600 and less than or equal to 0x17FF and greater than or equal to 0x1600 and less than or equal to 0x17FF, the value of slave_index is the same as the value of master_index.
[0027] In step S2_2, the incoming data are respectively the local object dictionary pointer master402_OD, the local object dictionary index master_index, the local object dictionary sub-index master_subindex, the pointer pdata where the value is stored, the value size size and the parameter type type.
[0028] In step S2_4, the node data writing function writeNetworkDictCallBack is used to write the slave object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and the data pointed to by the pointer pdata is written.
[0029] Wherein, step S3 includes the following sub-steps:
[0030] S3_1 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the local object dictionary index master_index, and the local object dictionary sub-index master_subindex. The pointer pdata where the value is stored, the value size, and the parameter type type are read to determine that the reading is successful, and then go to S3_2.
[0031] S3_2 calculates the sdo_data data in the configuration process. The calculation method is to shift the master_index value left by 16 bits plus the master_subindex value left by 8 bits, plus the size value obtained in S3_1 multiplied by 8, and the final calculated value is the value of sdo_data;
[0032] S3_3 clears the value pointed to by the data pointer pdata, the value of size size and the value of type type in S3_1;
[0033] S3_4 uses the readLocalDict function to read the object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the slave object dictionary index slave_index, and the slave object dictionary sub-index slave_subindex. After the pointer pdata, the value size, and the parameter type type are successfully written, S3_5 is transferred to perform the slave write operation.
[0034] S3_5 determines whether the range of the written node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise it directly returns an error;
[0035] S3_6 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem;
[0036] S3_7 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing to the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission.
[0037] S3_8 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
[0038] In step S3_6, the node data writing function writeNetworkDictCallBack is used to write the slave object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and the data pointed to by the pointer pdata is written.
[0039] (III) Beneficial effects
[0040] The CANOPEN-based master-slave synchronization method provided by the above technical solution will read the master object dictionary data according to the object dictionary index number, write it to the corresponding slave through the SDO message write operation, and classify different mapping methods to improve the reliability and efficiency of synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a flow chart of the master-slave synchronization method based on CANOPEN. DETAILED DESCRIPTION
[0042] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.
[0043] Reference Figure 1 As shown, the master-slave synchronization method based on CANOPEN in this embodiment includes the following steps:
[0044] S1: Synchronize the parameters of the master object dictionary to the slave
[0045] S1_1 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters; the incoming data are the local object dictionary pointer master402_OD, the local object dictionary index master_index and the local object dictionary sub-index master_subindex; the pointer pdata where the value is stored, the value size and the parameter type type are read.
[0046] S1_2 determines whether the node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise an error is directly returned.
[0047] S1_3 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem.
[0048] Use the node data writing function writeNetworkDictCallBack to write the slave object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and write the data pointed to by the pointer pdata.
[0049] S1_4 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing into the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission.
[0050] S1_5 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
[0051] S2: Synchronize the master object dictionary TPDO mapping parameters to the slave object dictionary RPDO mapping parameters, and synchronize the master object dictionary RPDO mapping parameters to the slave object dictionary TPDO mapping parameters
[0052] S2_1 sets the slave station index number slave_master value according to the master station index number master_index of the data to be synchronized;
[0053] If the value range of master_index is greater than or equal to 0x1600 and less than or equal to 0x17FF, set the slave station index number slave_master to master_index+0x400.
[0054] If the value range of master_index is greater than or equal to 0x1A00 and less than or equal to 0x1BFF, set the slave station index number slave_master to master_index-0x400.
[0055] If master_index is not in the range of 0x1600 to 0x17FF and 0x17FF, the slave_index value is the same as the master_index value.
[0056] S2_2 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the local object dictionary index master_index, the local object dictionary sub-index master_subindex, the pointer pdata where the value is stored, the value size, and the parameter type type.
[0057] S2_3 determines whether the node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise an error is directly returned.
[0058] S2_4 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem. Use the node data writing function writeNetworkDictCallBack to write the slave object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size and the parameter type type, and write the data pointed to by the pointer pdata.
[0059] S2_5 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing into the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission.
[0060] S2_6 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
[0061] S3: Synchronize the master configuration map to the slave
[0062] S3_1 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the local object dictionary index master_index, and the local object dictionary sub-index master_subindex. The pointer pdata where the value is stored, the size of the value size, and the parameter type type are read to determine that the reading is successful, and then go to S3_2.
[0063] S3_2 calculates the sdo_data data in the configuration process. The calculation method is to shift the master_index value left by 16 bits plus the master_subindex value left by 8 bits, plus the size value obtained in S3_1 multiplied by 8. The final calculated value is the value of sdo_data.
[0064] S3_3 clears the value pointed to by the data pointer pdata, the value of size size, and the value of type type in S3_1.
[0065] S3_4 uses the readLocalDict function to read the object dictionary parameters. The data passed in are the local object dictionary pointer master402_OD, the slave object dictionary index slave_index, and the slave object dictionary sub-index slave_subindex. After the pointer pdata where the value is stored, the value size, and the parameter type type are successfully written, it is transferred to S3_5 for the slave write operation.
[0066] S3_5 determines whether the range of the written node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise an error is directly returned.
[0067] S3_6 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem. Use the node data writing function writeNetworkDictCallBack to write the slave object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size and the parameter type type, and write the data pointed to by the pointer pdata.
[0068] S3_7 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing to the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission.
[0069] S3_8 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
[0070] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A master-slave synchronization method based on CANOPEN, characterized in that: The following steps are involved: S1: Synchronize the parameters of the master object dictionary to the slave; S2: synchronize the master object dictionary TPDO mapping parameters to the slave object dictionary RPDO mapping parameters, and synchronize the master object dictionary RPDO mapping parameters to the slave object dictionary TPDO mapping parameters; S3: Synchronize the master configuration map area to the slave.
2. The master-slave station synchronization method based on CANOPEN as claimed in claim 1, characterized in that: Step S1 includes the following sub-steps: S1_1 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters; S1_2 determines whether the node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise it returns an error directly; S1_3 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem; S1_4 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing into the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission. S1_5 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
3. The master-slave station synchronization method based on CANOPEN as claimed in claim 2, characterized in that: In step S1_1, the incoming data are respectively the local object dictionary pointer master402_OD, the local object dictionary index master_index and the local object dictionary sub-index master_subindex; the pointer pdata where the value is stored, the value size size and the parameter type type are read.
4. The master-slave station synchronization method based on CANOPEN as claimed in claim 3, characterized in that: In step S1_3, the node data writing function writeNetworkDictCallBack is used to write the slave object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and the data pointed to by the pointer pdata is written.
5. The master-slave station synchronization method based on CANOPEN as claimed in claim 4, characterized in that: Step S2 includes the following sub-steps: S2_1 sets the slave station index number slave_master value according to the master station index number master_index of the data to be synchronized; S2_2 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters; S2_3 determines whether the node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise it returns an error directly; S2_4 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem; S2_5 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing into the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission. S2_6 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
6. The master-slave station synchronization method based on CANOPEN as claimed in claim 5, characterized in that: In step S2_1, if the value range of master_index is greater than or equal to 0x1600 and less than or equal to 0x17FF, the slave station index number slave_master is set to master_index+0x400; if the value range of master_index is greater than or equal to 0x1A00 and less than or equal to 0x1BFF, the slave station index number slave_master is set to master_index-0x400; if master_index is not in the range of greater than or equal to 0x1600 and less than or equal to 0x17FF and greater than or equal to 0x1600 and less than or equal to 0x17FF, the value of slave_index is the same as the value of master_index.
7. The master-slave station synchronization method based on CANOPEN as claimed in claim 6, characterized in that: In step S2_2, the incoming data are respectively the local object dictionary pointer master402_OD, the local object dictionary index master_index, the local object dictionary sub-index master_subindex, the pointer pdata where the value is stored, the value size size and the parameter type type.
8. The CANOPEN-based master-slave synchronization method according to claim 7, characterized in that: In step S2_4, the node data writing function writeNetworkDictCallBack is used to write the slave object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and the data pointed to by the pointer pdata is written.
9. The master-slave station synchronization method based on CANOPEN as claimed in claim 8, characterized in that: Step S3 includes the following sub-steps: S3_1 uses the readLocalDict function in the CANOPEN standard library to read the object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the local object dictionary index master_index, and the local object dictionary sub-index master_subindex. The pointer pdata where the value is stored, the value size, and the parameter type type are read to determine that the reading is successful, and then go to S3_2. S3_2 calculates the sdo_data data in the configuration process. The calculation method is to shift the master_index value left by 16 bits plus the master_subindex value left by 8 bits, plus the size value obtained in S3_1 multiplied by 8, and the final calculated value is the value of sdo_data; S3_3 clears the value pointed to by the data pointer pdata, the value of size size and the value of type type in S3_1; S3_4 uses the readLocalDict function to read the object dictionary parameters. The incoming data are the local object dictionary pointer master402_OD, the slave object dictionary index slave_index, and the slave object dictionary sub-index slave_subindex. After the pointer pdata, the value size, and the parameter type type are successfully written, S3_5 is transferred to perform the slave write operation. S3_5 determines whether the range of the written node number is between 1 and the maximum number of nodes MAX_NODE_COUNT-1, otherwise it directly returns an error; S3_6 uses the semaphore initialization function rt_sem_init to initialize the semaphore finish_sem; S3_7 cyclically calls the function getWriteResultNetworkDict to obtain the result of the master station writing to the slave station object dictionary. After the writing is successful, the closeSDOtransfer function is used to close the data transmission. S3_8 uses the semaphore unloading function rt_sem_detach to unload the semaphore finish_sem.
10. The CANOPEN-based master-slave synchronization method according to claim 9, characterized in that: In step S3_6, the node data writing function writeNetworkDictCallBack is used to write the slave object dictionary parameters. The input data are the local object dictionary pointer master402_OD, the node number node_id, the slave object dictionary index slave_index, the local object dictionary sub-index slave_subindex, the value size size and the parameter type type, and the data pointed to by the pointer pdata is written.
