question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hello, I have had everything working for over a year without issue, but i have been forced to update my image with the beaglebone black, and a lot has changed. i can see my servo drive hearbeat with Candump but i am thinking i have some sort of a disconnect with my python version ? i have “python 2.7.13” as the version the beaglebone uses if i use ‘python -V’… but i can only get the scripts to run by typing python3,

these are examples of the types of errors i am getting any ideas for what i need to investigate would be fantastic, as i fear i am simply starting to mess around without understanding the problem.

`debian@beaglebone:~/my_python$ python3 HelloCan.py Traceback (most recent call last): File “HelloCan.py”, line 37, in <module> node.pdo.rx[3][‘Controlword’, ‘Target position’].phys = 1000 File “/home/debian/.local/lib/python3.5/site-packages/canopen/pdo/base.py”, line 212, in getitem var = self.__getitem_by_index(int(key, 16)) TypeError: int() can’t convert non-string with explicit base

debian@beaglebone:~/my_python$ python3 HelloCan.py Traceback (most recent call last): File “HelloCan.py”, line 33, in <module> node.pdo.export(‘database.dbc’) File “/home/debian/.local/lib/python3.5/site-packages/canopen/pdo/base.py”, line 68, in export from canmatrix import canmatrix ImportError: No module named ‘canmatrix’

`debian@beaglebone:~/my_python$ python3.5 MoveCan.py Traceback (most recent call last): File “MoveCan.py”, line 3, in <module> from canopen.profiles.p402 import Node402 ImportError: cannot import name ‘Node402’

debian@beaglebone:~/my_python$ python3.5 MoveCan.py Traceback (most recent call last): File “MoveCan.py”, line 4, in <module> node = canopen.Node402(32, ‘object_dictionary.eds’) AttributeError: module ‘canopen’ has no attribute ‘Node402’

debian@beaglebone:~/my_python$ python3.5 MoveCan.py Traceback (most recent call last): File “MoveCan.py”, line 6, in <module> network.add_node(node) NameError: name ‘node’ is not defined

debian@beaglebone:~/my_python$ python3.5 MoveCan.py Traceback (most recent call last): File “MoveCan.py”, line 9, in <module> node.setup_402_state_machine() NameError: name ‘node’ is not defined

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
af-silvacommented, May 6, 2019

Hi @Wez50,

If you are satisfied and don’t need more help, please close the ticket so this thread can be clean, since this is not a software issue, thanks 😉

1reaction
af-silvacommented, Apr 8, 2019

Hi, that is strange… You don’t need to export, the export is to export da configurations to a ´.dbc´ file. What you need is to first configure the nodes you are trying to control like

# Add some nodes with corresponding Object Dictionaries
node1 = canopen.BaseNode402(35, '<Path to eds file>')
node2 = canopen.BaseNode402(35, '<Path to eds file>')
network.add_node(node1)
network.add_node(node2)

...
for id in self.network.nodes:
  node = self.network[id]
  # Load the configuration read from the EDS file to all the nodes
  node.load_configuration()
  # Start the internal DS402 State Machine
  node.setup_402_state_machine()
  # Start the node guarding mechanism
  node.nmt.start_node_guarding(0.01)
  node.state = 'OPERATION ENABLED'

If all the configuration nodes are present in the eds file you don’t need to do the configuration by hand like in the code example (e.g., node.sdo[0x6040].raw = 0x0F), make sure to call the node.load_configuration(), to make sure the configuration for each node has been loaded correctly you can call the node.rpdo.read() and node.tpdo.read().

One important thing, the Controlword and Statusword must be well configure. The code used in the example ds402 was used by me to test the correct control of my motor. In my configuration I have to configured the heartbeat (the NMT state Guard) the ensures the nodes are running, if the master can’t reach the nodes, they will shutdown.

EDS example, some of the values

[6040]
ParameterName=Controlword
ObjectType=0x7
DataType=0x0006
AccessType=rww
DefaultValue=0x0
PDOMapping=0x1

...

[1600]
SubNumber=0x9
ParameterName=RPDO 1 mapping parameter
ObjectType=0x9

[1600sub0]
ParameterName=number of mapped objects
ObjectType=0x7
DataType=0x0005
AccessType=rw
PDOMapping=0x0
ParameterValue=0x2

[1600sub1]
ParameterName=Target Velocity
ObjectType=0x7
DataType=0x0007
AccessType=rw
DefaultValue=0x60ff0020
PDOMapping=0x0
ParameterValue=0x60ff0020

