YARP CiA-402 EtherCAT Device 0.6.0
YARP device plugin for EtherCAT CiA-402 drives
Loading...
Searching...
No Matches
StoreHomePosition.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef STORE_HOME_POSITION_H
5#define STORE_HOME_POSITION_H
6
7#include <cstdint>
8#include <memory>
9#include <string>
10
11#include <yarp/os/ResourceFinder.h>
12
13namespace CiA402
14{
15
16/**
17 * @brief Calibration utility: home all CiA-402 drives on the bus and persist the result to flash.
18 *
19 * This application performs a complete homing sequence on every EtherCAT slave found on the
20 * specified network interface using CiA-402 homing methods 37 (current position as home, no index)
21 * or 35 (current position as home, with index). The procedure is executed entirely via SDO
22 * communication, so the ring never needs to reach OPERATIONAL state and no cyclic motion is
23 * commanded.
24 *
25 * After all slaves have been homed and the home position has been saved to their non-volatile
26 * memory, the application reads back the raw and adjusted encoder positions of both encoder
27 * channels together with their resolution parameters and writes the data to a TOML file.
28 * This file can subsequently be used by higher-level software to reconstruct the conversion
29 * from raw encoder counts to degrees without querying the drives again.
30 *
31 * **Per-slave homing sequence:**
32 * 1. Set operation mode to Homing (0x6060 = 6).
33 * 2. Write the selected homing method to 0x6098 (35 or 37).
34 * 3. Optionally write a home offset to 0x607C.
35 * 4. Start homing by toggling bit 4 of the Controlword (0x6040) low→high.
36 * 5. Poll Statusword (0x6041) bit 12 ("Homing attained") until set; abort on bit 13
37 * ("Homing error") or user-specified timeout.
38 * 6. Write vendor-specific restore-on-startup flag to 0x2005:02.
39 * 7. Persist all parameters to non-volatile memory via 0x1010:01 = @c 0x65766173 ("evas").
40 *
41 * **Post-calibration encoder snapshot (written to TOML):**
42 * - Encoder 1 (0x2111): raw position (:01, UDINT), adjusted position (:02, DINT).
43 * - Encoder 2 (0x2113): raw position (:01, UDINT), adjusted position (:02, DINT).
44 * - Encoder resolutions (counts/rev): 0x2110:03 for encoder 1, 0x2112:03 for encoder 2.
45 * - Computed angle in degrees for both raw and adjusted positions of each encoder.
46 * - Conversion factor (degrees/count) for each encoder.
47 *
48 * @note Only SDO communication is used; the ring stays in SAFE-OP/PRE-OP throughout.
49 * @note Setting @c restore-on-boot to @c true causes the drive to boot already referenced,
50 * skipping the homing procedure on the next startup.
51 * @note SOEM uses 1-based slave indices; slave numbering in the output TOML follows the same
52 * convention (@c slave_1, @c slave_2, …).
53 */
55{
56public:
57 /**
58 * @brief Default constructor.
59 *
60 * Allocates the internal implementation object. No EtherCAT communication is started.
61 */
63
64 /**
65 * @brief Destructor.
66 *
67 * Releases all resources owned by the implementation. If the EtherCAT master was
68 * initialised, it is cleanly shut down.
69 */
71
72 /// @cond — non-copyable
73 StoreHome37(const StoreHome37&) = delete;
74 StoreHome37& operator=(const StoreHome37&) = delete;
75 /// @endcond
76
77 /**
78 * @brief Run the full homing and persistence procedure on all slaves, then write encoder data.
79 *
80 * Reads configuration from the provided ResourceFinder, discovers all EtherCAT slaves on the
81 * specified network interface, executes the per-slave homing sequence described in the class
82 * documentation, and finally writes a TOML snapshot of the encoder state to disk.
83 *
84 * @param rf ResourceFinder populated with the parameters listed below.
85 * @return @c true if every slave was homed, persisted, and the TOML file was written
86 * successfully; @c false on any error (initialisation failure, slave not found,
87 * homing error, homing timeout, SDO write failure, file I/O error).
88 *
89 * @note Expected keys in the ResourceFinder:
90 * | Key | Type | Description | Default |
91 * |:----------------:|:-----------:|-------------------------------------------------------|:--------------------------:|
92 * | ifname | string | Network interface name (e.g. @c "eth0") | @c "eth0" |
93 * | method | int | CiA-402 homing method: @c 35 or @c 37 | @c 37 |
94 * | home-offset | int32 | Additional home offset written to 0x607C | @c 0 |
95 * | timeout-ms | int | Maximum time (ms) to wait for homing attained | @c 2000 |
96 * | restore-on-boot | bool / int | Set drive restore-on-startup flag (0x2005:02) | @c true |
97 * | toml-output | string | Path of the TOML file written after calibration | @c "joint_calibration_YYYY_MM_DD_HH_MM_SS.toml" |
98 */
99 bool run(yarp::os::ResourceFinder& rf);
100
101private:
102 class Impl;
103 std::unique_ptr<Impl> m_impl; ///< Opaque implementation (PIMPL idiom).
104};
105
106} // namespace CiA402
107
108#endif // STORE_HOME_POSITION_H
~StoreHome37()
Destructor.
StoreHome37()
Default constructor.
bool run(yarp::os::ResourceFinder &rf)
Run the full homing and persistence procedure on all slaves, then write encoder data.