Work on oxberry camera firmware. Basics are there. Will add button features to mitchell.
This commit is contained in:
parent
84fe1b71be
commit
c0e7422920
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"ext_port": 1111,
|
"ext_port": 1111,
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"mcopy": {
|
"mcopy": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "mcopy-app",
|
"name": "mcopy-app",
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "mcopy-app",
|
"name": "mcopy-app",
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"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": {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"ext_port": 1111,
|
"ext_port": 1111,
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"mcopy": {
|
"mcopy": {
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#include "EndstopCameraShield.h"
|
#include "EndstopCameraShield.h"
|
||||||
|
|
||||||
EndstopCameraShield::EndstopCameraShield (uint32_t usPulse, uint8_t microsteps) : motorUsPulse(usPulse), motorMicrosteps(microsteps), motor(motorEnablePin, motorDirectionPin, motorPulsePin, motorUsPulse, motorMicrosteps) {
|
volatile bool EndstopCameraShield::_direction = true; //true = forward, false = backward
|
||||||
|
volatile bool EndstopCameraShield::_enabled = false;
|
||||||
|
volatile bool EndstopCameraShield::_isClosed = false;
|
||||||
|
volatile bool EndstopCameraShield::_isOpened = false;
|
||||||
|
|
||||||
|
EndstopCameraShield::EndstopCameraShield (uint32_t usPulse, uint8_t microsteps) : _motorUsPulse(usPulse), _motorMicrosteps(microsteps), _motor(_motorEnablePin, _motorDirectionPin, _motorPulsePin, _motorUsPulse, _motorMicrosteps) {
|
||||||
|
_stepAngle = (double) 360 / ((double) microsteps * (double) 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndstopCameraShield::loop () {
|
void EndstopCameraShield::loop () {
|
||||||
|
@ -9,7 +14,154 @@ void EndstopCameraShield::loop () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndstopCameraShield::setup () {
|
void EndstopCameraShield::setup () {
|
||||||
motor.setup();
|
_motor.setup();
|
||||||
pinMode(emitterOpenPin, OUTPUT);
|
pinMode(_emitterOpenPin, OUTPUT);
|
||||||
pinMode(emitterClosePin, OUTPUT);
|
pinMode(_emitterClosePin, OUTPUT);
|
||||||
|
|
||||||
|
_checkState();
|
||||||
|
_enableMotor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableCloseInterrupt() {
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receiverClosePin), EndstopCameraShield::_handleCloseInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableOpenInterrupt() {
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receiverOpenPin), EndstopCameraShield::_handleOpenInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableCloseEmitter() {
|
||||||
|
digitalWrite(_emitterClosePin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableOpenEmitter() {
|
||||||
|
digitalWrite(_emitterOpenPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableMotor() {
|
||||||
|
_enabled = true;
|
||||||
|
_motor.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableCloseInterrupt() {
|
||||||
|
detachInterrupt(digitalPinToInterrupt(_receiverClosePin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableOpenInterrupt() {
|
||||||
|
detachInterrupt(digitalPinToInterrupt(_receiverOpenPin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableCloseEmitter() {
|
||||||
|
digitalWrite(_emitterClosePin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableOpenEmitter() {
|
||||||
|
digitalWrite(_emitterOpenPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableMotor() {
|
||||||
|
_enabled = false;
|
||||||
|
_motor.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_handleCloseInterrupt() {
|
||||||
|
_isClosed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_handleOpenInterrupt() {
|
||||||
|
_isOpened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_checkState() {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableOpenEmitter();
|
||||||
|
if (digitalRead(_receiverClosePin) == LOW) {
|
||||||
|
_isClosed = true;
|
||||||
|
} else if (digitalRead(_receiverOpenPin) == LOW) {
|
||||||
|
_isOpened = true;
|
||||||
|
}
|
||||||
|
_disableCloseEmitter();
|
||||||
|
_disableOpenEmitter();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::frame() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isClosed = false;
|
||||||
|
_enableMotor();
|
||||||
|
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableCloseInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isClosed) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableCloseInterrupt();
|
||||||
|
_disableCloseEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::toOpen() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isOpened = false;
|
||||||
|
_enableMotor();
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableOpenEmitter();
|
||||||
|
_enableOpenInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isOpened) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableOpenInterrupt();
|
||||||
|
_disableOpenEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::toClosed() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isClosed = false;
|
||||||
|
_enableMotor();
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableCloseInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isClosed) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableCloseInterrupt();
|
||||||
|
_disableCloseEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::setDirection(bool direction) {
|
||||||
|
if (direction != _direction) {
|
||||||
|
_direction = direction;
|
||||||
|
_motor.setDirection(_direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EndstopCameraShield::isOpened() {
|
||||||
|
return _isOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EndstopCameraShield::isClosed() {
|
||||||
|
return _isClosed;
|
||||||
}
|
}
|
|
@ -14,19 +14,42 @@
|
||||||
|
|
||||||
class EndstopCameraShield {
|
class EndstopCameraShield {
|
||||||
private:
|
private:
|
||||||
const uint8_t receiverClosePin = 2;
|
const uint8_t _receiverClosePin = 2;
|
||||||
const uint8_t receiverOpenPin = 3;
|
const uint8_t _receiverOpenPin = 3;
|
||||||
const uint8_t emitterOpenPin = 4;
|
const uint8_t _emitterOpenPin = 4;
|
||||||
const uint8_t emitterClosePin = 5;
|
const uint8_t _emitterClosePin = 5;
|
||||||
|
|
||||||
const uint8_t motorEnablePin = 6;
|
const uint8_t _motorEnablePin = 6;
|
||||||
const uint8_t motorDirectionPin = 7;
|
const uint8_t _motorDirectionPin = 7;
|
||||||
const uint8_t motorPulsePin = 8;
|
const uint8_t _motorPulsePin = 8;
|
||||||
|
|
||||||
volatile uint32_t motorUsPulse = 300;
|
const double _ledAngle = 7.0;
|
||||||
volatile uint8_t motorMicrosteps = 2; //half stepping
|
|
||||||
|
|
||||||
TB6600MotorDriver motor;
|
volatile uint32_t _motorUsPulse = 300;
|
||||||
|
volatile uint8_t _motorMicrosteps = 2; //half stepping
|
||||||
|
volatile double _stepAngle = (double) 360 / ((double) 2 * (double) 200);
|
||||||
|
|
||||||
|
TB6600MotorDriver _motor;
|
||||||
|
|
||||||
|
static volatile bool _direction; //true = forward, false = backward
|
||||||
|
static volatile bool _enabled;
|
||||||
|
static volatile bool _isClosed;
|
||||||
|
static volatile bool _isOpened;
|
||||||
|
|
||||||
|
void _checkState();
|
||||||
|
void _enableCloseInterrupt();
|
||||||
|
void _enableOpenInterrupt();
|
||||||
|
void _enableCloseEmitter();
|
||||||
|
void _enableOpenEmitter();
|
||||||
|
void _enableMotor();
|
||||||
|
void _disableCloseInterrupt();
|
||||||
|
void _disableOpenInterrupt();
|
||||||
|
void _disableCloseEmitter();
|
||||||
|
void _disableOpenEmitter();
|
||||||
|
void _disableMotor();
|
||||||
|
|
||||||
|
static void _handleCloseInterrupt();
|
||||||
|
static void _handleOpenInterrupt();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -34,6 +57,12 @@ class EndstopCameraShield {
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
|
uint32_t frame();
|
||||||
|
uint32_t toOpen();
|
||||||
|
uint32_t toClosed();
|
||||||
|
void setDirection(bool direction);
|
||||||
|
bool isOpened();
|
||||||
|
bool isClosed();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,7 +1,12 @@
|
||||||
#include "EndstopCameraShield.h"
|
#include "EndstopCameraShield.h"
|
||||||
|
|
||||||
EndstopCameraShield::EndstopCameraShield (uint32_t usPulse, uint8_t microsteps) : motorUsPulse(usPulse), motorMicrosteps(microsteps), motor(motorEnablePin, motorDirectionPin, motorPulsePin, motorUsPulse, motorMicrosteps) {
|
volatile bool EndstopCameraShield::_direction = true; //true = forward, false = backward
|
||||||
|
volatile bool EndstopCameraShield::_enabled = false;
|
||||||
|
volatile bool EndstopCameraShield::_isClosed = false;
|
||||||
|
volatile bool EndstopCameraShield::_isOpened = false;
|
||||||
|
|
||||||
|
EndstopCameraShield::EndstopCameraShield (uint32_t usPulse, uint8_t microsteps) : _motorUsPulse(usPulse), _motorMicrosteps(microsteps), _motor(_motorEnablePin, _motorDirectionPin, _motorPulsePin, _motorUsPulse, _motorMicrosteps) {
|
||||||
|
_stepAngle = (double) 360 / ((double) microsteps * (double) 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndstopCameraShield::loop () {
|
void EndstopCameraShield::loop () {
|
||||||
|
@ -9,7 +14,154 @@ void EndstopCameraShield::loop () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndstopCameraShield::setup () {
|
void EndstopCameraShield::setup () {
|
||||||
motor.setup();
|
_motor.setup();
|
||||||
pinMode(emitterOpenPin, OUTPUT);
|
pinMode(_emitterOpenPin, OUTPUT);
|
||||||
pinMode(emitterClosePin, OUTPUT);
|
pinMode(_emitterClosePin, OUTPUT);
|
||||||
|
|
||||||
|
_checkState();
|
||||||
|
_enableMotor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableCloseInterrupt() {
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receiverClosePin), EndstopCameraShield::_handleCloseInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableOpenInterrupt() {
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receiverOpenPin), EndstopCameraShield::_handleOpenInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableCloseEmitter() {
|
||||||
|
digitalWrite(_emitterClosePin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableOpenEmitter() {
|
||||||
|
digitalWrite(_emitterOpenPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableMotor() {
|
||||||
|
_enabled = true;
|
||||||
|
_motor.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableCloseInterrupt() {
|
||||||
|
detachInterrupt(digitalPinToInterrupt(_receiverClosePin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableOpenInterrupt() {
|
||||||
|
detachInterrupt(digitalPinToInterrupt(_receiverOpenPin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableCloseEmitter() {
|
||||||
|
digitalWrite(_emitterClosePin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableOpenEmitter() {
|
||||||
|
digitalWrite(_emitterOpenPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableMotor() {
|
||||||
|
_enabled = false;
|
||||||
|
_motor.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_handleCloseInterrupt() {
|
||||||
|
_isClosed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_handleOpenInterrupt() {
|
||||||
|
_isOpened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_checkState() {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableOpenEmitter();
|
||||||
|
if (digitalRead(_receiverClosePin) == LOW) {
|
||||||
|
_isClosed = true;
|
||||||
|
} else if (digitalRead(_receiverOpenPin) == LOW) {
|
||||||
|
_isOpened = true;
|
||||||
|
}
|
||||||
|
_disableCloseEmitter();
|
||||||
|
_disableOpenEmitter();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::frame() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isClosed = false;
|
||||||
|
_enableMotor();
|
||||||
|
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableCloseInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isClosed) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableCloseInterrupt();
|
||||||
|
_disableCloseEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::toOpen() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isOpened = false;
|
||||||
|
_enableMotor();
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableOpenEmitter();
|
||||||
|
_enableOpenInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isOpened) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableOpenInterrupt();
|
||||||
|
_disableOpenEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::toClosed() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isClosed = false;
|
||||||
|
_enableMotor();
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableCloseInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isClosed) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableCloseInterrupt();
|
||||||
|
_disableCloseEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::setDirection(bool direction) {
|
||||||
|
if (direction != _direction) {
|
||||||
|
_direction = direction;
|
||||||
|
_motor.setDirection(_direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EndstopCameraShield::isOpened() {
|
||||||
|
return _isOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EndstopCameraShield::isClosed() {
|
||||||
|
return _isClosed;
|
||||||
}
|
}
|
|
@ -14,19 +14,42 @@
|
||||||
|
|
||||||
class EndstopCameraShield {
|
class EndstopCameraShield {
|
||||||
private:
|
private:
|
||||||
const uint8_t receiverClosePin = 2;
|
const uint8_t _receiverClosePin = 2;
|
||||||
const uint8_t receiverOpenPin = 3;
|
const uint8_t _receiverOpenPin = 3;
|
||||||
const uint8_t emitterOpenPin = 4;
|
const uint8_t _emitterOpenPin = 4;
|
||||||
const uint8_t emitterClosePin = 5;
|
const uint8_t _emitterClosePin = 5;
|
||||||
|
|
||||||
const uint8_t motorEnablePin = 6;
|
const uint8_t _motorEnablePin = 6;
|
||||||
const uint8_t motorDirectionPin = 7;
|
const uint8_t _motorDirectionPin = 7;
|
||||||
const uint8_t motorPulsePin = 8;
|
const uint8_t _motorPulsePin = 8;
|
||||||
|
|
||||||
volatile uint32_t motorUsPulse = 300;
|
const double _ledAngle = 7.0;
|
||||||
volatile uint8_t motorMicrosteps = 2; //half stepping
|
|
||||||
|
|
||||||
TB6600MotorDriver motor;
|
volatile uint32_t _motorUsPulse = 300;
|
||||||
|
volatile uint8_t _motorMicrosteps = 2; //half stepping
|
||||||
|
volatile double _stepAngle = (double) 360 / ((double) 2 * (double) 200);
|
||||||
|
|
||||||
|
TB6600MotorDriver _motor;
|
||||||
|
|
||||||
|
static volatile bool _direction; //true = forward, false = backward
|
||||||
|
static volatile bool _enabled;
|
||||||
|
static volatile bool _isClosed;
|
||||||
|
static volatile bool _isOpened;
|
||||||
|
|
||||||
|
void _checkState();
|
||||||
|
void _enableCloseInterrupt();
|
||||||
|
void _enableOpenInterrupt();
|
||||||
|
void _enableCloseEmitter();
|
||||||
|
void _enableOpenEmitter();
|
||||||
|
void _enableMotor();
|
||||||
|
void _disableCloseInterrupt();
|
||||||
|
void _disableOpenInterrupt();
|
||||||
|
void _disableCloseEmitter();
|
||||||
|
void _disableOpenEmitter();
|
||||||
|
void _disableMotor();
|
||||||
|
|
||||||
|
static void _handleCloseInterrupt();
|
||||||
|
static void _handleOpenInterrupt();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -34,6 +57,12 @@ class EndstopCameraShield {
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
|
uint32_t frame();
|
||||||
|
uint32_t toOpen();
|
||||||
|
uint32_t toClosed();
|
||||||
|
void setDirection(bool direction);
|
||||||
|
bool isOpened();
|
||||||
|
bool isClosed();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -23,10 +23,10 @@ void TB6600MotorDriver::setup() {
|
||||||
pinMode(_pulsePin, OUTPUT);
|
pinMode(_pulsePin, OUTPUT);
|
||||||
|
|
||||||
digitalWrite(_directionPin, LOW);
|
digitalWrite(_directionPin, LOW);
|
||||||
digitalWrite(_enablePin, HIGH);
|
digitalWrite(_enablePin, _enabled ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TB6600MotorDriver::setDirection(uint8_t direction) {
|
void TB6600MotorDriver::setDirection(bool direction) {
|
||||||
if (direction != _direction) {
|
if (direction != _direction) {
|
||||||
_direction = direction;
|
_direction = direction;
|
||||||
_setDirection();
|
_setDirection();
|
||||||
|
|
|
@ -35,10 +35,9 @@ class TB6600MotorDriver {
|
||||||
TB6600MotorDriver();
|
TB6600MotorDriver();
|
||||||
TB6600MotorDriver(uint8_t enablePin, uint8_t directionPin, uint8_t pulsePin, uint32_t usPulse, uint8_t microsteps);
|
TB6600MotorDriver(uint8_t enablePin, uint8_t directionPin, uint8_t pulsePin, uint32_t usPulse, uint8_t microsteps);
|
||||||
|
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
|
|
||||||
void setDirection(uint8_t direction);
|
void setDirection(bool direction);
|
||||||
void setSpeed(uint16_t rpm);
|
void setSpeed(uint16_t rpm);
|
||||||
|
|
||||||
//full
|
//full
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#include "EndstopCameraShield.h"
|
#include "EndstopCameraShield.h"
|
||||||
|
|
||||||
EndstopCameraShield::EndstopCameraShield (uint32_t usPulse, uint8_t microsteps) : motorUsPulse(usPulse), motorMicrosteps(microsteps), motor(motorEnablePin, motorDirectionPin, motorPulsePin, motorUsPulse, motorMicrosteps) {
|
volatile bool EndstopCameraShield::_direction = true; //true = forward, false = backward
|
||||||
|
volatile bool EndstopCameraShield::_enabled = false;
|
||||||
|
volatile bool EndstopCameraShield::_isClosed = false;
|
||||||
|
volatile bool EndstopCameraShield::_isOpened = false;
|
||||||
|
|
||||||
|
EndstopCameraShield::EndstopCameraShield (uint32_t usPulse, uint8_t microsteps) : _motorUsPulse(usPulse), _motorMicrosteps(microsteps), _motor(_motorEnablePin, _motorDirectionPin, _motorPulsePin, _motorUsPulse, _motorMicrosteps) {
|
||||||
|
_stepAngle = (double) 360 / ((double) microsteps * (double) 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndstopCameraShield::loop () {
|
void EndstopCameraShield::loop () {
|
||||||
|
@ -9,7 +14,154 @@ void EndstopCameraShield::loop () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndstopCameraShield::setup () {
|
void EndstopCameraShield::setup () {
|
||||||
motor.setup();
|
_motor.setup();
|
||||||
pinMode(emitterOpenPin, OUTPUT);
|
pinMode(_emitterOpenPin, OUTPUT);
|
||||||
pinMode(emitterClosePin, OUTPUT);
|
pinMode(_emitterClosePin, OUTPUT);
|
||||||
|
|
||||||
|
_checkState();
|
||||||
|
_enableMotor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableCloseInterrupt() {
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receiverClosePin), EndstopCameraShield::_handleCloseInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableOpenInterrupt() {
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_receiverOpenPin), EndstopCameraShield::_handleOpenInterrupt, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableCloseEmitter() {
|
||||||
|
digitalWrite(_emitterClosePin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableOpenEmitter() {
|
||||||
|
digitalWrite(_emitterOpenPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_enableMotor() {
|
||||||
|
_enabled = true;
|
||||||
|
_motor.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableCloseInterrupt() {
|
||||||
|
detachInterrupt(digitalPinToInterrupt(_receiverClosePin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableOpenInterrupt() {
|
||||||
|
detachInterrupt(digitalPinToInterrupt(_receiverOpenPin));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableCloseEmitter() {
|
||||||
|
digitalWrite(_emitterClosePin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableOpenEmitter() {
|
||||||
|
digitalWrite(_emitterOpenPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_disableMotor() {
|
||||||
|
_enabled = false;
|
||||||
|
_motor.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_handleCloseInterrupt() {
|
||||||
|
_isClosed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_handleOpenInterrupt() {
|
||||||
|
_isOpened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::_checkState() {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableOpenEmitter();
|
||||||
|
if (digitalRead(_receiverClosePin) == LOW) {
|
||||||
|
_isClosed = true;
|
||||||
|
} else if (digitalRead(_receiverOpenPin) == LOW) {
|
||||||
|
_isOpened = true;
|
||||||
|
}
|
||||||
|
_disableCloseEmitter();
|
||||||
|
_disableOpenEmitter();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::frame() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isClosed = false;
|
||||||
|
_enableMotor();
|
||||||
|
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableCloseInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isClosed) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableCloseInterrupt();
|
||||||
|
_disableCloseEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::toOpen() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isOpened = false;
|
||||||
|
_enableMotor();
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableOpenEmitter();
|
||||||
|
_enableOpenInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isOpened) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableOpenInterrupt();
|
||||||
|
_disableOpenEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t EndstopCameraShield::toClosed() {
|
||||||
|
bool primed = false;
|
||||||
|
bool running = true;
|
||||||
|
uint32_t i = 0;
|
||||||
|
_isClosed = false;
|
||||||
|
_enableMotor();
|
||||||
|
while (running) {
|
||||||
|
if (!primed && (double) i * _stepAngle > _ledAngle) {
|
||||||
|
_enableCloseEmitter();
|
||||||
|
_enableCloseInterrupt();
|
||||||
|
primed = true;
|
||||||
|
}
|
||||||
|
if (primed && _isClosed) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_disableCloseInterrupt();
|
||||||
|
_disableCloseEmitter();
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndstopCameraShield::setDirection(bool direction) {
|
||||||
|
if (direction != _direction) {
|
||||||
|
_direction = direction;
|
||||||
|
_motor.setDirection(_direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EndstopCameraShield::isOpened() {
|
||||||
|
return _isOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EndstopCameraShield::isClosed() {
|
||||||
|
return _isClosed;
|
||||||
}
|
}
|
|
@ -14,19 +14,42 @@
|
||||||
|
|
||||||
class EndstopCameraShield {
|
class EndstopCameraShield {
|
||||||
private:
|
private:
|
||||||
const uint8_t receiverClosePin = 2;
|
const uint8_t _receiverClosePin = 2;
|
||||||
const uint8_t receiverOpenPin = 3;
|
const uint8_t _receiverOpenPin = 3;
|
||||||
const uint8_t emitterOpenPin = 4;
|
const uint8_t _emitterOpenPin = 4;
|
||||||
const uint8_t emitterClosePin = 5;
|
const uint8_t _emitterClosePin = 5;
|
||||||
|
|
||||||
const uint8_t motorEnablePin = 6;
|
const uint8_t _motorEnablePin = 6;
|
||||||
const uint8_t motorDirectionPin = 7;
|
const uint8_t _motorDirectionPin = 7;
|
||||||
const uint8_t motorPulsePin = 8;
|
const uint8_t _motorPulsePin = 8;
|
||||||
|
|
||||||
volatile uint32_t motorUsPulse = 300;
|
const double _ledAngle = 7.0;
|
||||||
volatile uint8_t motorMicrosteps = 2; //half stepping
|
|
||||||
|
|
||||||
TB6600MotorDriver motor;
|
volatile uint32_t _motorUsPulse = 300;
|
||||||
|
volatile uint8_t _motorMicrosteps = 2; //half stepping
|
||||||
|
volatile double _stepAngle = (double) 360 / ((double) 2 * (double) 200);
|
||||||
|
|
||||||
|
TB6600MotorDriver _motor;
|
||||||
|
|
||||||
|
static volatile bool _direction; //true = forward, false = backward
|
||||||
|
static volatile bool _enabled;
|
||||||
|
static volatile bool _isClosed;
|
||||||
|
static volatile bool _isOpened;
|
||||||
|
|
||||||
|
void _checkState();
|
||||||
|
void _enableCloseInterrupt();
|
||||||
|
void _enableOpenInterrupt();
|
||||||
|
void _enableCloseEmitter();
|
||||||
|
void _enableOpenEmitter();
|
||||||
|
void _enableMotor();
|
||||||
|
void _disableCloseInterrupt();
|
||||||
|
void _disableOpenInterrupt();
|
||||||
|
void _disableCloseEmitter();
|
||||||
|
void _disableOpenEmitter();
|
||||||
|
void _disableMotor();
|
||||||
|
|
||||||
|
static void _handleCloseInterrupt();
|
||||||
|
static void _handleOpenInterrupt();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -34,6 +57,12 @@ class EndstopCameraShield {
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
|
uint32_t frame();
|
||||||
|
uint32_t toOpen();
|
||||||
|
uint32_t toClosed();
|
||||||
|
void setDirection(bool direction);
|
||||||
|
bool isOpened();
|
||||||
|
bool isClosed();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -23,10 +23,10 @@ void TB6600MotorDriver::setup() {
|
||||||
pinMode(_pulsePin, OUTPUT);
|
pinMode(_pulsePin, OUTPUT);
|
||||||
|
|
||||||
digitalWrite(_directionPin, LOW);
|
digitalWrite(_directionPin, LOW);
|
||||||
digitalWrite(_enablePin, HIGH);
|
digitalWrite(_enablePin, _enabled ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TB6600MotorDriver::setDirection(uint8_t direction) {
|
void TB6600MotorDriver::setDirection(bool direction) {
|
||||||
if (direction != _direction) {
|
if (direction != _direction) {
|
||||||
_direction = direction;
|
_direction = direction;
|
||||||
_setDirection();
|
_setDirection();
|
||||||
|
|
|
@ -35,10 +35,9 @@ class TB6600MotorDriver {
|
||||||
TB6600MotorDriver();
|
TB6600MotorDriver();
|
||||||
TB6600MotorDriver(uint8_t enablePin, uint8_t directionPin, uint8_t pulsePin, uint32_t usPulse, uint8_t microsteps);
|
TB6600MotorDriver(uint8_t enablePin, uint8_t directionPin, uint8_t pulsePin, uint32_t usPulse, uint8_t microsteps);
|
||||||
|
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
|
|
||||||
void setDirection(uint8_t direction);
|
void setDirection(bool direction);
|
||||||
void setSpeed(uint16_t rpm);
|
void setSpeed(uint16_t rpm);
|
||||||
|
|
||||||
//full
|
//full
|
||||||
|
|
|
@ -1,15 +1,121 @@
|
||||||
#include "EndstopCameraShield.h"
|
#include "EndstopCameraShield.h"
|
||||||
#include "McopySerial.h"
|
#include "McopySerial.h"
|
||||||
|
|
||||||
|
const bool DEBUG = false;
|
||||||
|
|
||||||
|
const uint8_t enableButtonPin = 9;
|
||||||
|
const uint8_t enableButtonPin = 10;
|
||||||
|
const uint8_t enableButtonPin = 11;
|
||||||
|
const uint8_t enableButtonPin = 12;
|
||||||
|
const uint8_t LEDPin = 13;
|
||||||
|
|
||||||
const uint32_t usPulse = 300;
|
const uint32_t usPulse = 300;
|
||||||
const uint8_t microsteps = 2;
|
const uint8_t microsteps = 2;
|
||||||
|
volatile char cmdChar = 'z';
|
||||||
|
volatile long now;
|
||||||
|
|
||||||
|
volatile long exposureAvg = -1; //pre-fill
|
||||||
|
volatile String exposureString;
|
||||||
|
volatile long exposureTarget = -1;
|
||||||
|
|
||||||
|
volatile bool direction = true;
|
||||||
|
volatile bool directionSwitch = true;
|
||||||
|
|
||||||
EndstopCameraShield cam(usPulse, microsteps);
|
EndstopCameraShield cam(usPulse, microsteps);
|
||||||
|
McopySerial mc;
|
||||||
|
|
||||||
void setup () {
|
void setup () {
|
||||||
|
mc.begin(mc.CAMERA_IDENTIFIER);
|
||||||
|
mc.debug(DEBUG);
|
||||||
cam.setup();
|
cam.setup();
|
||||||
|
if (cam.isOpened()) {
|
||||||
|
mc.log("Camera is OPENED");
|
||||||
|
} else if (cam.isClosed()) {
|
||||||
|
mc.log("Camera is CLOSED");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop () {
|
void loop () {
|
||||||
|
now = millis();
|
||||||
|
cmdChar = mc.loop();
|
||||||
|
cmd(cmdChar);
|
||||||
cam.loop();
|
cam.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmd (char val) {
|
||||||
|
if (val == mc.CAMERA_FORWARD) {
|
||||||
|
camera_direction(true);
|
||||||
|
} else if (val == mc.CAMERA_BACKWARD) {
|
||||||
|
camera_direction(false);
|
||||||
|
} else if (val == mc.CAMERA) {
|
||||||
|
camera();
|
||||||
|
} else if (val == mc.CAMERA_EXPOSURE) {
|
||||||
|
exposure();
|
||||||
|
} else if (val == mc.STATE) {
|
||||||
|
state();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void exposure () {
|
||||||
|
exposureString = mc.getString();
|
||||||
|
parseExposureString();
|
||||||
|
cameraFrame = exposureTarget;
|
||||||
|
mc.confirm(mc.CAMERA_EXPOSURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parseExposureString () {
|
||||||
|
exposureTarget = exposureString.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
void camera_direction (boolean state) {
|
||||||
|
direction = state;
|
||||||
|
cam.setDirection(direction);
|
||||||
|
if (state) {
|
||||||
|
mc.confirm(mc.CAMERA_FORWARD);
|
||||||
|
mc.log("camera_direction(true)");
|
||||||
|
} else {
|
||||||
|
mc.confirm(mc.CAMERA_BACKWARD);
|
||||||
|
mc.log("camera_direction(false)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void camera () {
|
||||||
|
long start, half, pause;
|
||||||
|
if (exposureTarget > -1) {
|
||||||
|
half = exposureAvg / 2; //assume a 180 shutter
|
||||||
|
pause = exposureTarget - half;
|
||||||
|
if (pause < exposureAvg) {
|
||||||
|
cam.frame();
|
||||||
|
} else {
|
||||||
|
cam.toOpen();
|
||||||
|
delay(pause);
|
||||||
|
cam.toClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else{
|
||||||
|
millis();
|
||||||
|
cam.frame();
|
||||||
|
updateAvg(millis() - start);
|
||||||
|
}
|
||||||
|
mc.confirm(mc.CAMERA);
|
||||||
|
}
|
||||||
|
|
||||||
|
void state () {
|
||||||
|
String stateString = String(mc.STATE);
|
||||||
|
stateString += String(mc.CAMERA_EXPOSURE);
|
||||||
|
if (exposureTarget > -1) {
|
||||||
|
stateString += String(exposureTarget);
|
||||||
|
} else {
|
||||||
|
stateString += String(exposureAvg);
|
||||||
|
}
|
||||||
|
stateString += String(mc.STATE);
|
||||||
|
mc.sendString(stateString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateAvg (long value) {
|
||||||
|
exposureAvg = round((exposureAvg + value) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button logic
|
||||||
|
**/
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "mcopy",
|
"name": "mcopy",
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "mcopy",
|
"name": "mcopy",
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"alert": "file:app/lib/alert",
|
"alert": "file:app/lib/alert",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "mcopy",
|
"name": "mcopy",
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"description": "Small gauge film optical printer platform",
|
"description": "Small gauge film optical printer platform",
|
||||||
"main": "build.js",
|
"main": "build.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "1.8.120",
|
"version": "1.8.121",
|
||||||
"ext_port": 1111,
|
"ext_port": 1111,
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"mcopy": {
|
"mcopy": {
|
||||||
|
|
Loading…
Reference in New Issue