Times work well on hardware for now. Need to connect it to projector

This commit is contained in:
Matt McWilliams 2023-02-13 20:49:49 -05:00
parent 609f604e4c
commit 724da68b0e
1 changed files with 19 additions and 11 deletions

View File

@ -22,8 +22,9 @@
#define Fbutton 3 #define Fbutton 3
#define Bbutton 4 #define Bbutton 4
const int frameTime = 40; //ms const int frameTime = 200; //ms
const int frameSpeed = 255; const int pullSpeed = 255;
const int pushSpeed = 125;
const int buttonPress = 100; //ms const int buttonPress = 100; //ms
/** /**
@ -138,8 +139,11 @@ void forward (int source) {
softSerial.write(Fcmd); softSerial.write(Fcmd);
} }
Ftime = timer; Ftime = timer;
set_speed(Fmotor, frameSpeed); set_speed(Fmotor, pullSpeed);
set_speed(Bmotor, pushSpeed);
Frunning = true;
clockwise(Fmotor); clockwise(Fmotor);
clockwise(Bmotor);
} }
void backward (int source) { void backward (int source) {
@ -150,16 +154,21 @@ void backward (int source) {
softSerial.write(Bcmd); softSerial.write(Bcmd);
} }
Btime = timer; Btime = timer;
set_speed(Bmotor, frameSpeed); set_speed(Bmotor, pullSpeed);
set_speed(Fmotor, pushSpeed);
Brunning = true;
counter_clockwise(Bmotor); counter_clockwise(Bmotor);
counter_clockwise(Fmotor);
} }
void monitor () { void monitor () {
if (Frunning && timer - Ftime >= frameTime) { if (Frunning && timer - Ftime >= frameTime) {
stop(Fmotor); stop(Fmotor);
stop(Bmotor);
} }
if (Brunning && timer - Btime >= frameTime) { if (Brunning && timer - Btime >= frameTime) {
stop(Bmotor); stop(Bmotor);
stop(Fmotor);
} }
} }
@ -176,6 +185,7 @@ void set_speed (int motor, int val){
} }
} }
/*
void clockwise_fade (int motor, int startSpeed, int stopSpeed, int ms) { void clockwise_fade (int motor, int startSpeed, int stopSpeed, int ms) {
int steps = ceil((float) ms / (float) abs(stopSpeed - startSpeed)); int steps = ceil((float) ms / (float) abs(stopSpeed - startSpeed));
int stepMs = round((float) ms / (float) steps); int stepMs = round((float) ms / (float) steps);
@ -231,16 +241,15 @@ void counter_clockwise_fade (int motor, int startSpeed, int stopSpeed, int ms) {
Bspeed = stopSpeed; Bspeed = stopSpeed;
} }
} }
*/
void clockwise (int motor){ void clockwise (int motor){
if (motor == Fmotor) { if (motor == Fmotor) {
analogWrite(Fpos, Fspeed); analogWrite(Fpos, Fspeed);
analogWrite(Fneg, 0); analogWrite(Fneg, 0);
Frunning = true; }
} else if (motor == Bmotor) { if (motor == Bmotor) {
analogWrite(Bpos, Bspeed); analogWrite(Bpos, Bspeed);
analogWrite(Bneg, 0); analogWrite(Bneg, 0);
Brunning = true;
} }
} }
@ -248,11 +257,10 @@ void counter_clockwise (int motor){
if (motor == Fmotor) { if (motor == Fmotor) {
analogWrite(Fpos, 0); analogWrite(Fpos, 0);
analogWrite(Fneg, Fspeed); analogWrite(Fneg, Fspeed);
Frunning = true; }
} else if (motor == Bmotor) { if (motor == Bmotor) {
analogWrite(Bpos, 0); analogWrite(Bpos, 0);
analogWrite(Bneg, Bspeed); analogWrite(Bneg, Bspeed);
Brunning = true;
} }
} }