Small example on how to drive a motor with CiA-402 device profile #597
Unanswered
Heideachim
asked this question in
Q&A
Replies: 2 comments 1 reply
-
This would be the configuration part, where everything is set up, especially PDOs, and the behaviour of the library is started: # Configure PDOs for velocity mode and start network
# TxPDOs from drive to master:
# TxPDO3: statusword; asynchronous: is sent when 402 state machinge changes
# TxPDO4: velocity actual value, modes of operation display; synchronous: for retrieving the current state on every SYNC message
# RxPDOs from master to drive:
# RxPDO4: controlword, modes of operation, target velocity; asynchronous: immediately sets new values in the drive
network = canopen.Network()
network.connect(interface='ixxat', channel=0, bitrate=1000000)
network.check()
node = BaseNode402(node_id, eds_file)
network.add_node(node)
# Reset network
node.nmt.state = 'RESET COMMUNICATION'
node.nmt.wait_for_bootup(2)
print(f'node NMT state: {node.nmt.state}')
# Read current PDO configuration (must be done, otherwise library only has standard mapping, despite setting new mapping and saved it...?)
node.tpdo.read(from_od = True) # Read PDOs from the online object dictionary
node.rpdo.read(from_od = True)
# clear all PDOs, we will configure them from scratch:
for no in range(1, 5):
node.tpdo[no].clear()
node.rpdo[no].clear()
# TxPDO3: asynchronous/event-driven, contains statusword (is sent if something changes in the 402 state machine)
node.tpdo[3].add_variable(0x6041, 0x00) # Statusword
node.tpdo[3].trans_type = 255 # 1=SYNC; 255=asynchronous --> with every change of the 402 state machine (in 0x2400.04, bit mask 0x00000002 must be set (which is the default))
node.tpdo[3].enabled = True
# TxPDO4: synchronous, contains velocity actual value and modes of operation display
node.tpdo[4].add_variable(0x606C, 0x00) # Velocity actual value
node.tpdo[4].add_variable(0x6061, 0x00) # Modes of operation display
node.tpdo[4].trans_type = 1 # 1=SYNC; 255=asynchronous
node.tpdo[4].enabled = True
# RxPDO4 (0x501): event-driven, contains controlword, modes of operation and target velocity
node.rpdo[4].add_variable(0x6040, 0x00) # Controlword
node.rpdo[4].add_variable(0x6060, 0x00) # Modes of operation
node.rpdo[4].add_variable(0x60FF, 0x00) # Target velocity
node.rpdo[4].trans_type = 255 # 1=SYNC; 255=asynchronous
node.rpdo[4].enabled = True
# Save new configuration (node must be in pre-operational)
node.nmt.state = 'PRE-OPERATIONAL'
node.tpdo.save()
node.rpdo.save()
node.setup_402_state_machine() # start-up the 402-behaviour of the library ( |
Beta Was this translation helpful? Give feedback.
0 replies
-
And this would be the main part, which starts up the drive, sets some velocity to make it turn, then reads back the actual velocity, and shuts down the drive again: # Configure sync and enable PDO communication:
node.nmt.state = 'OPERATIONAL'
network.sync.start(0.010)
try:
# Switch on the 402 state machine and set the mode of operation:
node.rpdo[4]['Modes of operation'].phys = 9 # Cyclic sync velocity mode
node.state = 'SWITCH ON DISABLED'
print(f'node state: {node.state}')
node.state = 'READY TO SWITCH ON'
print(f'node state: {node.state}')
node.state = 'SWITCHED ON'
print(f'node state: {node.state}')
node.state = 'OPERATION ENABLED'
print(f'node state: {node.state}')
# Let the motor turn a bit:
node.rpdo[4]['Target velocity'].phys = 10000
node.rpdo[4].transmit()
# Read 10 values of speed :
for i in range(10):
node.tpdo[4].wait_for_reception()
speed = node.tpdo['Velocity actual value'].phys
print(f'{speed}')
except KeyboardInterrupt:
pass
except BaseException as error:
print('An exception occurred: {}'.format(error))
raise(error)
finally:
print("Stopping")
node.rpdo[4]['Controlword'].raw = 0x00 # Quick stop
node.rpdo[4].transmit()
node.tpdo[4].wait_for_reception()
network.sync.stop() An issue: 'Target velocity' is not transmitted automatically to the drive when the value is set. It needs an explicit |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to create a small script that operates an electrical motor using CiA-402 profile. The drive supports variable PDO-mapping.
Additional, basic information is in Best practices for using this library #471
This thread started in examples/simple_ds402_node.py uses contradictory PDO mapping patterns #496 (Many thanks to @acolomb for his hepful input!)
While the drive sends it state cyclically (when a SYNC telegram arrives, e.g. every 10ms), new target values are sent asynchronically by the master. This is a deviation from the standard behaviour of a PLC, which has a cyclic main task running doing all input/output.
Beta Was this translation helpful? Give feedback.
All reactions