My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

powerloss.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * feature/powerloss.cpp - Resume an SD print after power-loss
  24. */
  25. #include "../inc/MarlinConfigPre.h"
  26. #if ENABLED(POWER_LOSS_RECOVERY)
  27. #include "powerloss.h"
  28. #include "../core/macros.h"
  29. bool PrintJobRecovery::enabled; // Initialized by settings.load()
  30. SdFile PrintJobRecovery::file;
  31. job_recovery_info_t PrintJobRecovery::info;
  32. const char PrintJobRecovery::filename[5] = "/PLR";
  33. uint8_t PrintJobRecovery::queue_index_r;
  34. uint32_t PrintJobRecovery::cmd_sdpos, // = 0
  35. PrintJobRecovery::sdpos[BUFSIZE];
  36. #if ENABLED(DWIN_CREALITY_LCD)
  37. bool PrintJobRecovery::dwin_flag; // = false
  38. #endif
  39. #include "../sd/cardreader.h"
  40. #include "../lcd/ultralcd.h"
  41. #include "../gcode/queue.h"
  42. #include "../gcode/gcode.h"
  43. #include "../module/motion.h"
  44. #include "../module/planner.h"
  45. #include "../module/printcounter.h"
  46. #include "../module/temperature.h"
  47. #include "../core/serial.h"
  48. #if ENABLED(FWRETRACT)
  49. #include "fwretract.h"
  50. #endif
  51. #define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  52. #include "../core/debug_out.h"
  53. PrintJobRecovery recovery;
  54. #ifndef POWER_LOSS_PURGE_LEN
  55. #define POWER_LOSS_PURGE_LEN 0
  56. #endif
  57. #ifndef POWER_LOSS_ZRAISE
  58. #define POWER_LOSS_ZRAISE 2 // Move on loss with backup power, or on resume without it
  59. #endif
  60. #if DISABLED(BACKUP_POWER_SUPPLY)
  61. #undef POWER_LOSS_RETRACT_LEN // No retract at outage without backup power
  62. #endif
  63. #ifndef POWER_LOSS_RETRACT_LEN
  64. #define POWER_LOSS_RETRACT_LEN 0
  65. #endif
  66. /**
  67. * Clear the recovery info
  68. */
  69. void PrintJobRecovery::init() { memset(&info, 0, sizeof(info)); }
  70. /**
  71. * Enable or disable then call changed()
  72. */
  73. void PrintJobRecovery::enable(const bool onoff) {
  74. enabled = onoff;
  75. changed();
  76. }
  77. /**
  78. * The enabled state was changed:
  79. * - Enabled: Purge the job recovery file
  80. * - Disabled: Write the job recovery file
  81. */
  82. void PrintJobRecovery::changed() {
  83. if (!enabled)
  84. purge();
  85. else if (IS_SD_PRINTING())
  86. save(true);
  87. }
  88. /**
  89. * Check for Print Job Recovery during setup()
  90. *
  91. * If a saved state exists send 'M1000 S' to initiate job recovery.
  92. */
  93. void PrintJobRecovery::check() {
  94. //if (!card.isMounted()) card.mount();
  95. if (card.isMounted()) {
  96. load();
  97. if (!valid()) return cancel();
  98. queue.inject_P(PSTR("M1000 S"));
  99. TERN_(DWIN_CREALITY_LCD, dwin_flag = true);
  100. }
  101. }
  102. /**
  103. * Delete the recovery file and clear the recovery data
  104. */
  105. void PrintJobRecovery::purge() {
  106. init();
  107. card.removeJobRecoveryFile();
  108. }
  109. /**
  110. * Load the recovery data, if it exists
  111. */
  112. void PrintJobRecovery::load() {
  113. if (exists()) {
  114. open(true);
  115. (void)file.read(&info, sizeof(info));
  116. close();
  117. }
  118. debug(PSTR("Load"));
  119. }
  120. /**
  121. * Set info fields that won't change
  122. */
  123. void PrintJobRecovery::prepare() {
  124. card.getAbsFilename(info.sd_filename); // SD filename
  125. cmd_sdpos = 0;
  126. }
  127. /**
  128. * Save the current machine state to the power-loss recovery file
  129. */
  130. void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/) {
  131. #if SAVE_INFO_INTERVAL_MS > 0
  132. static millis_t next_save_ms; // = 0
  133. millis_t ms = millis();
  134. #endif
  135. #ifndef POWER_LOSS_MIN_Z_CHANGE
  136. #define POWER_LOSS_MIN_Z_CHANGE 0.05 // Vase-mode-friendly out of the box
  137. #endif
  138. // Did Z change since the last call?
  139. if (force
  140. #if DISABLED(SAVE_EACH_CMD_MODE) // Always save state when enabled
  141. #if SAVE_INFO_INTERVAL_MS > 0 // Save if interval is elapsed
  142. || ELAPSED(ms, next_save_ms)
  143. #endif
  144. // Save if Z is above the last-saved position by some minimum height
  145. || current_position.z > info.current_position.z + POWER_LOSS_MIN_Z_CHANGE
  146. #endif
  147. ) {
  148. #if SAVE_INFO_INTERVAL_MS > 0
  149. next_save_ms = ms + SAVE_INFO_INTERVAL_MS;
  150. #endif
  151. // Set Head and Foot to matching non-zero values
  152. if (!++info.valid_head) ++info.valid_head; // non-zero in sequence
  153. //if (!IS_SD_PRINTING()) info.valid_head = 0;
  154. info.valid_foot = info.valid_head;
  155. // Machine state
  156. info.current_position = current_position;
  157. info.zraise = zraise;
  158. TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
  159. TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
  160. info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
  161. #if EXTRUDERS > 1
  162. info.active_extruder = active_extruder;
  163. #endif
  164. #if DISABLED(NO_VOLUMETRICS)
  165. info.volumetric_enabled = parser.volumetric_enabled;
  166. #if EXTRUDERS > 1
  167. for (int8_t e = 0; e < EXTRUDERS; e++) info.filament_size[e] = planner.filament_size[e];
  168. #else
  169. if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[active_extruder];
  170. #endif
  171. #endif
  172. #if EXTRUDERS
  173. HOTEND_LOOP() info.target_temperature[e] = thermalManager.temp_hotend[e].target;
  174. #endif
  175. TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.temp_bed.target);
  176. #if HAS_FAN
  177. COPY(info.fan_speed, thermalManager.fan_speed);
  178. #endif
  179. #if HAS_LEVELING
  180. info.leveling = planner.leveling_active;
  181. info.fade = TERN0(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height);
  182. #endif
  183. TERN_(GRADIENT_MIX, memcpy(&info.gradient, &mixer.gradient, sizeof(info.gradient)));
  184. #if ENABLED(FWRETRACT)
  185. COPY(info.retract, fwretract.current_retract);
  186. info.retract_hop = fwretract.current_hop;
  187. #endif
  188. // Relative axis modes
  189. info.axis_relative = gcode.axis_relative;
  190. // Elapsed print job time
  191. info.print_job_elapsed = print_job_timer.duration();
  192. write();
  193. }
  194. }
  195. #if PIN_EXISTS(POWER_LOSS)
  196. #if ENABLED(BACKUP_POWER_SUPPLY)
  197. void PrintJobRecovery::retract_and_lift(const float &zraise) {
  198. #if POWER_LOSS_RETRACT_LEN || POWER_LOSS_ZRAISE
  199. gcode.set_relative_mode(true); // Use relative coordinates
  200. #if POWER_LOSS_RETRACT_LEN
  201. // Retract filament now
  202. gcode.process_subcommands_now_P(PSTR("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
  203. #endif
  204. #if POWER_LOSS_ZRAISE
  205. // Raise the Z axis now
  206. if (zraise) {
  207. char cmd[20], str_1[16];
  208. sprintf_P(cmd, PSTR("G0 Z%s"), dtostrf(zraise, 1, 3, str_1));
  209. gcode.process_subcommands_now(cmd);
  210. }
  211. #else
  212. UNUSED(zraise);
  213. #endif
  214. //gcode.axis_relative = info.axis_relative;
  215. planner.synchronize();
  216. #endif
  217. }
  218. #endif
  219. /**
  220. * An outage was detected by a sensor pin.
  221. * - If not SD printing, let the machine turn off on its own with no "KILL" screen
  222. * - Disable all heaters first to save energy
  223. * - Save the recovery data for the current instant
  224. * - If backup power is available Retract E and Raise Z
  225. * - Go to the KILL screen
  226. */
  227. void PrintJobRecovery::_outage() {
  228. #if ENABLED(BACKUP_POWER_SUPPLY)
  229. static bool lock = false;
  230. if (lock) return; // No re-entrance from idle() during retract_and_lift()
  231. lock = true;
  232. #endif
  233. #if POWER_LOSS_ZRAISE
  234. // Get the limited Z-raise to do now or on resume
  235. const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z);
  236. #else
  237. constexpr float zraise = 0;
  238. #endif
  239. // Save, including the limited Z raise
  240. if (IS_SD_PRINTING()) save(true, zraise);
  241. // Disable all heaters to reduce power loss
  242. thermalManager.disable_all_heaters();
  243. #if ENABLED(BACKUP_POWER_SUPPLY)
  244. // Do a hard-stop of the steppers (with possibly a loud thud)
  245. quickstop_stepper();
  246. // With backup power a retract and raise can be done now
  247. retract_and_lift(zraise);
  248. #endif
  249. kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
  250. }
  251. #endif
  252. /**
  253. * Save the recovery info the recovery file
  254. */
  255. void PrintJobRecovery::write() {
  256. debug(PSTR("Write"));
  257. open(false);
  258. file.seekSet(0);
  259. const int16_t ret = file.write(&info, sizeof(info));
  260. if (ret == -1) DEBUG_ECHOLNPGM("Power-loss file write failed.");
  261. if (!file.close()) DEBUG_ECHOLNPGM("Power-loss file close failed.");
  262. }
  263. /**
  264. * Resume the saved print job
  265. */
  266. void PrintJobRecovery::resume() {
  267. char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
  268. const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
  269. #if HAS_LEVELING
  270. // Make sure leveling is off before any G92 and G28
  271. gcode.process_subcommands_now_P(PSTR("M420 S0 Z0"));
  272. #endif
  273. // Reset E, raise Z, home XY...
  274. #if Z_HOME_DIR > 0
  275. // If Z homing goes to max, just reset E and home all
  276. gcode.process_subcommands_now_P(PSTR(
  277. "G92.9 E0\n"
  278. "G28R0" TERN_(MARLIN_DEV_MODE, "S")
  279. ));
  280. #else // "G92.9 E0 ..."
  281. // Set Z to 0, raise Z by info.zraise, and Home (XY only for Cartesian)
  282. // with no raise. (Only do simulated homing in Marlin Dev Mode.)
  283. sprintf_P(cmd, PSTR("G92.9 E0 "
  284. #if ENABLED(BACKUP_POWER_SUPPLY)
  285. "Z%s" // Z was already raised at outage
  286. #else
  287. "Z0\nG1Z%s" // Set Z=0 and Raise Z now
  288. #endif
  289. ),
  290. dtostrf(info.zraise, 1, 3, str_1)
  291. );
  292. gcode.process_subcommands_now(cmd);
  293. gcode.process_subcommands_now_P(PSTR(
  294. "G28R0" // No raise during G28
  295. TERN_(MARLIN_DEV_MODE, "S") // Simulated Homing
  296. TERN_(IS_CARTESIAN, "XY") // Don't home Z on Cartesian
  297. ));
  298. #endif
  299. // Pretend that all axes are homed
  300. axis_homed = axis_known_position = xyz_bits;
  301. // Recover volumetric extrusion state
  302. #if DISABLED(NO_VOLUMETRICS)
  303. #if EXTRUDERS > 1
  304. for (int8_t e = 0; e < EXTRUDERS; e++) {
  305. sprintf_P(cmd, PSTR("M200 T%i D%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
  306. gcode.process_subcommands_now(cmd);
  307. }
  308. if (!info.volumetric_enabled) {
  309. sprintf_P(cmd, PSTR("M200 T%i D0"), info.active_extruder);
  310. gcode.process_subcommands_now(cmd);
  311. }
  312. #else
  313. if (info.volumetric_enabled) {
  314. sprintf_P(cmd, PSTR("M200 D%s"), dtostrf(info.filament_size[0], 1, 3, str_1));
  315. gcode.process_subcommands_now(cmd);
  316. }
  317. #endif
  318. #endif
  319. #if HAS_HEATED_BED
  320. const int16_t bt = info.target_temperature_bed;
  321. if (bt) {
  322. // Restore the bed temperature
  323. sprintf_P(cmd, PSTR("M190 S%i"), bt);
  324. gcode.process_subcommands_now(cmd);
  325. }
  326. #endif
  327. // Restore all hotend temperatures
  328. #if HAS_HOTEND
  329. HOTEND_LOOP() {
  330. const int16_t et = info.target_temperature[e];
  331. if (et) {
  332. #if HAS_MULTI_HOTEND
  333. sprintf_P(cmd, PSTR("T%i S"), e);
  334. gcode.process_subcommands_now(cmd);
  335. #endif
  336. sprintf_P(cmd, PSTR("M109 S%i"), et);
  337. gcode.process_subcommands_now(cmd);
  338. }
  339. }
  340. #endif
  341. // Select the previously active tool (with no_move)
  342. #if EXTRUDERS > 1
  343. sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
  344. gcode.process_subcommands_now(cmd);
  345. #endif
  346. // Restore print cooling fan speeds
  347. FANS_LOOP(i) {
  348. uint8_t f = info.fan_speed[i];
  349. if (f) {
  350. sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f);
  351. gcode.process_subcommands_now(cmd);
  352. }
  353. }
  354. // Restore retract and hop state
  355. #if ENABLED(FWRETRACT)
  356. LOOP_L_N(e, EXTRUDERS) {
  357. if (info.retract[e] != 0.0) {
  358. fwretract.current_retract[e] = info.retract[e];
  359. fwretract.retracted[e] = true;
  360. }
  361. }
  362. fwretract.current_hop = info.retract_hop;
  363. #endif
  364. #if HAS_LEVELING
  365. // Restore leveling state before 'G92 Z' to ensure
  366. // the Z stepper count corresponds to the native Z.
  367. if (info.fade || info.leveling) {
  368. sprintf_P(cmd, PSTR("M420 S%i Z%s"), int(info.leveling), dtostrf(info.fade, 1, 1, str_1));
  369. gcode.process_subcommands_now(cmd);
  370. }
  371. #endif
  372. #if ENABLED(GRADIENT_MIX)
  373. memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
  374. #endif
  375. // Un-retract if there was a retract at outage
  376. #if POWER_LOSS_RETRACT_LEN
  377. gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000"));
  378. #endif
  379. // Additional purge if configured
  380. #if POWER_LOSS_PURGE_LEN
  381. sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
  382. gcode.process_subcommands_now(cmd);
  383. #endif
  384. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  385. gcode.process_subcommands_now_P(PSTR("G12"));
  386. #endif
  387. // Move back to the saved XY
  388. sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"),
  389. dtostrf(info.current_position.x, 1, 3, str_1),
  390. dtostrf(info.current_position.y, 1, 3, str_2)
  391. );
  392. gcode.process_subcommands_now(cmd);
  393. // Move back to the saved Z
  394. dtostrf(info.current_position.z, 1, 3, str_1);
  395. #if Z_HOME_DIR > 0
  396. sprintf_P(cmd, PSTR("G1 Z%s F200"), str_1);
  397. #else
  398. gcode.process_subcommands_now_P(PSTR("G1 Z0 F200"));
  399. sprintf_P(cmd, PSTR("G92.9 Z%s"), str_1);
  400. #endif
  401. gcode.process_subcommands_now(cmd);
  402. // Restore the feedrate
  403. sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate);
  404. gcode.process_subcommands_now(cmd);
  405. // Restore E position with G92.9
  406. sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position.e, 1, 3, str_1));
  407. gcode.process_subcommands_now(cmd);
  408. // Relative axis modes
  409. gcode.axis_relative = info.axis_relative;
  410. TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
  411. TERN_(HAS_POSITION_SHIFT, position_shift = info.position_shift);
  412. #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
  413. LOOP_XYZ(i) update_workspace_offset((AxisEnum)i);
  414. #endif
  415. // Resume the SD file from the last position
  416. char *fn = info.sd_filename;
  417. extern const char M23_STR[];
  418. sprintf_P(cmd, M23_STR, fn);
  419. gcode.process_subcommands_now(cmd);
  420. sprintf_P(cmd, PSTR("M24 S%ld T%ld"), resume_sdpos, info.print_job_elapsed);
  421. gcode.process_subcommands_now(cmd);
  422. }
  423. #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  424. void PrintJobRecovery::debug(PGM_P const prefix) {
  425. DEBUG_PRINT_P(prefix);
  426. DEBUG_ECHOLNPAIR(" Job Recovery Info...\nvalid_head:", int(info.valid_head), " valid_foot:", int(info.valid_foot));
  427. if (info.valid_head) {
  428. if (info.valid_head == info.valid_foot) {
  429. DEBUG_ECHOPGM("current_position: ");
  430. LOOP_XYZE(i) {
  431. if (i) DEBUG_CHAR(',');
  432. DEBUG_DECIMAL(info.current_position[i]);
  433. }
  434. DEBUG_EOL();
  435. DEBUG_ECHOLNPAIR("zraise: ", info.zraise);
  436. #if HAS_HOME_OFFSET
  437. DEBUG_ECHOPGM("home_offset: ");
  438. LOOP_XYZ(i) {
  439. if (i) DEBUG_CHAR(',');
  440. DEBUG_DECIMAL(info.home_offset[i]);
  441. }
  442. DEBUG_EOL();
  443. #endif
  444. #if HAS_POSITION_SHIFT
  445. DEBUG_ECHOPGM("position_shift: ");
  446. LOOP_XYZ(i) {
  447. if (i) DEBUG_CHAR(',');
  448. DEBUG_DECIMAL(info.position_shift[i]);
  449. }
  450. DEBUG_EOL();
  451. #endif
  452. DEBUG_ECHOLNPAIR("feedrate: ", info.feedrate);
  453. #if EXTRUDERS > 1
  454. DEBUG_ECHOLNPAIR("active_extruder: ", int(info.active_extruder));
  455. #endif
  456. #if HAS_HOTEND
  457. DEBUG_ECHOPGM("target_temperature: ");
  458. HOTEND_LOOP() {
  459. DEBUG_ECHO(info.target_temperature[e]);
  460. if (e < HOTENDS - 1) DEBUG_CHAR(',');
  461. }
  462. DEBUG_EOL();
  463. #endif
  464. #if HAS_HEATED_BED
  465. DEBUG_ECHOLNPAIR("target_temperature_bed: ", info.target_temperature_bed);
  466. #endif
  467. #if HAS_FAN
  468. DEBUG_ECHOPGM("fan_speed: ");
  469. FANS_LOOP(i) {
  470. DEBUG_ECHO(int(info.fan_speed[i]));
  471. if (i < FAN_COUNT - 1) DEBUG_CHAR(',');
  472. }
  473. DEBUG_EOL();
  474. #endif
  475. #if HAS_LEVELING
  476. DEBUG_ECHOLNPAIR("leveling: ", int(info.leveling), " fade: ", info.fade);
  477. #endif
  478. #if ENABLED(FWRETRACT)
  479. DEBUG_ECHOPGM("retract: ");
  480. for (int8_t e = 0; e < EXTRUDERS; e++) {
  481. DEBUG_ECHO(info.retract[e]);
  482. if (e < EXTRUDERS - 1) DEBUG_CHAR(',');
  483. }
  484. DEBUG_EOL();
  485. DEBUG_ECHOLNPAIR("retract_hop: ", info.retract_hop);
  486. #endif
  487. DEBUG_ECHOLNPAIR("sd_filename: ", info.sd_filename);
  488. DEBUG_ECHOLNPAIR("sdpos: ", info.sdpos);
  489. DEBUG_ECHOLNPAIR("print_job_elapsed: ", info.print_job_elapsed);
  490. }
  491. else
  492. DEBUG_ECHOLNPGM("INVALID DATA");
  493. }
  494. DEBUG_ECHOLNPGM("---");
  495. }
  496. #endif // DEBUG_POWER_LOSS_RECOVERY
  497. #endif // POWER_LOSS_RECOVERY