-
Notifications
You must be signed in to change notification settings - Fork 179
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
feat(hardware): add messages to fetch lifetime motor usage data #12464
Merged
ryanthecoder
merged 4 commits into
edge
from
RLAB-291-use-eeprom-filesystem-to-store-stepper-motor-move-distance-data
Apr 14, 2023
+310
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2aead5e
add can messages for requesting usagage info
ryanthecoder 29169ae
add a script to wipe out a eeprom filesystem to the default settings
ryanthecoder 7f28ff0
fixups for the eeprom reset script
ryanthecoder 2e8b89c
add a script to dump out the eeprom contents
ryanthecoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/usr/bin/env python3 | ||
"""blow away and reset EEPROM file systems.""" | ||
|
||
import asyncio | ||
import logging | ||
import argparse | ||
from logging.config import dictConfig | ||
from typing import Dict, Any | ||
from typing_extensions import Final | ||
|
||
from opentrons_hardware.drivers.can_bus import build, CanMessenger | ||
from opentrons_hardware.firmware_bindings import utils, ArbitrationId | ||
from opentrons_hardware.firmware_bindings.constants import MessageId | ||
from opentrons_hardware.firmware_bindings.messages import ( | ||
MessageDefinition, | ||
message_definitions, | ||
payloads, | ||
) | ||
from opentrons_hardware.firmware_bindings.constants import NodeId | ||
from opentrons_hardware.scripts.can_args import add_can_args, build_settings | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
LOG_CONFIG = { | ||
"version": 1, | ||
"disable_existing_loggers": False, | ||
"formatters": { | ||
"basic": {"format": "%(asctime)s %(name)s %(levelname)s %(message)s"} | ||
}, | ||
"handlers": { | ||
"stream_handler": { | ||
"class": "logging.StreamHandler", | ||
"formatter": "basic", | ||
"level": logging.DEBUG, | ||
}, | ||
}, | ||
"loggers": { | ||
"": { | ||
"handlers": ["stream_handler"], | ||
"level": logging.DEBUG, | ||
}, | ||
}, | ||
} | ||
|
||
TARGETS: Final[Dict[str, NodeId]] = { | ||
"head": NodeId.head, | ||
"gantry-x": NodeId.gantry_x, | ||
"gantry-y": NodeId.gantry_y, | ||
"pipette-left": NodeId.pipette_left, | ||
"pipette-right": NodeId.pipette_right, | ||
"gripper": NodeId.gripper, | ||
} | ||
|
||
|
||
async def run(args: argparse.Namespace) -> None: | ||
"""Script entrypoint.""" | ||
with open(args.file, "w") as f: | ||
|
||
def handle_read_resp( | ||
message: MessageDefinition, arbitration_id: ArbitrationId | ||
) -> None: | ||
"""Called by can messenger when a message arrives.""" | ||
if isinstance(message, message_definitions.ReadFromEEPromResponse): | ||
f.write( | ||
"".join("{:02x} ".format(x) for x in message.payload.data.value) | ||
) | ||
f.write("\n") | ||
|
||
async with build.driver(build_settings(args)) as driver, CanMessenger( | ||
driver | ||
) as messenger: | ||
messenger.add_listener( | ||
handle_read_resp, | ||
lambda arbitration_id: bool( | ||
arbitration_id.parts.message_id == MessageId.read_eeprom_response | ||
), | ||
) | ||
|
||
await dump_eeprom( | ||
messenger, | ||
TARGETS[args.target], | ||
256 if args.old_version else 16384, | ||
) | ||
|
||
|
||
async def dump_eeprom(messenger: CanMessenger, node: NodeId, limit: int) -> None: | ||
"""Wipe out all of the data used for the general purpose file system.""" | ||
start = 0 | ||
max_read = 8 | ||
while start < limit: | ||
read_len = min(max_read, limit - start) | ||
read_msg = message_definitions.ReadFromEEPromRequest( | ||
payload=payloads.EEPromReadPayload( | ||
address=utils.UInt16Field(start), | ||
data_length=utils.UInt16Field(read_len), | ||
) | ||
) | ||
start += read_len | ||
await messenger.send(node, read_msg) | ||
|
||
|
||
def main() -> None: | ||
"""Entry point.""" | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
|
||
add_can_args(parser) | ||
parser.add_argument( | ||
"--target", | ||
help="The FW subsystem to be cleared.", | ||
type=str, | ||
required=True, | ||
choices=TARGETS.keys(), | ||
) | ||
parser.add_argument( | ||
"--file", | ||
help="file where to save the dump file.", | ||
type=str, | ||
default="/var/log/eeprom_dump.hex", | ||
required=False, | ||
) | ||
parser.add_argument( | ||
"--less-logs", | ||
help="Set log level to INFO, so we see less logs.", | ||
action="store_true", | ||
default=False, | ||
) | ||
parser.add_argument( | ||
"--old-version", | ||
help="Enable this flag to clear eeprom on the older 256 Byte eeproms.", | ||
action="store_true", | ||
default=False, | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
def _set_log_lvl_warn(d: Dict[str, Any]) -> None: | ||
for k in d.keys(): | ||
if isinstance(d[k], dict): | ||
_set_log_lvl_warn(d[k]) | ||
elif k == "level": | ||
d[k] = logging.WARNING | ||
|
||
if args.less_logs: | ||
_set_log_lvl_warn(LOG_CONFIG) | ||
dictConfig(LOG_CONFIG) | ||
asyncio.run(run(args)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/usr/bin/env python3 | ||
"""blow away and reset EEPROM file systems.""" | ||
|
||
import asyncio | ||
import logging | ||
import argparse | ||
from logging.config import dictConfig | ||
from typing import Dict, Any | ||
from typing_extensions import Final | ||
|
||
from opentrons_hardware.drivers.can_bus import build, CanMessenger | ||
from opentrons_hardware.firmware_bindings import utils | ||
from opentrons_hardware.firmware_bindings.messages import ( | ||
message_definitions, | ||
payloads, | ||
fields, | ||
) | ||
from opentrons_hardware.firmware_bindings.constants import NodeId | ||
from opentrons_hardware.scripts.can_args import add_can_args, build_settings | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
LOG_CONFIG = { | ||
"version": 1, | ||
"disable_existing_loggers": False, | ||
"formatters": { | ||
"basic": {"format": "%(asctime)s %(name)s %(levelname)s %(message)s"} | ||
}, | ||
"handlers": { | ||
"stream_handler": { | ||
"class": "logging.StreamHandler", | ||
"formatter": "basic", | ||
"level": logging.DEBUG, | ||
}, | ||
}, | ||
"loggers": { | ||
"": { | ||
"handlers": ["stream_handler"], | ||
"level": logging.DEBUG, | ||
}, | ||
}, | ||
} | ||
|
||
TARGETS: Final[Dict[str, NodeId]] = { | ||
"head": NodeId.head, | ||
"gantry-x": NodeId.gantry_x, | ||
"gantry-y": NodeId.gantry_y, | ||
"pipette-left": NodeId.pipette_left, | ||
"pipette-right": NodeId.pipette_right, | ||
"gripper": NodeId.gripper, | ||
} | ||
|
||
|
||
async def run(args: argparse.Namespace) -> None: | ||
"""Script entrypoint.""" | ||
async with build.driver(build_settings(args)) as driver, CanMessenger( | ||
driver | ||
) as messenger: | ||
await clear_eeprom( | ||
messenger, | ||
TARGETS[args.target], | ||
256 if args.old_version else 16384, | ||
"0000000000000000" if args.old_version else "FFFFFFFFFFFFFFFF", | ||
) | ||
|
||
|
||
async def clear_eeprom( | ||
messenger: CanMessenger, node: NodeId, limit: int, filler: str | ||
) -> None: | ||
"""Wipe out all of the data used for the general purpose file system.""" | ||
start = 28 | ||
max_write = 8 | ||
while start < limit: | ||
write_len = min(max_write, limit - start) | ||
write_msg = message_definitions.WriteToEEPromRequest( | ||
payload=payloads.EEPromDataPayload( | ||
address=utils.UInt16Field(start), | ||
data_length=utils.UInt16Field(write_len), | ||
data=fields.EepromDataField.from_string(filler), | ||
) | ||
) | ||
start += write_len | ||
await messenger.ensure_send(node, write_msg, expected_nodes=[node]) | ||
|
||
|
||
def main() -> None: | ||
"""Entry point.""" | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
|
||
add_can_args(parser) | ||
parser.add_argument( | ||
"--target", | ||
help="The FW subsystem to be cleared.", | ||
type=str, | ||
required=True, | ||
choices=TARGETS.keys(), | ||
) | ||
parser.add_argument( | ||
"--less-logs", | ||
help="Set log level to INFO, so we see less logs.", | ||
action="store_true", | ||
default=False, | ||
) | ||
parser.add_argument( | ||
"--old-version", | ||
help="Enable this flag to clear eeprom on the older 256 Byte eeproms.", | ||
action="store_true", | ||
default=False, | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
def _set_log_lvl_warn(d: Dict[str, Any]) -> None: | ||
for k in d.keys(): | ||
if isinstance(d[k], dict): | ||
_set_log_lvl_warn(d[k]) | ||
elif k == "level": | ||
d[k] = logging.WARNING | ||
|
||
if args.less_logs: | ||
_set_log_lvl_warn(LOG_CONFIG) | ||
dictConfig(LOG_CONFIG) | ||
asyncio.run(run(args)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🌬️