From 6f68081dc5fc0b0e05eefdc4466406fa19bfb7b8 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 3 Oct 2023 13:44:04 -0400 Subject: [PATCH] Restore the home method. Now it compiles. --- app/data/cfg.json | 2 +- app/package-lock.json | 2 +- app/package.json | 2 +- data/cfg.json | 2 +- .../McopyProjector.cpp | 113 +++++++++++++----- ino/mcopy_projector_firmware/McopyProjector.h | 1 + package-lock.json | 4 +- package.json | 2 +- processing/mcopy/cfg.json | 2 +- 9 files changed, 95 insertions(+), 35 deletions(-) diff --git a/app/data/cfg.json b/app/data/cfg.json index 2e52ca9..12ee438 100644 --- a/app/data/cfg.json +++ b/app/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.40", + "version": "1.8.41", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/app/package-lock.json b/app/package-lock.json index 25ab44b..9677178 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.40", + "version": "1.8.41", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/app/package.json b/app/package.json index f578163..79da04f 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.40", + "version": "1.8.41", "description": "GUI for the mcopy small gauge film optical printer platform", "main": "main.js", "scripts": { diff --git a/data/cfg.json b/data/cfg.json index 2e52ca9..12ee438 100644 --- a/data/cfg.json +++ b/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.40", + "version": "1.8.41", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/ino/mcopy_projector_firmware/McopyProjector.cpp b/ino/mcopy_projector_firmware/McopyProjector.cpp index af0c31b..ca0a745 100644 --- a/ino/mcopy_projector_firmware/McopyProjector.cpp +++ b/ino/mcopy_projector_firmware/McopyProjector.cpp @@ -157,56 +157,110 @@ void McopyProjector::setStepperMode (uint8_t mode) { } void McopyProjector::home () { - /* uint16_t steps = _motorSteps * _mode; - long reading; - // + uint16_t quarter = steps / 4; + uint16_t eighth = quarter / 2; + uint16_t takeupPeak = 0; + uint16_t feedPeak = 0; + uint16_t takeupOffset = 0; + uint16_t feedOffset = 0; + long takeupReading = 0.0; + long feedReading = 0.0; + + emitters(true); + delay(10); + for (uint16_t i = 0; i < steps; i++) { - reading = analogReadAccurateAverage(_takeupReceiver); - _takeupSamples[i] = reading; + takeupReading = analogReadAccurateAverage(_takeupReceiver); + feedReading = analogReadAccurateAverage(_feedReceiver); + _takeupSamples[i] = takeupReading; + _feedSamples[i] = feedReading; if (i < steps - 1) { _takeup.move(1); + _feed.move(1); _takeup.runToPosition(); + _feed.runToPosition(); } } - // + for (uint16_t i = 0; i < steps; i++) { Serial.print(i); Serial.print(", "); - Serial.println(_takeupSamples[i]); + Serial.print(_takeupSamples[i]); + Serial.print(", "); + Serial.println(_feedSamples[i]); } - uint16_t peak = findPeak(_takeupSamples, steps); - Serial.print("peak: "); - Serial.println(peak); - uint16_t offset = abs(200 - peak); - Serial.print("offset: "); - Serial.println(offset); - if (offset != 0) { - for (uint16_t i = 0; i < offset; i++) { - _takeup.move(-1); - _takeup.runToPosition(); - } - for (uint16_t i = 0; i < 25; i++) { + + takeupPeak = findPeak(_takeupSamples, steps); + feedPeak = findPeak(_feedSamples, steps); + Serial.print(" takeup peak: "); + Serial.println(takeupPeak); + Serial.print(" feed peak: "); + Serial.println(feedPeak); + + takeupOffset = abs(steps - takeupPeak); + feedOffset = abs(steps - takeupPeak); + + Serial.print("takeup offset: "); + Serial.println(takeupOffset); + Serial.print(" feed offset: "); + Serial.println(feedOffset); + + if (takeupOffset > 0) { + for (uint16_t i = 0; i < takeupOffset; i++) { _takeup.move(-1); _takeup.runToPosition(); } } - for (uint16_t i = 0; i < 50; i++) { - reading = analogReadAccurateAverage(_takeupReceiver); - _takeupSamples[i] = reading; + if (feedOffset > 0) { + for (uint16_t i = 0; i < feedOffset; i++) { + _feed.move(-1); + _feed.runToPosition(); + } + } + + for (uint16_t i = 0; i < eighth; i++) { + _takeup.move(-1); + _feed.move(-1); + _takeup.runToPosition(); + _feed.runToPosition(); + } + + for (uint16_t i = 0; i < quarter; i++) { + takeupReading = analogReadAccurateAverage(_takeupReceiver); + feedReading = analogReadAccurateAverage(_feedReceiver); + _takeupSamples[i] = takeupReading; + _feedSamples[i] = feedReading; if (i < steps - 1) { _takeup.move(1); + _feed.move(1); _takeup.runToPosition(); + _feed.runToPosition(); } } - uint16_t peak2 = findPeak(_takeupSamples, 50); - uint16_t offset2 = abs(50 - peak2); - if (offset2 != 0) { - for (uint16_t i = 0; i < offset2; i++) { + + emitters(false); + + takeupPeak = findPeak(_takeupSamples, quarter); + feedPeak = findPeak(_feedSamples, quarter); + takeupOffset = abs(quarter - takeupPeak); + feedOffset = abs(quarter - feedPeak); + + if (takeupOffset > 0) { + for (uint16_t i = 0; i < takeupOffset; i++) { _takeup.move(-1); _takeup.runToPosition(); } - }*/ + } + if (feedOffset > 0) { + for (uint16_t i = 0; i < feedOffset; i++) { + _feed.move(-1); + _feed.runToPosition(); + } + } + + _posTakeup = 0; + _posFeed = 0; } long McopyProjector::readVcc() { @@ -249,3 +303,8 @@ uint16_t McopyProjector::findPeak(long (&arr)[200], uint16_t &steps) { } return maxI; } + +void McopyProjector::emitters (bool enabled) { + digitalWrite(_takeupEmitter, enabled ? HIGH : LOW); + digitalWrite(_feedEmitter, enabled ? HIGH : LOW); +} diff --git a/ino/mcopy_projector_firmware/McopyProjector.h b/ino/mcopy_projector_firmware/McopyProjector.h index 846e7d7..ff10c48 100644 --- a/ino/mcopy_projector_firmware/McopyProjector.h +++ b/ino/mcopy_projector_firmware/McopyProjector.h @@ -62,6 +62,7 @@ class McopyProjector { long analogReadAccurate (uint8_t &pin); long analogReadAccurateAverage (uint8_t &pin); uint16_t findPeak(long (&arr)[200], uint16_t &steps); + void emitters(bool enabled); public: diff --git a/package-lock.json b/package-lock.json index 0b59667..678ccee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcopy", - "version": "1.8.40", + "version": "1.8.41", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mcopy", - "version": "1.8.40", + "version": "1.8.41", "license": "MIT", "dependencies": { "arduino": "file:app/lib/arduino", diff --git a/package.json b/package.json index 8c74f3c..2602262 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcopy", - "version": "1.8.40", + "version": "1.8.41", "description": "Small gauge film optical printer platform", "main": "build.js", "directories": { diff --git a/processing/mcopy/cfg.json b/processing/mcopy/cfg.json index 2e52ca9..12ee438 100644 --- a/processing/mcopy/cfg.json +++ b/processing/mcopy/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.40", + "version": "1.8.41", "ext_port": 1111, "profiles": { "mcopy": {