Merge in 9 months of work on capper branch #71

Merged
mattmcw merged 95 commits from capper into main 2023-02-19 05:28:46 +00:00
1 changed files with 42 additions and 18 deletions
Showing only changes of commit 98f2c7a24a - Show all commits

View File

@ -16,8 +16,9 @@ class ArriSMotor {
void Start (boolean dir) { void Start (boolean dir) {
startTime = millis(); startTime = millis();
rotationTime = startTime;
direction = dir; direction = dir;
rotations = 0;
Run(direction, speed); Run(direction, speed);
running = true; running = true;
@ -26,49 +27,67 @@ class ArriSMotor {
void Run (boolean dir, int speed) { void Run (boolean dir, int speed) {
if (dir) { if (dir) {
analogWrite(pinPositive, speed);
analogWrite(pinNegative, 0);
} else {
analogWrite(pinPositive, 0); analogWrite(pinPositive, 0);
analogWrite(pinNegative, speed); analogWrite(pinNegative, speed);
} else {
analogWrite(pinPositive, speed);
analogWrite(pinNegative, 0);
} }
} }
void CheckMicroswitch () { void CheckMicroswitch () {
int value = digitalRead(pinMicroswitch); int value = digitalRead(pinMicroswitch);
if (value == 1) { if (value == 1) {
if (running && !primed && millis() - startTime > primeTime) { if (running && !primed && millis() - rotationTime > primeTime) {
primed = true; primed = true;
} }
} }
if (value == 0) { if (value == 0) {
if (running && primed && millis() - startTime > minTime) { if (running && primed && millis() - rotationTime > minTime) {
Stop(); if (rotations < rotationsPer - 1) {
rotations++;
primed = false;
rotationTime = millis();
} else {
Stop();
}
} }
} }
}; };
private: private:
int pinPositive = 5; const int pinPositive = 5;
int pinNegative = 6; const int pinNegative = 6;
int pinMicroswitch = 7; const int pinMicroswitch = 7;
int startTime = 0; const int rotationsPer = 3;
int primeTime = 100; volatile int rotations = 0;
int minTime = 200;
volatile long startTime = 0;
volatile long rotationTime = 0;
const int primeTime = 100;
const int minTime = 200;
void Stop () { void Stop () {
int val = 1; int val = 1;
digitalWrite(pinPositive, LOW); digitalWrite(pinPositive, LOW);
digitalWrite(pinNegative, LOW); digitalWrite(pinNegative, LOW);
Run(!direction, 55); EvaluateTiming();
delay(50); Run(!direction, 40);
long c = millis();
while (val == 1) {
delay(4);
val = digitalRead(pinMicroswitch);
}
Serial.print("Correction: ");
Serial.print(millis() - c);
Serial.println("ms");
digitalWrite(pinPositive, LOW); digitalWrite(pinPositive, LOW);
digitalWrite(pinNegative, LOW); digitalWrite(pinNegative, LOW);
running = false; running = false;
primed = false; primed = false;
EvaluateTiming();
} }
void EvaluateTiming () { void EvaluateTiming () {
@ -104,11 +123,16 @@ void setup() {
} }
boolean d = false; boolean d = false;
int count = 0;
void loop() { void loop() {
if (!motor.running) { if (!motor.running) {
delay(3000); delay(5000);
motor.Start(d); motor.Start(d);
d = !d; count++;
if (count > 9) {
d = !d;
count = 0;
}
} }
motor.CheckMicroswitch(); motor.CheckMicroswitch();
if (!motor.primed) { if (!motor.primed) {