Skip to content

Refactor PythonExamples/AHControl to add configuration and unit tests#2

Merged
Juliaj merged 6 commits intohardware-fork:mainfrom
Juliaj:dual_setup_refactor
Feb 26, 2026
Merged

Refactor PythonExamples/AHControl to add configuration and unit tests#2
Juliaj merged 6 commits intohardware-fork:mainfrom
Juliaj:dual_setup_refactor

Conversation

@Juliaj
Copy link

@Juliaj Juliaj commented Feb 16, 2026

Refactors the Python examples and the AHControl (Rust) stack to use shared, canonical hand configuration where applicable, and adds or extends unit tests. PythonExample demos read serial port, servo IDs, and finger calibration from canonical profiles and calibration files. AHControl supports both canonical calibration (config/calibration/, config/hand_geometry.toml) and legacy TOML under Demo/AHControl/config/.

Configuration

Others

  • Unit tests added.
  • CI enabled.

@Juliaj Juliaj force-pushed the dual_setup_refactor branch from 1038180 to e7f59d2 Compare February 16, 2026 20:09
@Juliaj Juliaj force-pushed the dual_setup_refactor branch from e7f59d2 to cb92a8a Compare February 16, 2026 20:11
@Juliaj Juliaj requested review from kbhakt and mwonger February 16, 2026 20:38
@Juliaj Juliaj changed the title Refactor PythonExamples to add configuration and unit tests Refactor PythonExamples/AHControl to add configuration and unit tests Feb 20, 2026

# Commands

Run from the project root. If you use pixi for Rust, run `pixi shell` first. Set `PORT` to your serial device (e.g. `/dev/ttyACM0` on Linux, `COM3` on Windows). For canonical calibration use a file under `config/calibration/` (e.g. `config/calibration/r_hand_team_julia.toml`).
Copy link

Choose a reason for hiding this comment

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

Are you using Rust vs. just python? or is this for future development?

Copy link
Author

Choose a reason for hiding this comment

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

Since this is a refactoring, I wanted to make sure all demos (rust + python) still run. We can decide whether we want to use Rust for development. Rust is also new to me.

ROOT_PATH = Path(os.path.dirname(os.path.abspath(__file__))).parent

# Per-tip (dx, dy, dz) for pos: result = x*1.5+dx, y*1.5+dy, z*1.5+dz
MOCAP_POS_OFFSETS = {
Copy link

Choose a reason for hiding this comment

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

are these manually calculated?

Copy link
Author

Choose a reason for hiding this comment

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

These are the extractions from the upstream code. For example, here are the original lines of code:

if "r_tip1" in hand[0]:
[x,y,z]=hand[0]['r_tip1'].values
self.data.mocap_pos[0]=[x.as_py()*1.5-0.025,y.as_py()*1.5+0.022,z.as_py()*1.5+0.098]
if "r_tip2" in hand[0]:
[x,y,z]=hand[0]['r_tip2'].values
self.data.mocap_pos[1]=[x.as_py()*1.5-0.025,y.as_py()*1.5-0.009,z.as_py()*1.5+0.092]
if "r_tip3" in hand[0]:
[x,y,z]=hand[0]['r_tip3'].values
self.data.mocap_pos[2]=[x.as_py()*1.5-0.025,y.as_py()*1.5-0.040,z.as_py()*1.5+0.082]
if "r_tip4" in hand[0]:
[x,y,z]=hand[0]['r_tip4'].values
self.data.mocap_pos[3]=[x.as_py()*1.5+0.024,y.as_py()*1.5+0.019,z.as_py()*1.5+0.017]

and the values are now put under

MOCAP_POS_OFFSETS = {
    "right": [
        (-0.025, 0.022, 0.098),
        (-0.025, -0.009, 0.092),
        (-0.025, -0.040, 0.082),
        (0.024, 0.019, 0.017),
    ],

@@ -0,0 +1,80 @@
# Canonical Hand Configuration Design (Proposal)
Copy link

Choose a reason for hiding this comment

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

This is nice addition!!

Copy link

@kbhakt kbhakt left a comment

Choose a reason for hiding this comment

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

maybe I missed this, but do you have an automatic linter / check like ruff implemented in this CI pipeline?

@Juliaj
Copy link
Author

Juliaj commented Feb 26, 2026

maybe I missed this, but do you have an automatic linter / check like ruff implemented in this CI pipeline?

Yes, the specifics are in two places. This PR adds a .github/ci.yml, we have


      - name: Run pre-commit
        run: pixi run pre-commit run --all-files

The hooks defined in .pre-commit-config.yaml will perform the linting.

@Juliaj Juliaj merged commit abdc199 into hardware-fork:main Feb 26, 2026
1 check passed
@Juliaj Juliaj deleted the dual_setup_refactor branch March 3, 2026 04:23
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