Skip to content

Conversation

@luminize
Copy link
Contributor

for issue #16 I've added code to use nodes with a CiA 402 device profile.

  • the Node402 class is a subclass of Node.
  • added to this is a PowerStateEngine class for monitoring state changes. Inspired by the NMT state monitoring in the NmtMaster
  • states are changed by adding the on_PDO1_callback function to the TPDO1 callback

@christiansandberg christiansandberg self-assigned this Feb 27, 2017
Copy link
Member

@christiansandberg christiansandberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with 402 so can't say much about the functionality.

Could you perhaps also add a chapter in the documentation about specific profiles and a bit how to use interface with a 402 node?

# first read the current PDO setup and only change TPDO1
print(self.nmt.state)
self.nmt.state = 'PRE-OPERATIONAL'
self.pdo.read()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do self.pdo.tx[1].read() instead to save some time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok i understand

self.pdo.tx[1].add_variable(0x6041)
# add callback to listen to TPDO1 and change 402 state
self.pdo.tx[1].add_callback(self.powerstate_402.on_PDO1_callback)
self.pdo.trans_type = 255
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be self.pdo.tx[1].trans_type = 255.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, agree

self.pdo.tx[1].add_callback(self.powerstate_402.on_PDO1_callback)
self.pdo.trans_type = 255
self.pdo.tx[1].enabled = True
self.pdo.save()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like above, you can do self.pdo.tx[1].save() to only write to map 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

# Since I haven't found a way to do this the ParameterName is first
# retrieved from the OD, and used for extracting the data in the Map.
description = mapobject.pdo_node.node.object_dictionary[0x6041].name
statusword = mapobject.pdo_node.tx[1][description].raw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also get variables by position, i.e. statusword = mapobject[0].raw. Then you could skip having to add a reference to the parent Node in PdoNode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Thanks, i didnt like my solution, this is better

# the current status
bitmaskvalue = statusword & value[0]
if bitmaskvalue == value[1]:
mapobject.pdo_node.node.powerstate_402._state = key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was a normal method instead of static, you could write self._state = key which I think is easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggled a lot with adding this function to the callback. It looked like calling self.something blocks the code somehow while a static function worked. So the workaround was to access _state from the passed object. I there is a better way i have no problem changing to that.


"""
if self._state in POWER_STATES_402.values():
return POWER_STATES_402[self._state]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't self._state is already a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Takeover from NmtMaster, i'll clean it up

@christiansandberg
Copy link
Member

I've made some changes that will cause some minor conflicts with your changes, could you merge in master to your branch also?

@luminize
Copy link
Contributor Author

I'll add to the documentation, and if you have added new code in master then i'll rebase my branch onto your master. When i push to my github branch ten we can see the new commits appear.

@luminize
Copy link
Contributor Author

I've updated documentation and various small things, rebased all onto master.

@christiansandberg christiansandberg merged commit 44fe038 into canopen-python:master Feb 28, 2017
@luminize
Copy link
Contributor Author

luminize commented Mar 1, 2017

now that this is merged, I have some small future additions, like automatically mirroring the homing state of a device. That's a bit in the Statusword (in TPDO1). I'll make a separate PR for that in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants