From 290d8ca5be1dcf1ac0667b657a71a7c26135ef7c Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Sun, 12 Nov 2023 18:57:07 -0600 Subject: [PATCH 1/9] added shooting object --- src/main.cpp | 14 ++++++++++++-- src/shooting.cpp | 29 +++++++++++++++++++++++++++++ src/shooting.h | 26 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/shooting.cpp create mode 100644 src/shooting.h diff --git a/src/main.cpp b/src/main.cpp index 31a5c47..58f156d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include #include "motorControl.h" +#include "shooting.h" motorControl controller; +shooting shooter stepStruct reading; //function prototype: @@ -10,6 +12,7 @@ void serialCommunicate(); void setup() { Serial.begin(115200); controller.setup(); + shooter.setup(); while (!Serial) { ; // Wait for the serial port to be ready } @@ -48,7 +51,7 @@ void serialCommunicate(){ String inputString = Serial.readStringUntil('\n'); // Read until newline // Separate the comma-separated values - int values[4]; + int values[5]; int currentIndex = 0; int commaIndex = inputString.indexOf(','); while (commaIndex != -1) { @@ -59,12 +62,19 @@ void serialCommunicate(){ } // Handle the last value - if (currentIndex < 4) { + if (currentIndex < 5) { values[currentIndex] = inputString.toInt(); } //write the values to the arduino controller.updateMotors(values[0], values[1], values[2], values[3]); + + //loading and shooting values write to arduino + values[4]; + if(values[4] == 1){ + shooter.shoot(); + values[4] = 0; + } } //read from the motor reading = controller.readSteppers(); diff --git a/src/shooting.cpp b/src/shooting.cpp new file mode 100644 index 0000000..f6576bc --- /dev/null +++ b/src/shooting.cpp @@ -0,0 +1,29 @@ +#include "shooting.h" + +shooting::shooting() +{ + +} + +shooting::~shooting() { + +} + +void shooting::setup() { + Stepper myStepper(200, IN1, IN2, IN3, IN4) + myStepper.setSpeed(25); + pinMode(solenoidPin, OUTPUT); +} + + +void shooting::shoot(){ + //Shooting Code, may need to adjust delays + digitalWrite(solenoidPin, HIGH); + myStepper.step(-125); //Switch Solenoid ON + delay(100); + digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF + //Reload code + //need to verify rotation duration/trial&error? + delay(300); + myStepper.step(125); +} \ No newline at end of file diff --git a/src/shooting.h b/src/shooting.h new file mode 100644 index 0000000..6c3c2bd --- /dev/null +++ b/src/shooting.h @@ -0,0 +1,26 @@ +#ifndef shooting_h +#define shooting_h + +#include +#include + + +class shooting { +public: + shooting(); //constructor + virtual ~shooting(); //virtual destructor + void setup(); + void shoot(); + +protected: + //solenoid pin + int Solenoid = ;//pin value + + //motors + int IN1 = ;//1 + int IN2 = ;//2 + int IN3 = ;//3 + int IN4 = ;//4 +}; + +#endif \ No newline at end of file From 2f868904ac12619364c6dd747a70fa0175964213 Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Sun, 12 Nov 2023 19:19:06 -0600 Subject: [PATCH 2/9] global variable to ensure only fire one puck at a time --- src/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 58f156d..5e43589 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,9 @@ motorControl controller; shooting shooter stepStruct reading; +//previous count for shooting to ensure fire one puck at a time +int prevCount = 0; + //function prototype: void serialCommunicate(); @@ -49,7 +52,7 @@ void loop() { void serialCommunicate(){ if (Serial.available() > 0) { String inputString = Serial.readStringUntil('\n'); // Read until newline - + // Separate the comma-separated values int values[5]; int currentIndex = 0; @@ -70,10 +73,9 @@ void serialCommunicate(){ controller.updateMotors(values[0], values[1], values[2], values[3]); //loading and shooting values write to arduino - values[4]; - if(values[4] == 1){ + if(values[4] > prevCount){ shooter.shoot(); - values[4] = 0; + prevCount = values[4] = 0; } } //read from the motor From b0b749bd6cb37589dce68090ec46e489e74747d3 Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Sun, 12 Nov 2023 23:14:51 -0600 Subject: [PATCH 3/9] myStepper instance is accesible to all functions within class --- src/shooting.cpp | 6 ++---- src/shooting.h | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shooting.cpp b/src/shooting.cpp index f6576bc..d9c5c9c 100644 --- a/src/shooting.cpp +++ b/src/shooting.cpp @@ -1,8 +1,7 @@ #include "shooting.h" -shooting::shooting() -{ - +shooting::shooting() :myStepper(200, IN1, IN2, IN3, IN4){ +// Constructor initializer list to initialize myStepper } shooting::~shooting() { @@ -10,7 +9,6 @@ shooting::~shooting() { } void shooting::setup() { - Stepper myStepper(200, IN1, IN2, IN3, IN4) myStepper.setSpeed(25); pinMode(solenoidPin, OUTPUT); } diff --git a/src/shooting.h b/src/shooting.h index 6c3c2bd..2d917ed 100644 --- a/src/shooting.h +++ b/src/shooting.h @@ -21,6 +21,8 @@ class shooting { int IN2 = ;//2 int IN3 = ;//3 int IN4 = ;//4 + + Stepper myStepper;// Declare Stepper instance as a member variable }; #endif \ No newline at end of file From 3ab49f7a97590a4bc99185e24ceb2281debb92a6 Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Mon, 13 Nov 2023 19:40:46 -0600 Subject: [PATCH 4/9] Update shooting.h --- src/shooting.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shooting.h b/src/shooting.h index 2d917ed..e4f6ba0 100644 --- a/src/shooting.h +++ b/src/shooting.h @@ -14,13 +14,13 @@ class shooting { protected: //solenoid pin - int Solenoid = ;//pin value + int Solenoid = 50;//pin value //motors - int IN1 = ;//1 - int IN2 = ;//2 - int IN3 = ;//3 - int IN4 = ;//4 + int IN1 = 42;//1 + int IN2 = 44;//2 + int IN3 = 46;//3 + int IN4 = 48;//4 Stepper myStepper;// Declare Stepper instance as a member variable }; From 687af7b583b35b2d2c8349a4db1b9cdbd3f577b4 Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Mon, 13 Nov 2023 19:43:18 -0600 Subject: [PATCH 5/9] Update main.cpp --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5e43589..2b04a20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,7 @@ void serialCommunicate(){ //loading and shooting values write to arduino if(values[4] > prevCount){ shooter.shoot(); - prevCount = values[4] = 0; + prevCount = values[4]; } } //read from the motor From 604058dcbc4448fa00459db11694f284b7205319 Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Mon, 13 Nov 2023 19:54:03 -0600 Subject: [PATCH 6/9] minor errors fixed --- platformio.ini | 1 + src/main.cpp | 2 +- src/shooting.cpp | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7216e60..16b65bf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,5 +16,6 @@ lib_deps = paulstoffregen/Encoder@^1.4.2 andrealombardo/L298N@^2.0.3 waspinator/AccelStepper@^1.64 + stepper upload_port = COM4 monitor_speed = 115200 diff --git a/src/main.cpp b/src/main.cpp index 2b04a20..a5635ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include "shooting.h" motorControl controller; -shooting shooter +shooting shooter; stepStruct reading; //previous count for shooting to ensure fire one puck at a time diff --git a/src/shooting.cpp b/src/shooting.cpp index d9c5c9c..b8a8ac1 100644 --- a/src/shooting.cpp +++ b/src/shooting.cpp @@ -10,16 +10,16 @@ shooting::~shooting() { void shooting::setup() { myStepper.setSpeed(25); - pinMode(solenoidPin, OUTPUT); + pinMode(Solenoid, OUTPUT); } void shooting::shoot(){ //Shooting Code, may need to adjust delays - digitalWrite(solenoidPin, HIGH); + digitalWrite(Solenoid, HIGH); myStepper.step(-125); //Switch Solenoid ON delay(100); - digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF + digitalWrite(Solenoid, LOW); //Switch Solenoid OFF //Reload code //need to verify rotation duration/trial&error? delay(300); From 9bb4e9f63f8a615a6b26e0d68f7904b774aaefe7 Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Mon, 13 Nov 2023 20:11:42 -0600 Subject: [PATCH 7/9] removed blocking delay code --- src/shooting.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shooting.cpp b/src/shooting.cpp index b8a8ac1..fa185a6 100644 --- a/src/shooting.cpp +++ b/src/shooting.cpp @@ -18,10 +18,10 @@ void shooting::shoot(){ //Shooting Code, may need to adjust delays digitalWrite(Solenoid, HIGH); myStepper.step(-125); //Switch Solenoid ON - delay(100); + //delay(100); digitalWrite(Solenoid, LOW); //Switch Solenoid OFF //Reload code //need to verify rotation duration/trial&error? - delay(300); + //delay(300); myStepper.step(125); } \ No newline at end of file From d1d19476bdc99782a1356cb604228ba67a77bc8a Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Mon, 13 Nov 2023 20:23:57 -0600 Subject: [PATCH 8/9] timing changes --- src/shooting.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/shooting.cpp b/src/shooting.cpp index fa185a6..739acc8 100644 --- a/src/shooting.cpp +++ b/src/shooting.cpp @@ -17,11 +17,13 @@ void shooting::setup() { void shooting::shoot(){ //Shooting Code, may need to adjust delays digitalWrite(Solenoid, HIGH); - myStepper.step(-125); //Switch Solenoid ON + delay(100); + digitalWrite(Solenoid, LOW); + myStepper.step(-130); //Switch Solenoid ON //delay(100); - digitalWrite(Solenoid, LOW); //Switch Solenoid OFF + //Switch Solenoid OFF //Reload code //need to verify rotation duration/trial&error? //delay(300); - myStepper.step(125); + myStepper.step(130); } \ No newline at end of file From ab1b2dff2eae0c79bfe5f91aa6a97ac49ca62e8d Mon Sep 17 00:00:00 2001 From: ycleeag267 Date: Mon, 13 Nov 2023 22:58:05 -0600 Subject: [PATCH 9/9] sends shooting command recieved value to rpi --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a5635ff..2d6f6c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,6 +87,8 @@ void serialCommunicate(){ Serial.print(reading.step3); Serial.print(','); Serial.print(reading.step4); + Serial.print(','); + Serial.print(prevCount); Serial.println(); //move steps