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,
"profiles": {
"mcopy": {

2
app/package-lock.json generated
View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@ void EndstopCameraShield::setup () {
_checkState();
_enableMotor();
Serial.println(_minSteps);
}
void EndstopCameraShield::_enableCloseInterrupt() {
@ -75,6 +76,7 @@ void EndstopCameraShield::_handleOpenInterrupt() {
void EndstopCameraShield::_checkState() {
_enableCloseEmitter();
_enableOpenEmitter();
delay(3);
if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true;
} else if (digitalRead(_receiverOpenPin) == LOW) {
@ -84,6 +86,22 @@ void EndstopCameraShield::_checkState() {
_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() {
bool primed = false;
bool running = true;
@ -92,17 +110,21 @@ uint32_t EndstopCameraShield::frame() {
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableCloseEmitter();
_enableCloseInterrupt();
_enableOpenEmitter();
//_enableCloseInterrupt();
primed = true;
}
_checkClose();
if (primed && _isClosed) {
running = false;
break;
}
_motor.step();
i++;
}
_disableCloseInterrupt();
//_disableCloseInterrupt();
_disableCloseEmitter();
return i;
}
@ -114,17 +136,21 @@ uint32_t EndstopCameraShield::toOpen() {
_isOpened = false;
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableOpenEmitter();
_enableOpenInterrupt();
_enableCloseEmitter();
//_enableOpenInterrupt();
primed = true;
}
_checkOpen();
if (primed && _isOpened) {
running = false;
break;
}
_motor.step();
i++;
}
_disableOpenInterrupt();
//_disableOpenInterrupt();
_disableOpenEmitter();
return i;
}
@ -136,18 +162,22 @@ uint32_t EndstopCameraShield::toClose() {
_isClosed = false;
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableCloseEmitter();
_enableCloseInterrupt();
_enableOpenEmitter();
//_enableCloseInterrupt();
primed = true;
}
_checkClose();
if (primed && _isClosed) {
running = false;
break;
}
_motor.step();
i++;
}
_disableCloseInterrupt();
_disableCloseEmitter();
//_disableCloseEmitter();
return i;
}
@ -164,4 +194,28 @@ bool EndstopCameraShield::isOpened() {
bool EndstopCameraShield::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 double _ledAngle = 7.0;
const uint32_t _motorSteps = 200;
volatile uint32_t _motorUsPulse = 300;
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;
@ -47,6 +49,8 @@ class EndstopCameraShield {
void _disableCloseEmitter();
void _disableOpenEmitter();
void _disableMotor();
void _checkClose();
void _checkOpen();
static void _handleCloseInterrupt();
static void _handleOpenInterrupt();
@ -63,6 +67,7 @@ class EndstopCameraShield {
void setDirection(bool direction);
bool isOpened();
bool isClosed();
void test();
};
#endif

View File

@ -20,6 +20,7 @@ void EndstopCameraShield::setup () {
_checkState();
_enableMotor();
Serial.println(_minSteps);
}
void EndstopCameraShield::_enableCloseInterrupt() {
@ -75,6 +76,7 @@ void EndstopCameraShield::_handleOpenInterrupt() {
void EndstopCameraShield::_checkState() {
_enableCloseEmitter();
_enableOpenEmitter();
delay(3);
if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true;
} else if (digitalRead(_receiverOpenPin) == LOW) {
@ -84,6 +86,22 @@ void EndstopCameraShield::_checkState() {
_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() {
bool primed = false;
bool running = true;
@ -92,17 +110,21 @@ uint32_t EndstopCameraShield::frame() {
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableCloseEmitter();
_enableCloseInterrupt();
_enableOpenEmitter();
//_enableCloseInterrupt();
primed = true;
}
_checkClose();
if (primed && _isClosed) {
running = false;
break;
}
_motor.step();
i++;
}
_disableCloseInterrupt();
//_disableCloseInterrupt();
_disableCloseEmitter();
return i;
}
@ -114,17 +136,21 @@ uint32_t EndstopCameraShield::toOpen() {
_isOpened = false;
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableOpenEmitter();
_enableOpenInterrupt();
_enableCloseEmitter();
//_enableOpenInterrupt();
primed = true;
}
_checkOpen();
if (primed && _isOpened) {
running = false;
break;
}
_motor.step();
i++;
}
_disableOpenInterrupt();
//_disableOpenInterrupt();
_disableOpenEmitter();
return i;
}
@ -136,18 +162,22 @@ uint32_t EndstopCameraShield::toClose() {
_isClosed = false;
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableCloseEmitter();
_enableCloseInterrupt();
_enableOpenEmitter();
//_enableCloseInterrupt();
primed = true;
}
_checkClose();
if (primed && _isClosed) {
running = false;
break;
}
_motor.step();
i++;
}
_disableCloseInterrupt();
_disableCloseEmitter();
//_disableCloseEmitter();
return i;
}
@ -164,4 +194,28 @@ bool EndstopCameraShield::isOpened() {
bool EndstopCameraShield::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 double _ledAngle = 7.0;
const uint32_t _motorSteps = 200;
volatile uint32_t _motorUsPulse = 300;
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;
@ -47,6 +49,8 @@ class EndstopCameraShield {
void _disableCloseEmitter();
void _disableOpenEmitter();
void _disableMotor();
void _checkClose();
void _checkOpen();
static void _handleCloseInterrupt();
static void _handleOpenInterrupt();
@ -63,6 +67,7 @@ class EndstopCameraShield {
void setDirection(bool direction);
bool isOpened();
bool isClosed();
void test();
};
#endif

View File

@ -20,6 +20,7 @@ void EndstopCameraShield::setup () {
_checkState();
_enableMotor();
Serial.println(_minSteps);
}
void EndstopCameraShield::_enableCloseInterrupt() {
@ -75,6 +76,7 @@ void EndstopCameraShield::_handleOpenInterrupt() {
void EndstopCameraShield::_checkState() {
_enableCloseEmitter();
_enableOpenEmitter();
delay(3);
if (digitalRead(_receiverClosePin) == LOW) {
_isClosed = true;
} else if (digitalRead(_receiverOpenPin) == LOW) {
@ -84,6 +86,22 @@ void EndstopCameraShield::_checkState() {
_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() {
bool primed = false;
bool running = true;
@ -92,17 +110,21 @@ uint32_t EndstopCameraShield::frame() {
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableCloseEmitter();
_enableCloseInterrupt();
_enableOpenEmitter();
//_enableCloseInterrupt();
primed = true;
}
_checkClose();
if (primed && _isClosed) {
running = false;
break;
}
_motor.step();
i++;
}
_disableCloseInterrupt();
//_disableCloseInterrupt();
_disableCloseEmitter();
return i;
}
@ -114,17 +136,21 @@ uint32_t EndstopCameraShield::toOpen() {
_isOpened = false;
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableOpenEmitter();
_enableOpenInterrupt();
_enableCloseEmitter();
//_enableOpenInterrupt();
primed = true;
}
_checkOpen();
if (primed && _isOpened) {
running = false;
break;
}
_motor.step();
i++;
}
_disableOpenInterrupt();
//_disableOpenInterrupt();
_disableOpenEmitter();
return i;
}
@ -136,18 +162,22 @@ uint32_t EndstopCameraShield::toClose() {
_isClosed = false;
_enableMotor();
while (running) {
if (!primed && (double) i * _stepAngle > _ledAngle) {
if (!primed && i > _minSteps) {
_enableCloseEmitter();
_enableCloseInterrupt();
_enableOpenEmitter();
//_enableCloseInterrupt();
primed = true;
}
_checkClose();
if (primed && _isClosed) {
running = false;
break;
}
_motor.step();
i++;
}
_disableCloseInterrupt();
_disableCloseEmitter();
//_disableCloseEmitter();
return i;
}
@ -164,4 +194,28 @@ bool EndstopCameraShield::isOpened() {
bool EndstopCameraShield::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 double _ledAngle = 7.0;
const uint32_t _motorSteps = 200;
volatile uint32_t _motorUsPulse = 300;
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;
@ -47,6 +49,8 @@ class EndstopCameraShield {
void _disableCloseEmitter();
void _disableOpenEmitter();
void _disableMotor();
void _checkClose();
void _checkOpen();
static void _handleCloseInterrupt();
static void _handleOpenInterrupt();
@ -63,6 +67,7 @@ class EndstopCameraShield {
void setDirection(bool direction);
bool isOpened();
bool isClosed();
void test();
};
#endif

View File

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

4
package-lock.json generated
View File

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

View File

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

View File

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