Update the esp32 poc to reflect what it is.

This commit is contained in:
Matt McWilliams 2024-01-21 22:27:40 -05:00
parent 7e03fadb9f
commit 5282fbec1c
2 changed files with 12 additions and 12 deletions

View File

@ -33,7 +33,7 @@ const float ratio = 62.0 / 1.0;
const int maxPulses = (int) round((float) ppr * ratio); const int maxPulses = (int) round((float) ppr * ratio);
const int speed = 230; const int speed = 230;
const int framesPerRotation = 18; const int framesPerRotation = 18;
const int pulsesPerFrame = (int) round((float) maxPulses / (float) framesPerRotation); const float pulsesPerFrame = (float) maxPulses / (float) framesPerRotation;
volatile long start = 0; volatile long start = 0;
volatile bool done = false; volatile bool done = false;
volatile bool stop = false; volatile bool stop = false;
@ -84,19 +84,19 @@ void loop() {
pos = posi; pos = posi;
} }
if (pos != lastRotationPosition && abs(pos) % maxPulses == 0) { rotations = (int) floor((float) pos / (float) maxPulses);
lastRotationPosition = pos; if (pos != lastRotationPosition) {
rotations++; lastRotationPosition = rotations;
frames = rotations * framesPerRotation; frames = rotations * framesPerRotation;
} }
if (pos != lastFramePosition && abs(pos) % pulsesPerFrame == 0) { frames = (int) floor((float) pos / pulsesPerFrame);
lastFramePosition = pos; if (frames != lastFramePosition) {
frames++; lastFramePosition = frames;
Serial.print("Frames: "); Serial.print("Frames: ");
Serial.print(frames); Serial.println(frames);
Serial.print("@"); //Serial.print("@");
Serial.println(String(pos)); //Serial.println(pos);
} }
if (abs(pos) >= maxPulses * maxRotations) { if (abs(pos) >= maxPulses * maxRotations) {
@ -111,8 +111,8 @@ void loop() {
} else if ((stop || millis() - start >= maxTime) && !done) { } else if ((stop || millis() - start >= maxTime) && !done) {
digitalWrite(MOTORA, LOW); digitalWrite(MOTORA, LOW);
digitalWrite(MOTORB, LOW); digitalWrite(MOTORB, LOW);
Serial.print("Final: "); //Serial.print("Final: ");
Serial.println(pos); //Serial.println(pos);
Serial.print("Time: "); Serial.print("Time: ");
Serial.println(millis() - start); Serial.println(millis() - start);
rpm = calculateRPM(millis() - start) * (float) (rotations + 1); rpm = calculateRPM(millis() - start) * (float) (rotations + 1);