-
Notifications
You must be signed in to change notification settings - Fork 4
Add encoder calibration check utility and documentation #57
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3289d48
Add encoder calibration check utility and documentation
GiulioRomualdi 99a4201
Update utils/CheckEncoderCalibration/src/CheckEncoderCalibration.cpp
GiulioRomualdi 39addea
Update utils/CheckEncoderCalibration/README.md
GiulioRomualdi fcdc4af
Clarify reference to StoreHome37 in encoder calibration checker docum…
GiulioRomualdi 0325dc1
Add cross-platform localtime wrapper for time formatting
GiulioRomualdi 080e9ca
Update Doxyfile input paths to remove README.md and include additiona…
GiulioRomualdi 0ee1975
Remove unused includes from CheckEncoderCalibration.cpp
GiulioRomualdi 6518cdd
Remove YARP::YARP_dev from check-encoder-calibration link libraries
GiulioRomualdi 243c1c4
Add Encoder SDO indices and TimeUtils header files; update CMakeLists…
GiulioRomualdi 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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # Check Encoder Calibration {#check_encoder_calibration} | ||
|
|
||
| [TOC] | ||
|
|
||
| ## Purpose | ||
|
|
||
| After a homing / calibration run (performed by @ref CiA402::StoreHome37), the | ||
| encoder positions are persisted on each drive's non-volatile memory and a TOML | ||
| snapshot is written to disk. Over time — due to mechanical play, power cycles, | ||
| firmware updates, or unexpected faults — the actual encoder readings may drift | ||
| from the reference values recorded in that TOML file. | ||
|
|
||
| **`check-encoder-calibration`** is a read-only diagnostic tool that: | ||
|
|
||
| 1. Reads the reference TOML file produced by `store-home-position`. | ||
| 2. Connects to all EtherCAT slaves via SDO (no cyclic motion is commanded). | ||
| 3. Reads back each encoder channel's current raw and adjusted positions plus | ||
| resolution parameters. | ||
| 4. Computes the delta between the recorded and live values. | ||
| 5. Writes a **Markdown report** with summary and per-slave comparison tables. | ||
|
|
||
| > The ring stays in SAFE-OP / PRE-OP throughout; no drive parameters are | ||
| > modified. | ||
|
|
||
| ## SDOs Read | ||
|
|
||
| | SDO | Sub | Type | Description | | ||
| |:--------:|:------:|:-----:|------------------------------------| | ||
| | `0x2110` | `:03` | UDINT | Encoder 1 resolution (counts/rev) | | ||
| | `0x2111` | `:01` | UDINT | Encoder 1 raw position | | ||
| | `0x2111` | `:02` | DINT | Encoder 1 adjusted position | | ||
| | `0x2112` | `:03` | UDINT | Encoder 2 resolution (counts/rev) | | ||
| | `0x2113` | `:01` | UDINT | Encoder 2 raw position | | ||
| | `0x2113` | `:02` | DINT | Encoder 2 adjusted position | | ||
|
|
||
| These are the same objects written to the TOML snapshot by | ||
| @ref CiA402::StoreHome37 — see @ref protocol_map for the full object | ||
| dictionary. | ||
|
|
||
| ## Command-Line Usage | ||
|
|
||
| ```bash | ||
| yarp-cia402-check-encoder-calibration \ | ||
| --ifname eth0 \ | ||
| --toml-input joint_calibration_2026_03_04_18_54_35.toml \ | ||
| --report-output calibration_check.md | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| | Key | Type | Description | Default | | ||
| |:----------------:|:------:|--------------------------------------------------------------|:-------:| | ||
| | `ifname` | string | Network interface used by SOEM | `eth0` | | ||
| | `toml-input` | string | **(required)** Reference TOML file from `store-home-position`| — | | ||
| | `report-output` | string | Path of the Markdown report to write | `encoder_calibration_check_YYYY_MM_DD_HH_MM_SS.md` | | ||
|
|
||
| Parameters can also be provided via a YARP `.ini` file: | ||
|
|
||
| ```ini | ||
| # check_calibration.ini | ||
| ifname eth0 | ||
| toml-input joint_calibration_2026_03_04_18_54_35.toml | ||
| report-output calibration_check.md | ||
| ``` | ||
|
|
||
| ```bash | ||
| yarp-cia402-check-encoder-calibration --from check_calibration.ini | ||
| ``` | ||
|
|
||
| ## Report Format | ||
|
|
||
| The generated Markdown file has three sections: | ||
|
|
||
| ### Header | ||
|
|
||
| | | | | ||
| |:--|:--| | ||
| | **Date** | 2026-03-05 14:30:00 | | ||
| | **Reference TOML** | `joint_calibration_2026_03_04_18_54_35.toml` | | ||
| | **Slaves checked** | 3 | | ||
|
|
||
| ### Summary Table | ||
|
|
||
| One row per slave with the adjusted-position delta in degrees for quick | ||
| pass / fail inspection: | ||
|
|
||
| | Slave | Name | Enc1 Adj Δ (deg) | Enc2 Adj Δ (deg) | | ||
| |:-----:|:--------|------------------:|------------------:| | ||
| | 1 | SOMANET | +0.001234 | −0.000567 | | ||
| | 2 | SOMANET | +0.000000 | +0.000012 | | ||
|
|
||
| ### Per-Slave Detailed Tables | ||
|
|
||
| Two tables per slave (Encoder 1, Encoder 2) with full comparison: | ||
|
|
||
| | Metric | Reference (TOML) | Current (Live) | Delta | | ||
| |:---------------------------|-----------------:|---------------:|----------:| | ||
| | Raw position (counts) | 2461952 | 2461960 | +8 | | ||
| | Raw position (deg) | 350.753906 | 350.754047 | +0.000141 | | ||
| | Adjusted position (counts) | 2461952 | 2461960 | +8 | | ||
| | Adjusted position (deg) | 350.753906 | 350.754047 | +0.000141 | | ||
| | Counts per revolution | 2527232 | 2527232 | 0 | | ||
| | Raw-to-degrees factor | 0.000142 | 0.000142 | +0.000000 | | ||
|
|
||
| ## Typical Workflow | ||
|
|
||
| ```text | ||
| store-home-position check-encoder-calibration | ||
| ─────────────────── ───────────────────────── | ||
| Calibrate all drives ──► reference.toml | ||
| │ | ||
| ▼ | ||
| Read reference + live SDOs | ||
| │ | ||
| ▼ | ||
| Write Markdown report | ||
| ``` | ||
|
|
||
| ```bash | ||
| # 1. Calibrate (done once or when needed) | ||
| yarp-cia402-store-home-position --ifname eth0 --toml-output reference.toml | ||
|
|
||
| # 2. Later, verify calibration integrity | ||
| yarp-cia402-check-encoder-calibration --ifname eth0 --toml-input reference.toml | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| - @ref CiA402::CheckEncoderCalibration — main application class. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| add_subdirectory(StoreHomePosition) | ||
| add_subdirectory(CheckEncoderCalibration) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| add_application( | ||
| NAME check-encoder-calibration | ||
| SOURCES src/main.cpp src/CheckEncoderCalibration.cpp | ||
| HEADERS include/CheckEncoderCalibration/CheckEncoderCalibration.h | ||
| LINK_LIBRARIES YarpCiA402::EthercatManager YARP::YARP_os YARP::YARP_dev tomlplusplus::tomlplusplus) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Check Encoder Calibration 🔍 | ||
|
|
||
| ## Overview 🌟 | ||
| Utility to verify encoder calibration integrity on EtherCAT CiA402 drives. It: | ||
| - Connects to all slaves on the specified network interface via SDO. | ||
| - Reads the current encoder positions (raw and adjusted) and resolutions for both encoder channels. | ||
| - Compares the live values against a reference TOML file previously written by `store-home-position` after calibration. | ||
| - Generates a human-readable **Markdown report** with a summary table and per-slave detailed comparison tables showing reference values, current values, and deltas. | ||
|
|
||
| This allows an operator to quickly spot whether encoder state has drifted since the last calibration without re-running the homing procedure. | ||
|
|
||
| > Note: Tested on Linux. Requires raw-socket/network admin capabilities to access EtherCAT via SOEM. | ||
|
|
||
| ## Post-Install Setup 🔧 | ||
| After installing the project, make sure the binary can find its libraries and has the required capabilities: | ||
|
|
||
| ```console | ||
| patchelf --add-rpath $(dirname $(dirname $(which yarp-cia402-check-encoder-calibration)))/lib $(which yarp-cia402-check-encoder-calibration) | ||
| sudo setcap 'cap_net_raw,cap_net_admin+ep' "$(readlink -f $(which yarp-cia402-check-encoder-calibration))" | ||
| ``` | ||
|
|
||
| ## Usage 🚀 | ||
|
|
||
| Run the tool with the reference TOML file from a previous calibration: | ||
|
|
||
| ```bash | ||
| yarp-cia402-check-encoder-calibration \ | ||
| --ifname eth0 \ | ||
| --toml-input joint_calibration_2026_03_04_18_54_35.toml \ | ||
| --report-output calibration_check.md | ||
| ``` | ||
|
|
||
| ### Options ⚙️ | ||
| - `--ifname`: Network interface used by SOEM (default: `eth0`). | ||
| - `--toml-input`: **(required)** Path of the reference TOML file produced by `store-home-position`. | ||
| - `--report-output`: Path of the Markdown report to write (default: `encoder_calibration_check_<YYYY>_<MM>_<DD>_<HH>_<MM>_<SS>.md`). | ||
|
|
||
| ### Configuration file (optional) 📝 | ||
| You can also provide options through a YARP `.ini` file and pass it with `--from`: | ||
|
|
||
| ```ini | ||
| # check_calibration.ini | ||
| ifname eth0 | ||
| toml-input joint_calibration_2026_03_04_18_54_35.toml | ||
| report-output calibration_check.md | ||
| ``` | ||
|
|
||
| Run with: | ||
|
|
||
| ```bash | ||
| yarp-cia402-check-encoder-calibration --from check_calibration.ini | ||
| ``` | ||
|
|
||
| ## What It Does 🧠 | ||
| 1. Parses the reference TOML file produced by `store-home-position`. | ||
| 2. Initializes the EtherCAT master on `--ifname` and discovers all slaves. | ||
| 3. For each slave found in both the bus and the TOML file, reads the following SDOs: | ||
|
|
||
| | SDO | Sub | Type | Description | | ||
| |:----------:|:----:|:-----:|--------------------------------------------------| | ||
| | `0x2110` | `:03`| UDINT | Encoder 1 resolution (counts/rev) | | ||
| | `0x2111` | `:01`| UDINT | Encoder 1 raw position | | ||
| | `0x2111` | `:02`| DINT | Encoder 1 adjusted position | | ||
| | `0x2112` | `:03`| UDINT | Encoder 2 resolution (counts/rev) | | ||
| | `0x2113` | `:01`| UDINT | Encoder 2 raw position | | ||
| | `0x2113` | `:02`| DINT | Encoder 2 adjusted position | | ||
|
|
||
| 4. Compares each value against the reference and computes the delta. | ||
| 5. Writes a Markdown report. | ||
|
|
||
| ## Report Structure 📄 | ||
|
|
||
| The generated Markdown report contains: | ||
|
|
||
| ### 1. Header | ||
| General information: date/time, reference TOML path, number of slaves checked. | ||
|
|
||
| ### 2. Summary Table | ||
| A quick-glance table with one row per slave showing the adjusted-position delta in degrees for both encoder channels: | ||
|
|
||
| | Slave | Name | Enc1 Adj Δ (deg) | Enc2 Adj Δ (deg) | | ||
| |:-----:|:--------|------------------:|------------------:| | ||
| | 1 | SOMANET | +0.001234 | -0.000567 | | ||
| | 2 | SOMANET | +0.000000 | +0.000012 | | ||
|
|
||
| ### 3. Per-Slave Detailed Tables | ||
| For each slave, two tables (Encoder 1 and Encoder 2) with full comparison: | ||
|
|
||
| | Metric | Reference (TOML) | Current (Live) | Delta | | ||
| |:--------------------------|----------------:|---------------:|----------:| | ||
| | Raw position (counts) | 2461952 | 2461960 | +8 | | ||
| | Raw position (deg) | 350.753906 | 350.754047 | +0.000141 | | ||
| | Adjusted position (counts)| 2461952 | 2461960 | +8 | | ||
| | Adjusted position (deg) | 350.753906 | 350.754047 | +0.000141 | | ||
| | Counts per revolution | 2527232 | 2527232 | 0 | | ||
| | Raw-to-degrees factor | 0.000142 | 0.000142 | +0.000000 | | ||
|
|
||
| ## Example Workflow 🔄 | ||
|
|
||
| ```bash | ||
| # 1. Calibrate and save reference (done once) | ||
| yarp-cia402-store-home-position --ifname eth0 --toml-output calibration_ref.toml | ||
|
|
||
| # 2. Later, verify calibration is still valid | ||
| yarp-cia402-check-encoder-calibration --ifname eth0 --toml-input calibration_ref.toml | ||
|
|
||
| # 3. Open the generated report | ||
| cat encoder_calibration_check_2026_03_05_14_30_00.md | ||
| ``` | ||
|
|
||
| ## Safety Notes ⚠️ | ||
| - This tool performs **read-only** SDO communication; it does not modify any drive parameters. | ||
| - The EtherCAT ring stays in SAFE-OP/PRE-OP throughout; no cyclic motion is commanded. | ||
| - If a slave present on the bus has no matching entry in the TOML reference file, it is skipped with a warning. |
87 changes: 87 additions & 0 deletions
87
utils/CheckEncoderCalibration/include/CheckEncoderCalibration/CheckEncoderCalibration.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // SPDX-FileCopyrightText: Generative Bionics | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| #ifndef CHECK_ENCODER_CALIBRATION_H | ||
| #define CHECK_ENCODER_CALIBRATION_H | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include <yarp/os/ResourceFinder.h> | ||
|
|
||
| namespace CiA402 | ||
| { | ||
|
|
||
| /** | ||
| * @brief Encoder calibration checker: compare live encoder readings against a reference TOML file. | ||
| * | ||
| * This utility connects to all EtherCAT slaves on the specified network interface using SDO | ||
| * communication and reads back the current encoder positions (raw and adjusted) and resolutions | ||
| * for both encoder channels. It then compares these live values against a reference TOML file | ||
| * previously written by @ref CiA402::StoreHome37 (store-home-position application) immediately after calibration. | ||
| * | ||
| * The result is a human-readable Markdown report containing one table per slave, showing: | ||
| * - The reference value from the TOML file. | ||
| * - The current live value read from the drive. | ||
| * - The difference (delta) between the two. | ||
| * | ||
| * This allows an operator to quickly verify whether the encoder state has drifted since the last | ||
| * calibration, without re-running the full homing procedure. | ||
| * | ||
| * @note Only SDO communication is used; the ring stays in SAFE-OP/PRE-OP throughout. | ||
| * @note SOEM uses 1-based slave indices; the TOML file must follow the same convention | ||
| * (@c slave_1, @c slave_2, …). | ||
| */ | ||
| class CheckEncoderCalibration | ||
| { | ||
| public: | ||
| /** | ||
| * @brief Default constructor. | ||
| * | ||
| * Allocates the internal implementation object. No EtherCAT communication is started. | ||
| */ | ||
| CheckEncoderCalibration(); | ||
|
|
||
| /** | ||
| * @brief Destructor. | ||
| * | ||
| * Releases all resources owned by the implementation. If the EtherCAT master was | ||
| * initialised, it is cleanly shut down. | ||
| */ | ||
| ~CheckEncoderCalibration(); | ||
|
|
||
| /// @cond — non-copyable | ||
| CheckEncoderCalibration(const CheckEncoderCalibration&) = delete; | ||
| CheckEncoderCalibration& operator=(const CheckEncoderCalibration&) = delete; | ||
| /// @endcond | ||
|
|
||
| /** | ||
| * @brief Run the full encoder check and produce a Markdown report. | ||
| * | ||
| * Reads configuration from the provided ResourceFinder, discovers all EtherCAT slaves on | ||
| * the specified network interface, reads each slave's encoder data, compares it against | ||
| * the reference TOML file, and writes a Markdown report to disk. | ||
| * | ||
| * @param rf ResourceFinder populated with the parameters listed below. | ||
| * @return @c true if the check completed successfully and the report was written; | ||
| * @c false on any error (initialisation failure, TOML parse error, SDO read failure, | ||
| * file I/O error). | ||
| * | ||
| * @note Expected keys in the ResourceFinder: | ||
| * | Key | Type | Description | Default | | ||
| * |:----------------:|:-----------:|-------------------------------------------------------|:--------------------------:| | ||
| * | ifname | string | Network interface name (e.g. @c "eth0") | @c "eth0" | | ||
| * | toml-input | string | Path of the reference TOML file (from StoreHome37) | *(required)* | | ||
| * | report-output | string | Path of the Markdown report to write | @c "encoder_calibration_check_YYYY_MM_DD_HH_MM_SS.md" | | ||
| */ | ||
| bool run(yarp::os::ResourceFinder& rf); | ||
|
|
||
| private: | ||
| class Impl; | ||
| std::unique_ptr<Impl> m_impl; ///< Opaque implementation (PIMPL idiom). | ||
| }; | ||
|
|
||
| } // namespace CiA402 | ||
|
|
||
| #endif // CHECK_ENCODER_CALIBRATION_H |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.