61 yCInfo(CIA402,
"StoreHome37: initializing EtherCAT on %s", ifname.
c_str());
62 const auto rc = mgr.init(ifname);
65 yCError(CIA402,
"StoreHome37: init failed on %s (rc=%d)", ifname.
c_str(),
int(rc));
73 auto name = mgr.getName(s);
76 yCInfo(CIA402,
"StoreHome3537: found slave %d: %s", s, name.c_str());
81 yCError(CIA402,
"StoreHome3537: no slaves found");
88 allOk = allOk && this->homeAndPersistSingle(s, hm, hoff, timeoutMs, restore);
94 allOk = this->writeEncoderToml(slaves, tomlPath);
108 toml::table slaveTable;
111 uint32_t enc1Res = 0;
112 uint32_t enc2Res = 0;
113 (void)mgr.
readSDO<uint32_t>(s, IDX_ENC1_CONFIG, 0x03, enc1Res);
114 (void)mgr.
readSDO<uint32_t>(s, IDX_ENC2_CONFIG, 0x03, enc2Res);
117 uint32_t enc1RawPos = 0;
118 int32_t enc1AdjPos = 0;
119 (void)mgr.
readSDO<uint32_t>(s, IDX_ENC1_DATA, 0x01, enc1RawPos);
120 (void)mgr.
readSDO<int32_t>(s, IDX_ENC1_DATA, 0x02, enc1AdjPos);
123 uint32_t enc2RawPos = 0;
124 int32_t enc2AdjPos = 0;
125 (void)mgr.
readSDO<uint32_t>(s, IDX_ENC2_DATA, 0x01, enc2RawPos);
126 (void)mgr.
readSDO<int32_t>(s, IDX_ENC2_DATA, 0x02, enc2AdjPos);
129 const double enc1ResInv = enc1Res ? (1.0 /
static_cast<double>(enc1Res)) : 0.0;
130 const double enc2ResInv = enc2Res ? (1.0 /
static_cast<double>(enc2Res)) : 0.0;
131 const double enc1AdjDeg =
static_cast<double>(enc1AdjPos) * enc1ResInv * 360.0;
132 const double enc2AdjDeg =
static_cast<double>(enc2AdjPos) * enc2ResInv * 360.0;
135 const double enc1RawDeg =
static_cast<double>(enc1RawPos) * enc1ResInv * 360.0;
136 const double enc2RawDeg =
static_cast<double>(enc2RawPos) * enc2ResInv * 360.0;
139 toml::table enc1Table;
140 enc1Table.insert(
"raw_position",
static_cast<int64_t
>(enc1RawPos));
141 enc1Table.insert(
"raw_position_degrees", enc1RawDeg);
142 enc1Table.insert(
"adjusted_position",
static_cast<int64_t
>(enc1AdjPos));
143 enc1Table.insert(
"adjusted_position_degrees", enc1AdjDeg);
144 enc1Table.insert(
"counts_per_revolution",
static_cast<int64_t
>(enc1Res));
145 enc1Table.insert(
"raw_to_degrees_factor", enc1Res ? (360.0 /
static_cast<double>(enc1Res)) : 0.0);
146 slaveTable.insert(
"encoder1", enc1Table);
149 toml::table enc2Table;
150 enc2Table.insert(
"raw_position",
static_cast<int64_t
>(enc2RawPos));
151 enc2Table.insert(
"raw_position_degrees", enc2RawDeg);
152 enc2Table.insert(
"adjusted_position",
static_cast<int64_t
>(enc2AdjPos));
153 enc2Table.insert(
"adjusted_position_degrees", enc2AdjDeg);
154 enc2Table.insert(
"counts_per_revolution",
static_cast<int64_t
>(enc2Res));
155 enc2Table.insert(
"raw_to_degrees_factor", enc2Res ? (360.0 /
static_cast<double>(enc2Res)) : 0.0);
156 slaveTable.insert(
"encoder2", enc2Table);
159 slaveTable.insert(
"name", mgr.
getName(s));
161 root.insert(slaveName, slaveTable);
164 "s%02d: enc1 raw=%u adj=%d adj_deg=%.6f (res=%u), "
165 "enc2 raw=%u adj=%d adj_deg=%.6f (res=%u)",
181 yCError(CIA402,
"StoreHome37: cannot open %s for writing", tomlPath.
c_str());
186 yCInfo(CIA402,
"StoreHome37: encoder data written to %s", tomlPath.
c_str());
190 bool homeAndPersistSingle(
int s, int8_t hm, int32_t hoff,
int timeoutMs,
bool restore)
197 yCError(CIA402,
"s%02d: write 0x6060=6 failed", s);
203 if (hm != 35 && hm != 37)
205 yCWarning(CIA402,
"s%02d: invalid homing method %d, using 37", s,
int(hm));
210 yCError(CIA402,
"s%02d: write 0x6098=%d failed", s,
int(hm));
220 yCError(CIA402,
"s%02d: write 0x607C=%d failed", s, hoff);
229 const uint16_t cwLow =
static_cast<uint16_t
>(cw & ~(1u << 4));
230 const uint16_t cwHigh =
static_cast<uint16_t
>(cwLow | (1u << 4));
236 yCError(CIA402,
"s%02d: toggle 0x6040 bit4 failed", s);
249 yCError(CIA402,
"s%02d: read 0x6041 failed", s);
254 yCError(CIA402,
"s%02d: homing error (0x6041=0x%04X)", s, sw);
261 yCInfo(CIA402,
"s%02d: homing attained (pos=%d, sw=0x%04X)", s, pos, sw);
269 yCError(CIA402,
"s%02d: timeout waiting homing attained", s);
278 yCInfo(CIA402,
"s%02d: vendor Home (0x2005:01) = %d", s, homeVal);
282 const uint8_t flag = restore ? uint8_t{1} : uint8_t{0};
286 yCError(CIA402,
"s%02d: write 0x2005:02=%u failed", s, flag);
293 constexpr uint32_t EVAS = 0x65766173u;
297 yCError(CIA402,
"s%02d: save 0x1010:01='evas' failed", s);
301 "s%02d: configuration saved (home persisted, restoreOnStartup=%s)",
303 restore ?
"true" :
"false");