I’ll be using an Arduino UNO to set up the motors on a 1.1 minute cycle to correspond to the max time Skanect runs a scan. The turntable will simply rotate for the duration. The Kinect scanner will begin at center then rise until the endstop is activated then reverse direction to the bottom until the endstop is again activated. Ideally the turntable and scanner will return to their starting position to minimize any manual resetting of the gear between scans.
The initial arduino code is below. No timer has been implemented as of yet. This is working on the breadboard and I’m slowly adding the external motor control circuitry.
Open Body Skanner controller
/*The circuit:
* Skanner motor control attached to pin 6
* Skanner direction control attached to pin 7
* Turntable motor control attached to pin 5
* Power button attached from pin 2 to +5V
* 10K resistor attached from pin 2 to ground
* 2 endstops attached in series from pin 3 to +5V
* 10K resistor attached from pin 3 to ground
*/
// Assign pin numbers, using PWM pins for possible use of PWM for speed control
const int powerPin = 0; // the start/stop pin 10k resistor to ground. (pin D2)
const int endStopPin = 1; // the endstop pin 10k resistor to ground. (pin D3)
const int motorPin = 6; // the scanner motor pin
const int dirPin = 7; // the scanner direction pin
const int revolvePin = 5; // the platform motor pin
const unsigned int DEBOUNCE_TIME = 500; // Using 500 to ensure endstop has time to disengage after dir change.
const unsigned int RUNNING_TIME = 60000; // Total running time for each cycle (not implemented)
// Variables
int running = 0; // 0 - off; 1 - on; To start and stop the motor
int dir = 0; // 0 - up; 1 - down; To change direction
long startTime = 0; // time the cycle began.
int actionPending = 0; // 0 - no; 1 - yes: Need to handle the interrupt
long lastStateChange = 0; // Last time the button was pressed
long lastEndStopHit = 0; // Last time the endstop was hit
void setup() {
attachInterrupt(powerPin, stateChange, RISING);
attachInterrupt(endStopPin, dirChange, RISING); // must be rising else no dir change
pinMode(motorPin, OUTPUT); // toggle the pin for motor direction wind the spool
pinMode(dirPin, OUTPUT); // Used to control motor direction.
pinMode(revolvePin, OUTPUT);// Used to control the platform revolution
}
void reverse() { //endstop hit
if (dir == 0) {
// Set pins so motor goes down
digitalWrite(dirPin, HIGH);
dir = 1;
} else {
// Set pins so motor goes up
digitalWrite(dirPin, LOW);
dir = 0;
}
}
void toggleMotion() { //Start up or shut down the motors
if (running == 0) {
// code to start moving the motors
digitalWrite(motorPin, HIGH);
digitalWrite(revolvePin, HIGH);
running = 1;
} else {
// code to stop moving the motors
digitalWrite(motorPin, LOW);
digitalWrite(revolvePin, LOW);
running = 0;
}
}
void endCycle() { // reset to default settings (timer not implemented yet)
digitalWrite(motorPin, LOW);
digitalWrite(revolvePin, LOW);
digitalWrite(dirPin, LOW);
running = 0;
dir = 0;
}
void loop() {
if (actionPending == 1) { // Toggle on/pause
toggleMotion();
actionPending = 0;
}
if (actionPending == 2) { // Toggle direction
reverse();
actionPending = 0;
}
}
void stateChange() { // start/pause motion
long currentTime = millis();
if(currentTime - lastStateChange > DEBOUNCE_TIME) {
actionPending = 1;
}
lastStateChange = currentTime;
}
void dirChange() { // endstop hit, change direction
long currentTime = millis();
if(currentTime - lastEndStopHit > DEBOUNCE_TIME) {
actionPending = 2;
}
lastEndStopHit = currentTime;
}