文章

heartbeat机制简介

Heartbeat机制与Node-Guarding机制只能二选一,Hearbeat机制更受推荐。

heartbeat producer

Related Objects: Index: 100E (Node Guarding Identifier), 1017 (Producer Heartbeat Time) Index 100E sub 0 (unsigned 32) 指定Heartbeat所使用的Identifier。The identifier can take values between 1...7FFh, default 700h + Node-Id. Index 1017 sub 0 (unsigned 16) 指定每隔多久设备发送一个心跳,时间单位为毫秒。 若值不为0,则启动heartbeat producer机制,同时停止Node-guarding机制。

heartbeat consumer

Related Objects: Index: 1001, 1003, 1014, 1016, 1029 Emergency Message.

heartbeat demo

  1. Producer: 100E 0 -> 0x00000703 // Heartbeat transmit with can-id 0x703.
  2. Producer: 1017 0 -> 0x00001388 // Transmit every 5 seconds.
  3. CANreal: there should be messages transmitted with 703, 7f (pre-op) every 5 seconds.
  4. CANreal: send MNT message 000, 01 03. // node 3 enters OP
  5. CANreal: there should be messages transmitted with 703, 05 (op) every 5 seconds.
  6. CANreal: send MNT message 000, 02 03.
  7. CANreal: there should be messages transmitted with 703, 04 (stopped) every 5 seconds.
  8. Consumer: 1016 1 -> 0x00031770 // monitor the producer with node-id 03 (bit 16-23), every 6 seconds (0x1770, bit 0-15). 因为consumer设定监控的时间比Producer的时间长,所以Consumer端不会产生错误消息。
  9. Producer: 1017 0 -> 0x0000FFFF // Transmit every about 65 seconds (65535 milli-seconds).
  10. Consumer: Emergency message transmitted with 084, 30 81 11 0x 00 00 00 00 //can-id 084 means the Emergency Message(Index 1014), 0x8130 emergency-error-code means "Heartbeat Error". 0x11 is the value of Index 1001 Error-Register, which means "generic error and communication error". 0x could be value from 01-0A in CAN-CBX-DIO8 which means number of errors in the list (Index 1003 sub 0).
  11. CANreal: send MNT message 000, 01 00. // all nodes enter OP
  12. After node 4 transmit Emergency error message as above, check its state, it should change the state from op to pre-op. Check node 4 Index 1029 (error behaviour object) sub 1 (communication error), the value is 0, which means that when communication error occurs, module should change its state to pre-op state. Value 1 means "no state change", value 2 means change to "stopped" state.
  13. "E" LED in CAN-CBX-DIO8 node 4 will have "2 flashes" state when heartbeat error occurred.

Monitor node with heartbeat demo of esd CANopen manager software stack

As you can see below <Consumer_Heartbeat_Time>10000</Consumer_Heartbeat_Time> in Node 0x4, which means CANopen Manager instance will monitor Node 0x4's heartbeat message (for example: 704, 05[NMT OP state]) every 10 seconds. If there is no heartbeat message transmitted from Node 0x4 within 10 seconds, Manager will react with the specific action which can be defined in <NMT_Action_On_Error>STOP_ALL</NMT_Action_On_Error>, here STOP_ALL means that manager instance will send NMT STOP ALL message (000, 02 00) to the bus. Additionally, once no heartbeat message is not received within defined time, event msg "Disconnected by guarding no x" will be received by manager instance.

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.0 (http://www.xmlspy.com) by xxx (yyy) -->
<CANopen_Manager>
	<Manager_Instance>
		<Net_No>0x3</Net_No>
		<Baudrate>1000</Baudrate>
		<Manager_Node_Id>0x7F</Manager_Node_Id>
		<Boot_Time>1000</Boot_Time>
		<NMT_Master>TRUE</NMT_Master>
		<NMT_Start_All>TRUE</NMT_Start_All>
		<NMT_Auto_Operational>TRUE</NMT_Auto_Operational>
		<NMT_Auto_Start>TRUE</NMT_Auto_Start>
		<NMT_Action_On_Error>STOP_ALL</NMT_Action_On_Error>
		<Node_Instance>
			<Node_Id>0x3</Node_Id>
			<NMT_Mandatory_Slave>TRUE</NMT_Mandatory_Slave>
			<Device_Type_Identification>0x00030191</Device_Type_Identification>
			<Vendor_Identification>0x17</Vendor_Identification>
			<Guard_Time>0</Guard_Time>
			<Life_Time_Factor>0</Life_Time_Factor>
		</Node_Instance>		
		<Node_Instance>
			<Node_Id>0x4</Node_Id>
			<NMT_Mandatory_Slave>TRUE</NMT_Mandatory_Slave>
			<Device_Type_Identification>0x00030191</Device_Type_Identification>
			<Vendor_Identification>0x17</Vendor_Identification>
			<Guard_Time>0</Guard_Time>
			<Life_Time_Factor>0</Life_Time_Factor>
			<Consumer_Heartbeat_Time>10000</Consumer_Heartbeat_Time>
		</Node_Instance>
	</Manager_Instance>
</CANopen_Manager>

Transmit heartbeat message by CANopen manager.

<Heartbeat_Producer_Time>5000</Heartbeat_Producer_Time> means manager node instance 0x7F will send heartbeat message (for example: 77F, 05[NMT OP state]) every 5 seconds.

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.0 (http://www.xmlspy.com) by xxx (yyy) -->
<CANopen_Manager>
	<Manager_Instance>
		<Net_No>0x3</Net_No>
		<Baudrate>1000</Baudrate>
		<Manager_Node_Id>0x7F</Manager_Node_Id>
		<Boot_Time>1000</Boot_Time>
		<NMT_Master>TRUE</NMT_Master>
		<NMT_Start_All>TRUE</NMT_Start_All>
		<NMT_Auto_Operational>TRUE</NMT_Auto_Operational>
		<NMT_Auto_Start>TRUE</NMT_Auto_Start>
		<Heartbeat_Producer_Time>5000</Heartbeat_Producer_Time>
		<Node_Instance>
			<Node_Id>0x3</Node_Id>
			<NMT_Mandatory_Slave>TRUE</NMT_Mandatory_Slave>
			<Device_Type_Identification>0x00030191</Device_Type_Identification>
			<Vendor_Identification>0x17</Vendor_Identification>
			<Guard_Time>0</Guard_Time>
			<Life_Time_Factor>0</Life_Time_Factor>
		</Node_Instance>		
		<Node_Instance>
			<Node_Id>0x4</Node_Id>
			<NMT_Mandatory_Slave>TRUE</NMT_Mandatory_Slave>
			<Device_Type_Identification>0x00030191</Device_Type_Identification>
			<Vendor_Identification>0x17</Vendor_Identification>
			<Guard_Time>0</Guard_Time>
			<Life_Time_Factor>0</Life_Time_Factor>
		</Node_Instance>
	</Manager_Instance>
</CANopen_Manager>