Pausing work on arri_s_DC firmware because hardware is less than ideal. Too much play in the motor position to trust right now. Steppers better approach.

This commit is contained in:
Matt McWilliams 2022-10-28 11:28:30 -04:00
parent 787e6ed06e
commit 98f2c7a24a
1 changed files with 42 additions and 18 deletions

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) {
if (rotations < rotationsPer - 1) {
rotations++;
primed = false;
rotationTime = millis();
} else {
Stop(); 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);
count++;
if (count > 9) {
d = !d; d = !d;
count = 0;
}
} }
motor.CheckMicroswitch(); motor.CheckMicroswitch();
if (!motor.primed) { if (!motor.primed) {