From dd55bd49bee061be9176783cc04ee2227e734fd4 Mon Sep 17 00:00:00 2001 From: KevinTEngineering <89664867+KevinTEngineering@users.noreply.github.com> Date: Thu, 17 Mar 2022 14:03:13 -0700 Subject: [PATCH 1/4] Add files via upload Arduino code for pumps --- Pump_Arduino.ino | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Pump_Arduino.ino diff --git a/Pump_Arduino.ino b/Pump_Arduino.ino new file mode 100644 index 0000000..a58fdb3 --- /dev/null +++ b/Pump_Arduino.ino @@ -0,0 +1,174 @@ +/* + THIS IS FOR TESTING BOTH BALL PUMPS +*/ + +#include "SpeedyStepper.h" + +SpeedyStepper BallPump1; +SpeedyStepper BallPump2; + +const byte BALL_PUMP_SELECTOR_POT = A7; // POT + +const long BALL_PUMP_1_STEPS_PER_REV = 200 * 5; +const long BALL_PUMP_1_MICROSTEPPING = 8; +const long BALL_PUMP_1_STEPS_PER_REV_INCLUDING_MICROSTEPPING = (BALL_PUMP_1_STEPS_PER_REV * BALL_PUMP_1_MICROSTEPPING); +const long BALL_PUMP_1_SPEED_IN_SPS = 750; // 5000; // 750; +const long BALL_PUMP_1_ACCELERATION_IN_RPSS = 5000; +const byte BALL_PUMP_1_HOME_SENSOR = 24; // barrel sensor +const byte BALL_PUMP_1_SENSOR = 28; // Optical Ball sensor +const long BALL_PUMP_1_DIRECTION_TOWARD_HOME = -1; // -1 is CCW +const long BALL_PUMP_1_DIRECTION = -1; // -1 is CCW 15000 +const long BALL_PUMP_1_MAX_STEPS = 15000; + +const long BALL_PUMP_2_STEPS_PER_REV = 200 * 5; +const long BALL_PUMP_2_MICROSTEPPING = 8; +const long BALL_PUMP_2_STEPS_PER_REV_INCLUDING_MICROSTEPPING = (BALL_PUMP_1_STEPS_PER_REV * BALL_PUMP_1_MICROSTEPPING); +const long BALL_PUMP_2_SPEED_IN_SPS = 750; // 5000; // 750; +const long BALL_PUMP_2_ACCELERATION_IN_RPSS = 5000; +const byte BALL_PUMP_2_HOME_SENSOR = 27; // barrel sensor +const byte BALL_PUMP_2_SENSOR = 29; // Optical ball sensor +const long BALL_PUMP_2_DIRECTION_TOWARD_HOME = 1; // -1 is CCW +const long BALL_PUMP_2_DIRECTION = 1; // -1 is CCW +const long BALL_PUMP_2_MAX_STEPS = 1500000; + +void setup() +{ + + Serial.begin(9600); + Serial.println("Setup begins"); + + pinMode(BALL_PUMP_SELECTOR_POT, INPUT_PULLUP); + + BallPump1.connectToPort(1); + BallPump1.setStepsPerRevolution(BALL_PUMP_1_STEPS_PER_REV * BALL_PUMP_1_MICROSTEPPING); + BallPump1.setSpeedInStepsPerSecond(BALL_PUMP_1_SPEED_IN_SPS); + BallPump1.setAccelerationInStepsPerSecondPerSecond(BALL_PUMP_1_ACCELERATION_IN_RPSS); + BallPump1.disableStepper(); + + pinMode(BALL_PUMP_1_SENSOR, INPUT_PULLUP); + pinMode(29, INPUT_PULLUP); + pinMode(BALL_PUMP_1_HOME_SENSOR, INPUT_PULLUP); + + BallPump2.connectToPort(2); + BallPump2.setStepsPerRevolution(BALL_PUMP_2_STEPS_PER_REV * BALL_PUMP_2_MICROSTEPPING); + BallPump2.setSpeedInStepsPerSecond(BALL_PUMP_2_SPEED_IN_SPS); + BallPump2.setAccelerationInStepsPerSecondPerSecond(BALL_PUMP_2_ACCELERATION_IN_RPSS); + BallPump2.disableStepper(); + + pinMode(BALL_PUMP_2_SENSOR, INPUT); + pinMode(BALL_PUMP_2_HOME_SENSOR, INPUT_PULLUP); + + int ballPumpSelector = 0; + int ballPump1HomeSensorState = 0; + int ballPump2HomeSensorState = 0; + + // BALL PUMPS SETUP HERE// + + Serial.println("Start Homing Ball Pump 1"); + BallPump1.enableStepper(); + // Don't Assume the Ball Pump Is correctly homed, offset and ready to accept a ball - so rotate some first then home + BallPump1.moveRelativeInSteps(100 * BALL_PUMP_1_DIRECTION_TOWARD_HOME); + BallPump1.moveToHomeInSteps(BALL_PUMP_1_DIRECTION_TOWARD_HOME, BALL_PUMP_1_SPEED_IN_SPS, + BALL_PUMP_1_MAX_STEPS, BALL_PUMP_1_HOME_SENSOR); + BallPump1.disableStepper(); + ballPump1HomeSensorState = digitalRead(BALL_PUMP_1_HOME_SENSOR); + Serial.print("BALL_PUMP#1_HOME_SENSOR_STATE = "); + Serial.println(ballPump1HomeSensorState); + Serial.println("Ball Pump 1 Homed"); + Serial.println("Moving to allow ball to enter gate"); + // Homing sensor is located such that ball will not enter gate - at home so we have to rotate it - to allow ball to enter gate. +// BallPump1.enableStepper(); +// BallPump1.moveRelativeInSteps(3500 * BALL_PUMP_1_DIRECTION_TOWARD_HOME); +// BallPump1.disableStepper(); + Serial.println("Ball Pump 1 Ready for Ball"); + + + +// Serial.println("Start Homing Ball Pump 2"); +// BallPump2.enableStepper(); +// // Don't Assume the Ball Pump Is correctly homed, offset and ready to accept a ball - so rotate some first then home +// BallPump2.moveRelativeInSteps(10000 * BALL_PUMP_2_DIRECTION_TOWARD_HOME); +// BallPump2.moveToHomeInSteps(BALL_PUMP_2_DIRECTION_TOWARD_HOME, BALL_PUMP_2_SPEED_IN_SPS, +// BALL_PUMP_2_MAX_STEPS, BALL_PUMP_2_HOME_SENSOR); +// BallPump2.disableStepper(); +// ballPump2HomeSensorState = digitalRead(BALL_PUMP_2_HOME_SENSOR); +// Serial.print("BALL_PUMP#2_HOME_SENSOR_STATE = "); +// Serial.println(ballPump2HomeSensorState); +// Serial.println("Ball Pump 2 Homed"); +//// Serial.println("Moving to allow ball to enter gate"); +//// // Homing sensor is located such that ball will not enter gate - at home so we have to rotate it - to allow ball to enter gate. +//// BallPump2.enableStepper(); +//// BallPump2.moveRelativeInSteps(3500 * BALL_PUMP_2_DIRECTION_TOWARD_HOME); +//// BallPump2.disableStepper(); +// Serial.println("Ball Pump 2 Ready for Ball"); + + + Serial.println("setup complete"); + delay(1000); +} +double correction = 1; + +void loop() +{ +// Serial.print("Port 23 status"); +// Serial.println(digitalRead(23)); +// Serial.print("Current pos: "); +// Serial.println(BallPump1.getCurrentPositionInSteps()); + int ballPump1HomeSensorState = 0; + ballPump1HomeSensorState = digitalRead(BALL_PUMP_1_HOME_SENSOR); + Serial.print("BALL_PUMP#1_HOME_SENSOR_STATE = "); + Serial.println(ballPump1HomeSensorState); + int ballPumpHomeSensorState = 1; + if (digitalRead(28) == LOW && digitalRead(23) == HIGH) // Select Pump 1 + { + + Serial.println("Pump 1"); + // Move Ball Pump 1 + // + if ((digitalRead(28) == LOW)) // LOW for an active LOW sensor + { // Ball Detected - Pump ball + Serial.println("Move Ball pump #1, one Rotation"); + Serial.println("Checking2"); + BallPump1.enableStepper(); + BallPump1.moveRelativeInSteps(BALL_PUMP_1_STEPS_PER_REV * 8.3 * BALL_PUMP_1_DIRECTION); + + BallPump1.disableStepper(); + Serial.println("Moved Ball pump #1, one Rotation"); + Serial.println(correction); + correction += correction*0.8 - correction *.4; + } + else + { + + Serial.println("No ball detected in ball pump #1"); + ballPumpHomeSensorState = digitalRead(BALL_PUMP_1_HOME_SENSOR); + Serial.print("BALL_PUMP#1_HOME_SENSOR_STATE = "); + Serial.println(ballPumpHomeSensorState); + } + } + + + else if (digitalRead(28) == LOW && digitalRead(23) == LOW)// Select Pump 2 + { + // Move Ball Pump 2 + + Serial.println("Pump 2"); + + if ((digitalRead(27)) == LOW) // HIGH for an active HIGH sensor + { + Serial.println("Move Ball pump #2, one Rotation"); + BallPump2.enableStepper(); + BallPump2.moveRelativeInSteps(BALL_PUMP_2_STEPS_PER_REV * 8 * BALL_PUMP_2_DIRECTION); // + BallPump2.disableStepper(); + Serial.println("Moved Ball pump #2, one Rotation"); + } + else + { + Serial.println("No ball detected in ball pump #2"); + ballPumpHomeSensorState = digitalRead(BALL_PUMP_2_HOME_SENSOR); + Serial.print("BALL_PUMP#2_HOME_SENSOR_STATE = "); + Serial.println(ballPumpHomeSensorState); + } + } + delay(1000); +} From c631166c2a5a042fd197133888f3e82605e022c7 Mon Sep 17 00:00:00 2001 From: KevinTEngineering <89664867+KevinTEngineering@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:35:54 -0700 Subject: [PATCH 2/4] Update Pump_Arduino.ino --- Pump_Arduino.ino | 90 ++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/Pump_Arduino.ino b/Pump_Arduino.ino index a58fdb3..385f7ab 100644 --- a/Pump_Arduino.ino +++ b/Pump_Arduino.ino @@ -7,23 +7,21 @@ SpeedyStepper BallPump1; SpeedyStepper BallPump2; -const byte BALL_PUMP_SELECTOR_POT = A7; // POT - -const long BALL_PUMP_1_STEPS_PER_REV = 200 * 5; +const long BALL_PUMP_1_STEPS_PER_REV = 200 * 76.766; const long BALL_PUMP_1_MICROSTEPPING = 8; const long BALL_PUMP_1_STEPS_PER_REV_INCLUDING_MICROSTEPPING = (BALL_PUMP_1_STEPS_PER_REV * BALL_PUMP_1_MICROSTEPPING); -const long BALL_PUMP_1_SPEED_IN_SPS = 750; // 5000; // 750; +const long BALL_PUMP_1_SPEED_IN_SPS = 7500; // 5000; // 750; const long BALL_PUMP_1_ACCELERATION_IN_RPSS = 5000; -const byte BALL_PUMP_1_HOME_SENSOR = 24; // barrel sensor +const byte BALL_PUMP_1_HOME_SENSOR = 26; // barrel sensor const byte BALL_PUMP_1_SENSOR = 28; // Optical Ball sensor const long BALL_PUMP_1_DIRECTION_TOWARD_HOME = -1; // -1 is CCW -const long BALL_PUMP_1_DIRECTION = -1; // -1 is CCW 15000 -const long BALL_PUMP_1_MAX_STEPS = 15000; +const long BALL_PUMP_1_DIRECTION = -1; // -1 is CCW +const long BALL_PUMP_1_MAX_STEPS = 1500000; -const long BALL_PUMP_2_STEPS_PER_REV = 200 * 5; +const long BALL_PUMP_2_STEPS_PER_REV = 200 * 76.766; const long BALL_PUMP_2_MICROSTEPPING = 8; const long BALL_PUMP_2_STEPS_PER_REV_INCLUDING_MICROSTEPPING = (BALL_PUMP_1_STEPS_PER_REV * BALL_PUMP_1_MICROSTEPPING); -const long BALL_PUMP_2_SPEED_IN_SPS = 750; // 5000; // 750; +const long BALL_PUMP_2_SPEED_IN_SPS = 7500; // 5000; // 750; const long BALL_PUMP_2_ACCELERATION_IN_RPSS = 5000; const byte BALL_PUMP_2_HOME_SENSOR = 27; // barrel sensor const byte BALL_PUMP_2_SENSOR = 29; // Optical ball sensor @@ -37,7 +35,7 @@ void setup() Serial.begin(9600); Serial.println("Setup begins"); - pinMode(BALL_PUMP_SELECTOR_POT, INPUT_PULLUP); +// pinMode(BALL_PUMP_SELECTOR_POT, INPUT_PULLUP); BallPump1.connectToPort(1); BallPump1.setStepsPerRevolution(BALL_PUMP_1_STEPS_PER_REV * BALL_PUMP_1_MICROSTEPPING); @@ -46,7 +44,6 @@ void setup() BallPump1.disableStepper(); pinMode(BALL_PUMP_1_SENSOR, INPUT_PULLUP); - pinMode(29, INPUT_PULLUP); pinMode(BALL_PUMP_1_HOME_SENSOR, INPUT_PULLUP); BallPump2.connectToPort(2); @@ -55,7 +52,7 @@ void setup() BallPump2.setAccelerationInStepsPerSecondPerSecond(BALL_PUMP_2_ACCELERATION_IN_RPSS); BallPump2.disableStepper(); - pinMode(BALL_PUMP_2_SENSOR, INPUT); + pinMode(BALL_PUMP_2_SENSOR, INPUT_PULLUP); pinMode(BALL_PUMP_2_HOME_SENSOR, INPUT_PULLUP); int ballPumpSelector = 0; @@ -67,7 +64,8 @@ void setup() Serial.println("Start Homing Ball Pump 1"); BallPump1.enableStepper(); // Don't Assume the Ball Pump Is correctly homed, offset and ready to accept a ball - so rotate some first then home - BallPump1.moveRelativeInSteps(100 * BALL_PUMP_1_DIRECTION_TOWARD_HOME); + BallPump1.moveRelativeInSteps(10000 * BALL_PUMP_1_DIRECTION_TOWARD_HOME); + BallPump1.moveToHomeInSteps(BALL_PUMP_1_DIRECTION_TOWARD_HOME, BALL_PUMP_1_SPEED_IN_SPS, BALL_PUMP_1_MAX_STEPS, BALL_PUMP_1_HOME_SENSOR); BallPump1.disableStepper(); @@ -77,36 +75,35 @@ void setup() Serial.println("Ball Pump 1 Homed"); Serial.println("Moving to allow ball to enter gate"); // Homing sensor is located such that ball will not enter gate - at home so we have to rotate it - to allow ball to enter gate. -// BallPump1.enableStepper(); -// BallPump1.moveRelativeInSteps(3500 * BALL_PUMP_1_DIRECTION_TOWARD_HOME); -// BallPump1.disableStepper(); + BallPump1.enableStepper(); + BallPump1.moveRelativeInSteps(3500 * BALL_PUMP_1_DIRECTION_TOWARD_HOME); + BallPump1.disableStepper(); Serial.println("Ball Pump 1 Ready for Ball"); -// Serial.println("Start Homing Ball Pump 2"); -// BallPump2.enableStepper(); -// // Don't Assume the Ball Pump Is correctly homed, offset and ready to accept a ball - so rotate some first then home -// BallPump2.moveRelativeInSteps(10000 * BALL_PUMP_2_DIRECTION_TOWARD_HOME); -// BallPump2.moveToHomeInSteps(BALL_PUMP_2_DIRECTION_TOWARD_HOME, BALL_PUMP_2_SPEED_IN_SPS, -// BALL_PUMP_2_MAX_STEPS, BALL_PUMP_2_HOME_SENSOR); -// BallPump2.disableStepper(); -// ballPump2HomeSensorState = digitalRead(BALL_PUMP_2_HOME_SENSOR); -// Serial.print("BALL_PUMP#2_HOME_SENSOR_STATE = "); -// Serial.println(ballPump2HomeSensorState); -// Serial.println("Ball Pump 2 Homed"); -//// Serial.println("Moving to allow ball to enter gate"); -//// // Homing sensor is located such that ball will not enter gate - at home so we have to rotate it - to allow ball to enter gate. -//// BallPump2.enableStepper(); -//// BallPump2.moveRelativeInSteps(3500 * BALL_PUMP_2_DIRECTION_TOWARD_HOME); -//// BallPump2.disableStepper(); -// Serial.println("Ball Pump 2 Ready for Ball"); + Serial.println("Start Homing Ball Pump 2"); + BallPump2.enableStepper(); + // Don't Assume the Ball Pump Is correctly homed, offset and ready to accept a ball - so rotate some first then home + BallPump2.moveRelativeInSteps(10000 * BALL_PUMP_2_DIRECTION_TOWARD_HOME); + BallPump2.moveToHomeInSteps(BALL_PUMP_2_DIRECTION_TOWARD_HOME, BALL_PUMP_2_SPEED_IN_SPS, + BALL_PUMP_2_MAX_STEPS, BALL_PUMP_2_HOME_SENSOR); + BallPump2.disableStepper(); + ballPump2HomeSensorState = digitalRead(BALL_PUMP_2_HOME_SENSOR); + Serial.print("BALL_PUMP#2_HOME_SENSOR_STATE = "); + Serial.println(ballPump2HomeSensorState); + Serial.println("Ball Pump 2 Homed"); + Serial.println("Moving to allow ball to enter gate"); + // Homing sensor is located such that ball will not enter gate - at home so we have to rotate it - to allow ball to enter gate. + BallPump2.enableStepper(); + BallPump2.moveRelativeInSteps(3500 * BALL_PUMP_2_DIRECTION_TOWARD_HOME); + BallPump2.disableStepper(); + Serial.println("Ball Pump 2 Ready for Ball"); Serial.println("setup complete"); delay(1000); } -double correction = 1; void loop() { @@ -114,28 +111,25 @@ void loop() // Serial.println(digitalRead(23)); // Serial.print("Current pos: "); // Serial.println(BallPump1.getCurrentPositionInSteps()); - int ballPump1HomeSensorState = 0; - ballPump1HomeSensorState = digitalRead(BALL_PUMP_1_HOME_SENSOR); - Serial.print("BALL_PUMP#1_HOME_SENSOR_STATE = "); - Serial.println(ballPump1HomeSensorState); +// int ballPump1HomeSensorState = 0; +// ballPump1HomeSensorState = digitalRead(BALL_PUMP_1_HOME_SENSOR); +// Serial.print("BALL_PUMP#1_HOME_SENSOR_STATE = "); +// Serial.println(ballPump1HomeSensorState); int ballPumpHomeSensorState = 1; - if (digitalRead(28) == LOW && digitalRead(23) == HIGH) // Select Pump 1 + if (digitalRead(BALL_PUMP_1_SENSOR) == HIGH) // && digitalRead(23) == HIGH) // Select Pump 1 { Serial.println("Pump 1"); // Move Ball Pump 1 - // - if ((digitalRead(28) == LOW)) // LOW for an active LOW sensor + + if ((digitalRead(BALL_PUMP_1_SENSOR) == HIGH)) // LOW for an active LOW sensor { // Ball Detected - Pump ball Serial.println("Move Ball pump #1, one Rotation"); - Serial.println("Checking2"); BallPump1.enableStepper(); - BallPump1.moveRelativeInSteps(BALL_PUMP_1_STEPS_PER_REV * 8.3 * BALL_PUMP_1_DIRECTION); - + BallPump1.moveRelativeInSteps(BALL_PUMP_1_STEPS_PER_REV * 8 * BALL_PUMP_1_DIRECTION); + // 8.3 BallPump1.disableStepper(); Serial.println("Moved Ball pump #1, one Rotation"); - Serial.println(correction); - correction += correction*0.8 - correction *.4; } else { @@ -148,13 +142,13 @@ void loop() } - else if (digitalRead(28) == LOW && digitalRead(23) == LOW)// Select Pump 2 + if (digitalRead(BALL_PUMP_2_SENSOR) == HIGH) //&& digitalRead(23) == LOW)// Select Pump 2 { // Move Ball Pump 2 Serial.println("Pump 2"); - if ((digitalRead(27)) == LOW) // HIGH for an active HIGH sensor + if ((digitalRead(BALL_PUMP_2_SENSOR)) == HIGH) // HIGH for an active HIGH sensor { Serial.println("Move Ball pump #2, one Rotation"); BallPump2.enableStepper(); From 53db2cfa7ff802c5b136d5ea34430cbde4148b9c Mon Sep 17 00:00:00 2001 From: KevinTEngineering <89664867+KevinTEngineering@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:38:00 -0700 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8364828..482b088 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Joints: x,y,z, measured in mm from the lens of the camera. ## How to Run ## -TODO +Monkey See, Monkey Do, Monkey Say HooHoo From d3a77f0fd31f7bee6c72b92bc82fc3f1c1cd0de1 Mon Sep 17 00:00:00 2001 From: KevinTEngineering <89664867+KevinTEngineering@users.noreply.github.com> Date: Wed, 6 Apr 2022 12:49:50 -0700 Subject: [PATCH 4/4] Add files via upload --- firma.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 19 +++++++++++++++++++ test.kv | 8 ++++++++ 3 files changed, 79 insertions(+) create mode 100644 firma.py create mode 100644 main.py create mode 100644 test.kv diff --git a/firma.py b/firma.py new file mode 100644 index 0000000..d4a0b6d --- /dev/null +++ b/firma.py @@ -0,0 +1,52 @@ +from pyfirmata import Arduino, util +from kivy.app import App +from kivy.lang import Builder +from kivy.core.window import Window +from kivy.properties import ObjectProperty + +from kivy.uix.button import Button +from pidev.kivy import DPEAButton +from kivy.uix.screenmanager import ScreenManager, Screen + +SCREEN_MANAGER= ScreenManager() +MAIN_SCREEN_NAME = 'main' +board = Arduino("/dev/ttyACM1") +# Change to your port +from time import sleep +class ProjectNameGUI(App): + tester = ObjectProperty(DPEAButton) + + def build(self): + """ + Build the application + :return: Kivy Screen Manager instance + """ + return SCREEN_MANAGER + +class MainScreen(Screen): + xcv = 0 + def switch(self): + if self.xcv == 1: + board.digital[13].write(0) + self.xcv = 0 + print(self.xcv) + elif self.xcv == 0: + board.digital[13].write(1) + self.xcv = 1 + print(self.xcv) + + +# print("Start blinking D13") +# print(board.digital[13]) + +# while True: +# board.digital[13].write(1) +# sleep(1) +# board.digital[13].write(0) +# sleep(1) + +Builder.load_file('test.kv') +SCREEN_MANAGER.add_widget(MainScreen(name='main')) + +if __name__ == '__main__': + ProjectNameGUI().run() \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..2f196cd --- /dev/null +++ b/main.py @@ -0,0 +1,19 @@ +from pyfirmata import Arduino, util +from time import sleep + +board = Arduino("/dev/ttyACM1") # Change to your port +print("Start blinking D13") +# board.digital[13].write(1) +while True: + board.digital[13].write(1) + sleep(1) + board.digital[13].write(0) + sleep(1) + + + +# Press the green button in the gutter to run the script. +# if __name__ == '__main__': +# print_hi('PyCharm') + +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ diff --git a/test.kv b/test.kv new file mode 100644 index 0000000..cf2d231 --- /dev/null +++ b/test.kv @@ -0,0 +1,8 @@ +: + DPEAButton: + id: tester + text: 'test' + size: 100, 100 + x: root.width * 0.6 + y: root.height * 0.2 + on_press: root.switch()