-
Notifications
You must be signed in to change notification settings - Fork 221
402 profile #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
402 profile #23
Conversation
christiansandberg
left a comment
There was a problem hiding this 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?
canopen/profiles/p402.py
Outdated
| # first read the current PDO setup and only change TPDO1 | ||
| print(self.nmt.state) | ||
| self.nmt.state = 'PRE-OPERATIONAL' | ||
| self.pdo.read() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok i understand
canopen/profiles/p402.py
Outdated
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, agree
canopen/profiles/p402.py
Outdated
| 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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
canopen/profiles/p402.py
Outdated
| # 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
|
I've made some changes that will cause some minor conflicts with your changes, could you merge in master to your branch also? |
|
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. |
fd9164e to
ad7a2ce
Compare
|
I've updated documentation and various small things, rebased all onto master. |
|
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. |
for issue #16 I've added code to use nodes with a CiA 402 device profile.
Node402class is a subclass ofNode.PowerStateEngineclass for monitoring state changes. Inspired by the NMT state monitoring in theNmtMasteron_PDO1_callback functionto the TPDO1 callback