[1600sub2]
ParameterName=Control Word
ObjectType=0x7
DataType=0x0007
AccessType=rw
DefaultValue=0x60400010
PDOMapping=0x0
ParameterValue=0x60400010

...

[1A00]
SubNumber=0x9
ParameterName=TPDO 1 mapping parameter
ObjectType=0x9

[1A00sub0]
ParameterName=number of mapped objects
ObjectType=0x7
DataType=0x0005
AccessType=rw
DefaultValue=0x2
PDOMapping=0x0
ParameterValue=0x2

[1A00sub1]
ParameterName=Velocity Actual Value
ObjectType=0x7
DataType=0x0007
AccessType=rw
DefaultValue=0x606C0020
PDOMapping=0x0
ParameterValue=0x606C0020


[1A00sub2]
ParameterName=Status Word
ObjectType=0x7
DataType=0x0007
AccessType=rw
DefaultValue=0x60410010
PDOMapping=0x0
ParameterValue=0x60410010

The object 6040 is the ControlWord and the object 6041 is the StatusWord. They are mapped to the RDPO1 and TPDO1 like you can see in the configuration above. My RPDO1 maps the Controlword and the Target velocity, and my TPDO1 maps the Statusworkd and the Velocity Actual Value. This objects are used to issue commands to the drive, also the drive is configured to take action, this is, try to achieve the target velocity at each heart beat sent from the master node (0x80). Also, you need to send using the Controlword the instruction for the drive to move right away, like

SW_TARGET_REACHED = 0x400
SW_SETPOINT_ACKNOWLEDGE = 0x1000
SW_FOLLOWING_ERROR = 0x2000

CW_NEW_SETPOINT = 0X10
CW_NEW_SETPOINT_CHANGE_IMMEDIATELY = 0X30
CW_CHANGE_IMMEDIATELY = 0x20
CW_HALT = 0x100

...

def target_position(self, value):
	"""Target Position Setter used to set the target position of the node
	:param value: Position in counts (device internal units)
	"""
	try:
		self.rpdo_pointers[0x607A].raw = value
		self.rpdo_pointers[0x607A].pdo_parent.transmit()
		self.controlword = State402.CW_OPERATION_ENABLED | self.CW_NEW_SETPOINT_CHANGE_IMMEDIATELY
		timeout = time.time() + 0.5
		while (self.statusword & self.SW_SETPOINT_ACKNOWLEDGE) != self.SW_SETPOINT_ACKNOWLEDGE:
			time.sleep(0.0001)
			if time.time() > timeout:
				raise RuntimeError('Unable to set new position')
		self.controlword = State402.CW_OPERATION_ENABLED | self.CW_CHANGE_IMMEDIATELY
	except KeyError as ex:
		raise ValueError('The object 0x607A (Target Position) is not configured in any PDO, please check the device configuration! Error[{0}]'.format(ex.__str__()))

In the example above I post some of my code to set the target position of the drive using the State402 class and BaseNode402 class … I can’t however post more code … sorry.

Also make sure your BUS configuration is OK like: {'bustype': 'socketcan', 'channel': 'slcan0', 'bitrate': 1000000 }

To test, please read using the candump the messages that are being sent in the network bus. The candump is a tool provided by the SocketCAN utils here.

Sorry if I don’t explained my self well, I don’'t have much time now, but please try to see if you are reaching the nodes through the candump and check your configuration. Also don’t look only at the example, it was meant to only show how to start working with the code and access the controllers. The State402 class has a lot of code that helps in the communication with the controllers but you need to read it and understand how they work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

100+ Fun General Knowledge Quiz Questions 2022
General Knowledge Quiz 1 · What is a group of crows called? · Compared to their body weight, what animal is the strongest...
Read more >
105 best general knowledge quiz questions - Cosmopolitan
If you're on the hunt for the best general knowledge quiz questions, look no further than our 105 random quiz questions, perfect for...
Read more >
300+ general knowledge quiz questions & answers for a pub ...
Obscure quiz questions · How many permanent teeth does a dog have? · What is the most sold flavour of Walker's crisps? ·...
Read more >
50 General Knowledge Quiz Questions and Answers - KwizzBit
Test your trivia knowledge with this selection of our best online general knowledge quiz questions and answers. How many can you get right?...
Read more >
1000 BEST Trivia Questions In 11 Categories - Winter 2022
Selected trivia questions categorized into General Trivia, Animal Trivia, Funny Trivia, History Trivia, Movie Trivia, and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found