From 7f98d6028b245da70ca5ca1277d9c664404ceb20 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 21 Sep 2023 21:06:31 -0400 Subject: [PATCH] Commit all work in progress --- app/data/cfg.json | 2 +- app/package-lock.json | 2 +- app/package.json | 2 +- data/cfg.json | 2 +- .../McopyProjector.cpp | 53 +++++++++++++++++-- ino/mcopy_projector_firmware/McopyProjector.h | 13 +++-- .../mcopy_projector_firmware.ino | 7 ++- package-lock.json | 4 +- package.json | 2 +- processing/mcopy/cfg.json | 2 +- scad/mcopy_projector.scad | 35 ++++++------ 11 files changed, 92 insertions(+), 32 deletions(-) diff --git a/app/data/cfg.json b/app/data/cfg.json index 931e3b3..a5fd622 100644 --- a/app/data/cfg.json +++ b/app/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.28", + "version": "1.8.29", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/app/package-lock.json b/app/package-lock.json index 93fe278..66595fc 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.28", + "version": "1.8.29", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/app/package.json b/app/package.json index 6afbb78..de12f71 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.8.28", + "version": "1.8.29", "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 931e3b3..a5fd622 100644 --- a/data/cfg.json +++ b/data/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.28", + "version": "1.8.29", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/ino/mcopy_projector_firmware/McopyProjector.cpp b/ino/mcopy_projector_firmware/McopyProjector.cpp index 2c83932..1a47c70 100644 --- a/ino/mcopy_projector_firmware/McopyProjector.cpp +++ b/ino/mcopy_projector_firmware/McopyProjector.cpp @@ -34,6 +34,8 @@ void McopyProjector::setDirection (bool dir) { } void McopyProjector::frame (bool dir) { + uint16_t spf = _stepsPerFrame * _mode; //scaled + bool running = true; if (dir != _dir) { setDirection(dir); } @@ -41,14 +43,28 @@ void McopyProjector::frame (bool dir) { int64_t takeupGoal = _takeup.currentPosition(); int64_t feedGoal = _feed.currentPosition(); - takeupGoal += _dir ? _stepsPerFrame : -_stepsPerFrame; - feedGoal += _dir ? _stepsPerFrame : -_stepsPerFrame; + takeupGoal += _dir ? spf : -spf; + feedGoal += _dir ? spf : -spf; _takeup.moveTo(takeupGoal); _feed.moveTo(feedGoal); _running = true; + while (running) { + if (_takeup.distanceToGo() == 0 && _feed.distanceToGo() == 0) { + //frame done + running = false; + _posTakeup = takeupGoal; + _posFeed += feedGoal; + } else { + _takeup.run(); + _feed.run(); + } + } + + _running = false; + } void McopyProjector::adjust(uint8_t motor, int64_t steps) { @@ -72,6 +88,7 @@ void McopyProjector::adjustBoth (int64_t steps) { } void McopyProjector::loop () { + /* if (_running) { if (_takeup.distanceToGo() == 0 && _feed.distanceToGo() == 0) { //frame done @@ -90,11 +107,12 @@ void McopyProjector::loop () { _takeup.run(); _feed.run(); } - } + }*/ } //https://wiki.iteadstudio.com/Arduino_Dual_Step_Motor_Driver_Shield void McopyProjector::setStepperMode (uint8_t mode) { + _mode = mode; switch (mode) { case 1 : digitalWrite(_takeupSettingA, LOW); @@ -122,3 +140,32 @@ void McopyProjector::setStepperMode (uint8_t mode) { break; } } + +long McopyProjector::readVcc() { + long result; + // Read 1.1V reference against AVcc + ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); + delay(2); // Wait for Vref to settle + ADCSRA |= _BV(ADSC); // Convert + while (bit_is_set(ADCSRA,ADSC)); + result = ADCL; + result |= ADCH<<8; + result = 1125300L / result; // Back-calculate AVcc in mV + return result; +} + +long McopyProjector::analogReadAccurate (int pin) { + double Vcc = readVcc() / 1000.0; + double ADCValue = analogRead(pin); + return (ADCValue / 1024.0) * Vcc; +} + +long McopyProjector::analogReadAccurateAverage (int pin) { + int count = 3; + double sum = 0.0; + for (int i = 0; i < count; i++) { + sum += analogReadAccurate(pin); + delay(1); + } + return sum / (double) count; +} \ No newline at end of file diff --git a/ino/mcopy_projector_firmware/McopyProjector.h b/ino/mcopy_projector_firmware/McopyProjector.h index 6238459..3184820 100644 --- a/ino/mcopy_projector_firmware/McopyProjector.h +++ b/ino/mcopy_projector_firmware/McopyProjector.h @@ -28,10 +28,11 @@ class McopyProjector { AccelStepper _takeup; AccelStepper _feed; - uint8_t _motorSteps = 1600; //microstepped + uint16_t _motorSteps = 1600; //microstepped uint8_t _frames = 8; - uint8_t _stepsPerFrame = 25; //round(_motorSteps / _frames); - float _speed = 500.0; + uint16_t _stepsPerFrame = 25; //round(_motorSteps / _frames); + uint8_t _mode = 1; + float _speed = 2000.0; int64_t _posTakeup = 0; int64_t _posFeed = 0; @@ -47,6 +48,10 @@ class McopyProjector { bool _running = false; bool _adjusting = false; + long readVcc(); + long analogReadAccurate (int pin); + long analogReadAccurateAverage (int pin); + public: McopyProjector(AccelStepper takeup, AccelStepper feed, uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t feedSettingA, uint8_t feedSettingB); @@ -59,6 +64,8 @@ class McopyProjector { void setDirection(bool dir); void setStepperMode(uint8_t mode); void loop(); + void home(); + }; #endif \ No newline at end of file diff --git a/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino b/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino index a0abb60..ae6de7e 100644 --- a/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino +++ b/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino @@ -37,6 +37,11 @@ #define FEED_SETTINGS_A 8 #define FEED_SETTINGS_B 9 +#define TAKEUP_EMITTER 17 +#define TAKEUP_RECEIVER A8 +#define FEED_EMITTER 18 +#define FEED_RECEIVER A9 + AccelStepper takeup(AccelStepper::DRIVER, TAKEUP_STEP_PIN, TAKEUP_DIR_PIN); AccelStepper feed(AccelStepper::DRIVER, FEED_STEP_PIN, FEED_DIR_PIN); @@ -76,7 +81,7 @@ void loop () { if (digitalRead(BUTTON) == LOW) { projector_frame(); } - projector.loop(); + //projector.loop(); } void pins () { diff --git a/package-lock.json b/package-lock.json index 463872f..592039f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mcopy", - "version": "1.8.28", + "version": "1.8.29", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mcopy", - "version": "1.8.28", + "version": "1.8.29", "license": "MIT", "dependencies": { "arduino": "file:app/lib/arduino", diff --git a/package.json b/package.json index 9394107..1ae4878 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mcopy", - "version": "1.8.28", + "version": "1.8.29", "description": "Small gauge film optical printer platform", "main": "build.js", "directories": { diff --git a/processing/mcopy/cfg.json b/processing/mcopy/cfg.json index 931e3b3..a5fd622 100644 --- a/processing/mcopy/cfg.json +++ b/processing/mcopy/cfg.json @@ -1,5 +1,5 @@ { - "version": "1.8.28", + "version": "1.8.29", "ext_port": 1111, "profiles": { "mcopy": { diff --git a/scad/mcopy_projector.scad b/scad/mcopy_projector.scad index a038752..049da43 100644 --- a/scad/mcopy_projector.scad +++ b/scad/mcopy_projector.scad @@ -96,7 +96,7 @@ module LED_void (pos = [0, 0, 0], rot = [0, 0, 0], flip = false) { EmitterZ = 39.5; ReceiverZ = 65; translate(pos) rotate(rot) { - rotate([0, 90, 0]) { + rotate([0, -90, 0]) { cylinder(r = R(LightVoidD), h = 80, center = true, $fn = 40); if (flip) { translate([0, 0, -EmitterZ]) cylinder(r = R(LEDVoidD), h = 80, center = true, $fn = 40); @@ -169,18 +169,18 @@ module nub_void (pos = [0, 0, 0]) { } } -module stepper_mount_block (pos = [0, 0, 0]) { +module stepper_mount_block (pos = [0, 0, 0], rot = [0, 0, 0]) { BoltX = NEMA17BoltSpacing / 2; BoltY = NEMA17BoltSpacing / 2; H = 30; InnerD = 30; - translate(pos) { + translate(pos) rotate(rot) { difference () { union () { translate([0, 0, -5]) cube([NEMA17OuterWidth, NEMA17OuterWidth, H], center = true); - LED_prop([0, 19, -4.5 + 7.5], [0, 0, 45], flip = true); - LED_prop([0, -19, -4.5 + 11.5], [0, 0, 45], H = 9, flip = false); + LED_prop([0, -19, -4.5 + 7.5], [0, 0, 45], flip = false); + //LED_prop([0, -19, -4.5 + 11.5], [0, 0, 45], H = 9, flip = false); } //corners for (i = [0 : 3]) { @@ -197,8 +197,8 @@ module stepper_mount_block (pos = [0, 0, 0]) { bolt_and_cap_void([BoltX, -BoltY, 10], H, H); bolt_and_cap_void([-BoltX, -BoltY, 10], H, H); // - LED_void([0, 17.25, -4.5], [0, 0, 45]); - LED_void([0, -17.25, 2.5], [0, 0, 45], true); + LED_void([0, -17.25, -4.5], [0, 0, 45]); + //LED_void([0, -17.25, 2.5], [0, 0, 45], true); } } } @@ -206,7 +206,7 @@ module stepper_mount_block (pos = [0, 0, 0]) { module stepper_mount (pos = [0, 0, 0]) { //NEMA17BoltSpacing = 31; translate(pos) { - stepper_mount_block([0, KeyDistance / 2, 0]); + stepper_mount_block([0, KeyDistance / 2, 0], [0, 0, 90]); stepper_mount_block([0, -KeyDistance / 2, 0]); } } @@ -260,7 +260,7 @@ module gate_key_set_screw_void (pos = [0, 0, 0]) { } } -module gate_key (pos = [0, 0, 0], rot = [0, 0, 0]) { +module gate_key (pos = [0, 0, 0], rot = [0, 0, 0], KeyRot = 0) { Extension = 8.75; KeyZ = (13 / 2) + (10 / 2) + 6; OctoVoidX = 12; @@ -277,7 +277,7 @@ module gate_key (pos = [0, 0, 0], rot = [0, 0, 0]) { translate([0, 0, -3]) scale([1.07, 1.07, 1]) { NEMA17_motor_shaft([0, 0, -5]); } - octagon_void([0, 0, 3.5], D = 23.5); + //octagon_void([0, 0, 3.5], D = 23.5); //circular_void([0, 0, 3.5], D = 22); /*translate([0, 0, OctoVoidZ]) { for (i = [0 : 7]) { @@ -289,9 +289,9 @@ module gate_key (pos = [0, 0, 0], rot = [0, 0, 0]) { }*/ //registration flat - translate([0, 26.5, -3.5 - (Extension / 2)]) cube([29, 29, 10 + Extension + 1], center = true); + translate([0, 25, -3.5 - (Extension / 2)]) cube([29, 29, 20 + Extension + 1], center = true); //key - rotate ([0, 0, 45]) { + rotate ([0, 0, 45 + KeyRot]) { translate([0, (10 / 2) + (KeyWidth / 2), KeyZ]) cube([10, 10, 10], center = true); translate([0, -(10 / 2) - (KeyWidth / 2), KeyZ]) cube([10, 10, 10], center = true); } @@ -305,6 +305,7 @@ module gate_key (pos = [0, 0, 0], rot = [0, 0, 0]) { } } + module panel (pos = [0, 0, 0], rot = [0, 0, 0]) { translate(pos) rotate(rot) { difference () { @@ -348,19 +349,19 @@ module debug () { //panel(); //NEMA17([0, KeyDistance / 2, -50]); //NEMA17([0, -KeyDistance / 2, -50]); - //gate_key([0, KeyDistance / 2, -14], [0, 0, 45]); - //gate_key([0, -KeyDistance / 2, -14], [0, 0, 45]); + gate_key([0, KeyDistance / 2, -14], [0, 0, -90 + 45], KeyRot=90); + gate_key([0, -KeyDistance / 2, -14], [0, 0, 180 + 45 ]); difference () { union () { intersection () { panel(); - translate([0, -50, 0]) cube([60, 100, 150], center = true); + //translate([0, -50, 0]) cube([60, 100, 150], center = true); } } //translate([50, 0, 0]) rotate([0, 0, 45]) cube([100, 250, 150], center = true); - translate([0, 0, -75 - 10]) cube([100, 250, 150], center = true); + translate([0, 0, -82.5 - 10]) cube([100, 250, 150], center = true); } } @@ -368,7 +369,7 @@ module debug () { PART = "gate_key"; if (PART == "gate_key") { - gate_key(); + gate_key(KeyRot = 90); } else if (PART == "panel") { rotate([180, 0, 0]) panel(); } else {