All updates to EndstopCameraShield library for Oxberry and Mitchell cameras (now working and tested).

This commit is contained in:
Matt McWilliams 2024-07-30 20:00:09 -04:00
parent abc72087b2
commit c3d2943dcc
14 changed files with 218 additions and 38 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.123", "version": "1.8.124",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.8.123", "version": "1.8.124",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.8.123", "version": "1.8.124",
"description": "GUI for the mcopy small gauge film optical printer platform", "description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.123", "version": "1.8.124",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -20,6 +20,7 @@ void EndstopCameraShield::setup () {
_checkState(); _checkState();
_enableMotor(); _enableMotor();
Serial.println(_minSteps);
} }
void EndstopCameraShield::_enableCloseInterrupt() { void EndstopCameraShield::_enableCloseInterrupt() {
@ -75,6 +76,7 @@ void EndstopCameraShield::_handleOpenInterrupt() {
void EndstopCameraShield::_checkState() { void EndstopCameraShield::_checkState() {
_enableCloseEmitter(); _enableCloseEmitter();
_enableOpenEmitter(); _enableOpenEmitter();
delay(3);
if (digitalRead(_receiverClosePin) == LOW) { if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true; _isClosed = true;
} else if (digitalRead(_receiverOpenPin) == LOW) { } else if (digitalRead(_receiverOpenPin) == LOW) {
@ -84,6 +86,22 @@ void EndstopCameraShield::_checkState() {
_disableOpenEmitter(); _disableOpenEmitter();
} }
void EndstopCameraShield::_checkClose() {
if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true;
} else {
_isClosed = false;
}
}
void EndstopCameraShield::_checkOpen() {
if (digitalRead(_receiverOpenPin) == LOW) {
_isOpened = true;
} else {
_isOpened = false;
}
}
uint32_t EndstopCameraShield::frame() { uint32_t EndstopCameraShield::frame() {
bool primed = false; bool primed = false;
bool running = true; bool running = true;
@ -92,17 +110,21 @@ uint32_t EndstopCameraShield::frame() {
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableCloseEmitter(); _enableCloseEmitter();
_enableCloseInterrupt(); _enableOpenEmitter();
//_enableCloseInterrupt();
primed = true; primed = true;
} }
_checkClose();
if (primed && _isClosed) { if (primed && _isClosed) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableCloseInterrupt(); //_disableCloseInterrupt();
_disableCloseEmitter(); _disableCloseEmitter();
return i; return i;
} }
@ -114,17 +136,21 @@ uint32_t EndstopCameraShield::toOpen() {
_isOpened = false; _isOpened = false;
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableOpenEmitter(); _enableOpenEmitter();
_enableOpenInterrupt(); _enableCloseEmitter();
//_enableOpenInterrupt();
primed = true; primed = true;
} }
_checkOpen();
if (primed && _isOpened) { if (primed && _isOpened) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableOpenInterrupt(); //_disableOpenInterrupt();
_disableOpenEmitter(); _disableOpenEmitter();
return i; return i;
} }
@ -136,18 +162,22 @@ uint32_t EndstopCameraShield::toClose() {
_isClosed = false; _isClosed = false;
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableCloseEmitter(); _enableCloseEmitter();
_enableCloseInterrupt(); _enableOpenEmitter();
//_enableCloseInterrupt();
primed = true; primed = true;
} }
_checkClose();
if (primed && _isClosed) { if (primed && _isClosed) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableCloseInterrupt(); _disableCloseInterrupt();
_disableCloseEmitter(); //_disableCloseEmitter();
return i; return i;
} }
@ -164,4 +194,28 @@ bool EndstopCameraShield::isOpened() {
bool EndstopCameraShield::isClosed() { bool EndstopCameraShield::isClosed() {
return _isClosed; return _isClosed;
}
void EndstopCameraShield::test () {
_enableCloseEmitter();
_enableOpenEmitter();
delay(1000);
for (uint32_t i = 0; i < _motorMicrosteps * 200; i++) {
_motor.step();
Serial.print(i);
Serial.print(" ");
if (digitalRead(_receiverOpenPin) == HIGH) {
Serial.print("OPEN _ ");
} else {
Serial.print("OPEN x ");
}
if (digitalRead(_receiverClosePin) == HIGH) {
Serial.print("CLOSE _");
} else {
Serial.print("CLOSE x");
}
Serial.println("");
}
_enableCloseEmitter();
_enableOpenEmitter();
} }

View File

@ -24,10 +24,12 @@ class EndstopCameraShield {
const uint8_t _motorPulsePin = 8; const uint8_t _motorPulsePin = 8;
const double _ledAngle = 7.0; const double _ledAngle = 7.0;
const uint32_t _motorSteps = 200;
volatile uint32_t _motorUsPulse = 300; volatile uint32_t _motorUsPulse = 300;
volatile uint8_t _motorMicrosteps = 2; //half stepping volatile uint8_t _motorMicrosteps = 2; //half stepping
volatile double _stepAngle = (double) 360 / ((double) 2 * (double) 200); volatile double _stepAngle = (double) 360 / ((double) _motorMicrosteps * (double) _motorSteps);
volatile uint32_t _minSteps = 31;
TB6600MotorDriver _motor; TB6600MotorDriver _motor;
@ -47,6 +49,8 @@ class EndstopCameraShield {
void _disableCloseEmitter(); void _disableCloseEmitter();
void _disableOpenEmitter(); void _disableOpenEmitter();
void _disableMotor(); void _disableMotor();
void _checkClose();
void _checkOpen();
static void _handleCloseInterrupt(); static void _handleCloseInterrupt();
static void _handleOpenInterrupt(); static void _handleOpenInterrupt();
@ -63,6 +67,7 @@ class EndstopCameraShield {
void setDirection(bool direction); void setDirection(bool direction);
bool isOpened(); bool isOpened();
bool isClosed(); bool isClosed();
void test();
}; };
#endif #endif

View File

@ -20,6 +20,7 @@ void EndstopCameraShield::setup () {
_checkState(); _checkState();
_enableMotor(); _enableMotor();
Serial.println(_minSteps);
} }
void EndstopCameraShield::_enableCloseInterrupt() { void EndstopCameraShield::_enableCloseInterrupt() {
@ -75,6 +76,7 @@ void EndstopCameraShield::_handleOpenInterrupt() {
void EndstopCameraShield::_checkState() { void EndstopCameraShield::_checkState() {
_enableCloseEmitter(); _enableCloseEmitter();
_enableOpenEmitter(); _enableOpenEmitter();
delay(3);
if (digitalRead(_receiverClosePin) == LOW) { if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true; _isClosed = true;
} else if (digitalRead(_receiverOpenPin) == LOW) { } else if (digitalRead(_receiverOpenPin) == LOW) {
@ -84,6 +86,22 @@ void EndstopCameraShield::_checkState() {
_disableOpenEmitter(); _disableOpenEmitter();
} }
void EndstopCameraShield::_checkClose() {
if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true;
} else {
_isClosed = false;
}
}
void EndstopCameraShield::_checkOpen() {
if (digitalRead(_receiverOpenPin) == LOW) {
_isOpened = true;
} else {
_isOpened = false;
}
}
uint32_t EndstopCameraShield::frame() { uint32_t EndstopCameraShield::frame() {
bool primed = false; bool primed = false;
bool running = true; bool running = true;
@ -92,17 +110,21 @@ uint32_t EndstopCameraShield::frame() {
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableCloseEmitter(); _enableCloseEmitter();
_enableCloseInterrupt(); _enableOpenEmitter();
//_enableCloseInterrupt();
primed = true; primed = true;
} }
_checkClose();
if (primed && _isClosed) { if (primed && _isClosed) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableCloseInterrupt(); //_disableCloseInterrupt();
_disableCloseEmitter(); _disableCloseEmitter();
return i; return i;
} }
@ -114,17 +136,21 @@ uint32_t EndstopCameraShield::toOpen() {
_isOpened = false; _isOpened = false;
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableOpenEmitter(); _enableOpenEmitter();
_enableOpenInterrupt(); _enableCloseEmitter();
//_enableOpenInterrupt();
primed = true; primed = true;
} }
_checkOpen();
if (primed && _isOpened) { if (primed && _isOpened) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableOpenInterrupt(); //_disableOpenInterrupt();
_disableOpenEmitter(); _disableOpenEmitter();
return i; return i;
} }
@ -136,18 +162,22 @@ uint32_t EndstopCameraShield::toClose() {
_isClosed = false; _isClosed = false;
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableCloseEmitter(); _enableCloseEmitter();
_enableCloseInterrupt(); _enableOpenEmitter();
//_enableCloseInterrupt();
primed = true; primed = true;
} }
_checkClose();
if (primed && _isClosed) { if (primed && _isClosed) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableCloseInterrupt(); _disableCloseInterrupt();
_disableCloseEmitter(); //_disableCloseEmitter();
return i; return i;
} }
@ -164,4 +194,28 @@ bool EndstopCameraShield::isOpened() {
bool EndstopCameraShield::isClosed() { bool EndstopCameraShield::isClosed() {
return _isClosed; return _isClosed;
}
void EndstopCameraShield::test () {
_enableCloseEmitter();
_enableOpenEmitter();
delay(1000);
for (uint32_t i = 0; i < _motorMicrosteps * 200; i++) {
_motor.step();
Serial.print(i);
Serial.print(" ");
if (digitalRead(_receiverOpenPin) == HIGH) {
Serial.print("OPEN _ ");
} else {
Serial.print("OPEN x ");
}
if (digitalRead(_receiverClosePin) == HIGH) {
Serial.print("CLOSE _");
} else {
Serial.print("CLOSE x");
}
Serial.println("");
}
_enableCloseEmitter();
_enableOpenEmitter();
} }

View File

@ -24,10 +24,12 @@ class EndstopCameraShield {
const uint8_t _motorPulsePin = 8; const uint8_t _motorPulsePin = 8;
const double _ledAngle = 7.0; const double _ledAngle = 7.0;
const uint32_t _motorSteps = 200;
volatile uint32_t _motorUsPulse = 300; volatile uint32_t _motorUsPulse = 300;
volatile uint8_t _motorMicrosteps = 2; //half stepping volatile uint8_t _motorMicrosteps = 2; //half stepping
volatile double _stepAngle = (double) 360 / ((double) 2 * (double) 200); volatile double _stepAngle = (double) 360 / ((double) _motorMicrosteps * (double) _motorSteps);
volatile uint32_t _minSteps = 31;
TB6600MotorDriver _motor; TB6600MotorDriver _motor;
@ -47,6 +49,8 @@ class EndstopCameraShield {
void _disableCloseEmitter(); void _disableCloseEmitter();
void _disableOpenEmitter(); void _disableOpenEmitter();
void _disableMotor(); void _disableMotor();
void _checkClose();
void _checkOpen();
static void _handleCloseInterrupt(); static void _handleCloseInterrupt();
static void _handleOpenInterrupt(); static void _handleOpenInterrupt();
@ -63,6 +67,7 @@ class EndstopCameraShield {
void setDirection(bool direction); void setDirection(bool direction);
bool isOpened(); bool isOpened();
bool isClosed(); bool isClosed();
void test();
}; };
#endif #endif

View File

@ -20,6 +20,7 @@ void EndstopCameraShield::setup () {
_checkState(); _checkState();
_enableMotor(); _enableMotor();
Serial.println(_minSteps);
} }
void EndstopCameraShield::_enableCloseInterrupt() { void EndstopCameraShield::_enableCloseInterrupt() {
@ -75,6 +76,7 @@ void EndstopCameraShield::_handleOpenInterrupt() {
void EndstopCameraShield::_checkState() { void EndstopCameraShield::_checkState() {
_enableCloseEmitter(); _enableCloseEmitter();
_enableOpenEmitter(); _enableOpenEmitter();
delay(3);
if (digitalRead(_receiverClosePin) == LOW) { if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true; _isClosed = true;
} else if (digitalRead(_receiverOpenPin) == LOW) { } else if (digitalRead(_receiverOpenPin) == LOW) {
@ -84,6 +86,22 @@ void EndstopCameraShield::_checkState() {
_disableOpenEmitter(); _disableOpenEmitter();
} }
void EndstopCameraShield::_checkClose() {
if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true;
} else {
_isClosed = false;
}
}
void EndstopCameraShield::_checkOpen() {
if (digitalRead(_receiverOpenPin) == LOW) {
_isOpened = true;
} else {
_isOpened = false;
}
}
uint32_t EndstopCameraShield::frame() { uint32_t EndstopCameraShield::frame() {
bool primed = false; bool primed = false;
bool running = true; bool running = true;
@ -92,17 +110,21 @@ uint32_t EndstopCameraShield::frame() {
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableCloseEmitter(); _enableCloseEmitter();
_enableCloseInterrupt(); _enableOpenEmitter();
//_enableCloseInterrupt();
primed = true; primed = true;
} }
_checkClose();
if (primed && _isClosed) { if (primed && _isClosed) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableCloseInterrupt(); //_disableCloseInterrupt();
_disableCloseEmitter(); _disableCloseEmitter();
return i; return i;
} }
@ -114,17 +136,21 @@ uint32_t EndstopCameraShield::toOpen() {
_isOpened = false; _isOpened = false;
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableOpenEmitter(); _enableOpenEmitter();
_enableOpenInterrupt(); _enableCloseEmitter();
//_enableOpenInterrupt();
primed = true; primed = true;
} }
_checkOpen();
if (primed && _isOpened) { if (primed && _isOpened) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableOpenInterrupt(); //_disableOpenInterrupt();
_disableOpenEmitter(); _disableOpenEmitter();
return i; return i;
} }
@ -136,18 +162,22 @@ uint32_t EndstopCameraShield::toClose() {
_isClosed = false; _isClosed = false;
_enableMotor(); _enableMotor();
while (running) { while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) { if (!primed && i > _minSteps) {
_enableCloseEmitter(); _enableCloseEmitter();
_enableCloseInterrupt(); _enableOpenEmitter();
//_enableCloseInterrupt();
primed = true; primed = true;
} }
_checkClose();
if (primed && _isClosed) { if (primed && _isClosed) {
running = false; running = false;
break;
} }
_motor.step();
i++; i++;
} }
_disableCloseInterrupt(); _disableCloseInterrupt();
_disableCloseEmitter(); //_disableCloseEmitter();
return i; return i;
} }
@ -164,4 +194,28 @@ bool EndstopCameraShield::isOpened() {
bool EndstopCameraShield::isClosed() { bool EndstopCameraShield::isClosed() {
return _isClosed; return _isClosed;
}
void EndstopCameraShield::test () {
_enableCloseEmitter();
_enableOpenEmitter();
delay(1000);
for (uint32_t i = 0; i < _motorMicrosteps * 200; i++) {
_motor.step();
Serial.print(i);
Serial.print(" ");
if (digitalRead(_receiverOpenPin) == HIGH) {
Serial.print("OPEN _ ");
} else {
Serial.print("OPEN x ");
}
if (digitalRead(_receiverClosePin) == HIGH) {
Serial.print("CLOSE _");
} else {
Serial.print("CLOSE x");
}
Serial.println("");
}
_enableCloseEmitter();
_enableOpenEmitter();
} }

View File

@ -24,10 +24,12 @@ class EndstopCameraShield {
const uint8_t _motorPulsePin = 8; const uint8_t _motorPulsePin = 8;
const double _ledAngle = 7.0; const double _ledAngle = 7.0;
const uint32_t _motorSteps = 200;
volatile uint32_t _motorUsPulse = 300; volatile uint32_t _motorUsPulse = 300;
volatile uint8_t _motorMicrosteps = 2; //half stepping volatile uint8_t _motorMicrosteps = 2; //half stepping
volatile double _stepAngle = (double) 360 / ((double) 2 * (double) 200); volatile double _stepAngle = (double) 360 / ((double) _motorMicrosteps * (double) _motorSteps);
volatile uint32_t _minSteps = 31;
TB6600MotorDriver _motor; TB6600MotorDriver _motor;
@ -47,6 +49,8 @@ class EndstopCameraShield {
void _disableCloseEmitter(); void _disableCloseEmitter();
void _disableOpenEmitter(); void _disableOpenEmitter();
void _disableMotor(); void _disableMotor();
void _checkClose();
void _checkOpen();
static void _handleCloseInterrupt(); static void _handleCloseInterrupt();
static void _handleOpenInterrupt(); static void _handleOpenInterrupt();
@ -63,6 +67,7 @@ class EndstopCameraShield {
void setDirection(bool direction); void setDirection(bool direction);
bool isOpened(); bool isOpened();
bool isClosed(); bool isClosed();
void test();
}; };
#endif #endif

View File

@ -25,12 +25,15 @@ void setup () {
if (cam.isOpened()) { if (cam.isOpened()) {
mc.log("Camera is OPENED, closing..."); mc.log("Camera is OPENED, closing...");
cam.toClose(); cam.toClose();
mc.log("Camera is CLOSED");
} else if (cam.isClosed()) { } else if (cam.isClosed()) {
mc.log("Camera is CLOSED"); mc.log("Camera is CLOSED");
} else { } else {
mc.log("Camera is in UNKNOWN state, closing..."); mc.log("Camera is in UNKNOWN state, closing...");
cam.toClose(); cam.toClose();
mc.log("Camera is CLOSED");
} }
//cam.test();
} }
void loop () { void loop () {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.8.123", "version": "1.8.124",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mcopy", "name": "mcopy",
"version": "1.8.123", "version": "1.8.124",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"alert": "file:app/lib/alert", "alert": "file:app/lib/alert",

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.8.123", "version": "1.8.124",
"description": "Small gauge film optical printer platform", "description": "Small gauge film optical printer platform",
"main": "build.js", "main": "build.js",
"directories": { "directories": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.8.123", "version": "1.8.124",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {