From 1337de59b712c30c447b2b45de9ec54ecd6d8ea4 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Fri, 18 Feb 2022 12:41:51 -0600 Subject: Hopefully get the system able to be packaged Signed-off-by: Matt Strapp --- System/Tests/donovanTestScript.py | 81 +++++++++++++++++++++++++++++++++++++++ System/Tests/samTestScript.py | 42 ++++++++++++++++++++ System/Tests/test_Encoder.py | 23 +++++++++++ System/Tests/test_Motor.py | 29 ++++++++++++++ System/Tests/test_Return_Home.py | 19 +++++++++ System/Tests/test_System.py | 13 +++++++ 6 files changed, 207 insertions(+) create mode 100644 System/Tests/donovanTestScript.py create mode 100644 System/Tests/samTestScript.py create mode 100644 System/Tests/test_Encoder.py create mode 100644 System/Tests/test_Motor.py create mode 100644 System/Tests/test_Return_Home.py create mode 100644 System/Tests/test_System.py (limited to 'System/Tests') diff --git a/System/Tests/donovanTestScript.py b/System/Tests/donovanTestScript.py new file mode 100644 index 0000000..4a51f08 --- /dev/null +++ b/System/Tests/donovanTestScript.py @@ -0,0 +1,81 @@ + + + + + +import sys +sys.path.insert(0, '/home/pi/pendulum/System') +from System.system import System +import time +from sys import exit +#import pandas + + +### +sys.path.insert(0, '/home/pi/pendulum/System') +from encoder import Encoder +import RPi.GPIO as GPIO + + +clk_pin = 3 +cs_pin = 23 +data_pin = 2 + +e = Encoder(clk_pin, cs_pin, data_pin) +e.set_zero() +### + + + + +sys = System(angular_units = 'Radians') + +for x in range(4,20): + linear = 0 + + print("beginning of test with speed " + str(x)) + + while linear > -7: + sys.adjust(-5) + angle, linear = sys.measure() + print("Angle: " + str(angle) + ", Linear: " + str(linear)) + time.sleep(0.1) + sys.adjust(0) + time.sleep(3) + sys.add_log("this is a test with speed " + str(x)) + + while linear < 7: + sys.adjust(x) + angle, linear = sys.measure() + print("Angle: " + str(angle) + ", Linear: " + str(linear)) + sys.add_results(e.read_position('Degrees'), linear, x) + time.sleep(0.1) + sys.adjust(0) + print("end of test with speed " + str(x)) + time.sleep(3) + + +exit() + + + + + + + + +#class test(): +# def __init__(self, x, theta): +# self.x = 0 +# self.theta = 0 +# +# def getINFO(self, theta): +# #theta, x = self.System.measure() +# theta, x = self.sys.measure() +# +#while(1): +# test.getINFO() +# print("t") +# #print("theta",test.theta) +# #print("x",test.x) +# diff --git a/System/Tests/samTestScript.py b/System/Tests/samTestScript.py new file mode 100644 index 0000000..5f9312f --- /dev/null +++ b/System/Tests/samTestScript.py @@ -0,0 +1,42 @@ + +import sys +sys.path.insert(0, '/home/pi/pendulum/System') +from System.system import System +import time +from sys import exit +#import pandas + + +sys = System(angular_units = 'Radians') + +for x in range(0,10): + angle, linear = sys.measure() + print("Angle: " + str(angle) + ", Linear: " + str(linear)) + sys.add_results(linear, angle, angle) + time.sleep(0.2) + + +exit() + + + + + + + + +#class test(): +# def __init__(self, x, theta): +# self.x = 0 +# self.theta = 0 +# +# def getINFO(self, theta): +# #theta, x = self.System.measure() +# theta, x = self.sys.measure() +# +#while(1): +# test.getINFO() +# print("t") +# #print("theta",test.theta) +# #print("x",test.x) +# \ No newline at end of file diff --git a/System/Tests/test_Encoder.py b/System/Tests/test_Encoder.py new file mode 100644 index 0000000..bb6e3e4 --- /dev/null +++ b/System/Tests/test_Encoder.py @@ -0,0 +1,23 @@ +from encoder import Encoder +import time +import RPi.GPIO as GPIO + +# Decide which pins to hook up to on the Pi before running +clk_pin = 3 +cs_pin = 23 +data_pin = 2 + +e = Encoder(clk_pin, cs_pin, data_pin) +e.set_zero() + +try: + while(1): + print(e.read_position('Degrees')) + time.sleep(0.001) +except: + print("Program killed by Ctrl-C") +finally: + # Perform GPIO cleanup. Things may get weird otherwise... + GPIO.cleanup() + + diff --git a/System/Tests/test_Motor.py b/System/Tests/test_Motor.py new file mode 100644 index 0000000..f48b6ee --- /dev/null +++ b/System/Tests/test_Motor.py @@ -0,0 +1,29 @@ +from motor import Motor +import time +import RPi.GPIO as GPIO + +# Decide which pins to hook up to on the Pi before running +speed_pin = 17 +forward_pin = 27 +reverse_pin = 22 + +m = Motor(speed_pin, forward_pin, reverse_pin) + +dir = 'ascending' +speed = 0.0 +try: + while 1: + if speed >= 15.0: + dir = 'descending' + elif speed <= -15.0: + dir = 'ascending' + if dir == 'ascending': + speed = speed + 2.0 + else: + speed = speed - 2.0 + m.move(speed) + time.sleep(0.1) +except: + print("Program killed by Ctrl-C") +finally: + GPIO.cleanup() \ No newline at end of file diff --git a/System/Tests/test_Return_Home.py b/System/Tests/test_Return_Home.py new file mode 100644 index 0000000..04e19cb --- /dev/null +++ b/System/Tests/test_Return_Home.py @@ -0,0 +1,19 @@ +from system import System +from time import sleep + +# Main program +#print("before system()call") +sys = System() +#print("after system() call") +sys.initialize() +#print("after sys.inintalize called") + +ang,lin = sys.measure() +print("Starting position before moving: " + str(lin)) +sys.adjust(4) +ang,lin = sys.measure() +sleep(0.01) +while lin < 10: + ang,lin = sys.measure() + sleep(0.01) +sys.return_home() diff --git a/System/Tests/test_System.py b/System/Tests/test_System.py new file mode 100644 index 0000000..c05affc --- /dev/null +++ b/System/Tests/test_System.py @@ -0,0 +1,13 @@ +# This test file implements a super simple control-type function for testing the System library. +# DO NOT TEST ON ASSEMBLED PHYSICAL SYSTEM! It will probably break it. +import time + +from System.system import System + +# Main program +sys = System(angular_units = 'Radians') +while 1: + angle, linear = sys.measure() + print("Angle: " + str(angle) + ", Linear: " + str(linear)) + time.sleep(0.2) + -- cgit v1.2.3