Mergemaster#144
Merged
Merged
Conversation
Allow selecting/pinning USB boards and require CANopen masters; add TMC parameter readback. - UC2Client: pass new device_id and requireMaster flags into Serial constructor so callers can pin to a specific board or insist on a CANopen master. - mserial.Serial: accept device_id and requireMaster options; add firmware_info storage, _portMatchesDeviceId helper, and _probeDeviceIdentity to query /state_get and parse identity (pindef, version, etc.). Auto-skip ports that don't match device_id. When requireMaster is set, probe and reject non-master boards to avoid accidentally connecting to motor/slave devices. - state.State: add get_firmware_info and is_master helpers to expose parsed identity (name, version, date, author, pindef, isMaster). - motor.Motor: add get_tmc_parameters (and camelCase alias getTMCSettings) to read TMC settings from /tmc_get; returns a dict of known TMC keys or None if unsupported. These changes let users target specific physical boards, avoid connecting to non-master boards, and read back TMC settings when supported by firmware.
Fixes inflated time estimates by computing absolute travel distance as |current_physical - target_physical| and then converting to hardware steps (avoids sign/sum errors when axes are inverted). Clarifies that speed and acceleration are already expressed in firmware step units and uses their magnitudes directly (keeps a 20000 steps/s² safe default). Also expose acceleration in motor property output by adding "acceleration" and (misspelled) "acceleleration" keys alongside the existing "accel" for compatibility.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends UC2-REST’s Python client to better support multi-board USB environments (e.g., distinguishing CANopen master vs motor/slave boards), while also improving motor move time estimation and adding TMC parameter readback.
Changes:
- Add
device_idandrequireMasteroptions to serial connection setup to pin/select the intended USB device. - Introduce firmware identity parsing helpers (
get_firmware_info,is_master) and serial-side probing to support “master-only” selection. - Fix absolute-move time estimation logic for inverted axes, and add
/tmc_getreadback API with a compatibility alias.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| uc2rest/UC2Client.py | Threads new device_id / requireMaster options through client construction into serial layer. |
| uc2rest/state.py | Adds firmware identity parsing helpers for determining whether a connected board is a CANopen master. |
| uc2rest/mserial.py | Adds device filtering by device_id and master-only probing via /state_get before accepting a port. |
| uc2rest/motor.py | Corrects absolute-distance time estimation on inverted axes; adds TMC readback and expands motor payload fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| motorProp["acceleration"] = int(acceleration[iMotor]) | ||
| else: | ||
| motorProp["accel"] = self.DEFAULT_ACCELERATION | ||
| motorProp["acceleleration"] = self.DEFAULT_ACCELERATION |
| # motor/slave board (ESP32-S3, native USB) is never picked accidentally. | ||
| self.device_id = device_id | ||
| self.requireMaster = requireMaster | ||
| # identity of the board we actually connected to (filled by checkFirmware) |
Comment on lines
+149
to
+151
| The build date and pindef are the fields that matter for telling boards | ||
| apart. Returns an empty dict if nothing could be parsed. | ||
| ''' |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.