From 772cff67fd3b491d015ba89601a0a098c69edd69 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Thu, 27 Jan 2022 15:29:31 -0600 Subject: Add code that was not committed before --- .gitignore | 0 PI.PI.old.py | 64 +++++++++ PI.py | 64 --------- README.md | 0 System/Downloads/.~lock.results.csv# | 1 + System/Downloads/results.csv | 255 +++++++++++++++++++++++++++++++++++ System/System | 1 - System/Uploads/donovanTestScript.py | 81 +++++++++++ System/Uploads/upload.py | 81 +++++++++++ System/__init__.py | 0 System/donovanTestScript.py | 81 +++++++++++ System/encoder.py | 0 System/errorTestScript.py | 42 ++++++ System/homework8.ipynb | 0 System/initialize_system.py | 9 ++ System/motor.py | 9 ++ System/results.csv | 252 ++++++++++++++++++++++++++++++++++ System/samTestScript.py | 42 ++++++ System/swingUp.py | 16 +-- System/system.py | 68 ++++++++-- System/system_swingup_test.py | 0 System/system_swingup_test_2.py | 23 +++- System/test_Encoder.py | 8 +- System/test_Motor.py | 0 System/test_Return_Home.py | 3 + System/test_System.py | 0 Web/PI/PI.py | 0 Web/PI/Results/PLACEHOLDER.txt | 0 Web/PI/Uploads/PLACEHOLDER | 0 Web/PI/test2.py | 0 Web/Server/Results/PLACEHOLDER | 0 Web/Server/Results/results.csv | 0 Web/Server/Server.py | 0 Web/Server/static/Server.css | 0 Web/Server/static/Server.js | 0 Web/Server/templates/base.html | 0 Web/Server/templates/index.html | 0 Web/Server/templates/results.html | 0 Web/requirements.txt | 0 Web/test.py | 0 test_script_results.csv | 1 + 41 files changed, 1010 insertions(+), 91 deletions(-) mode change 100755 => 100644 .gitignore create mode 100644 PI.PI.old.py delete mode 100755 PI.py mode change 100755 => 100644 README.md create mode 100644 System/Downloads/.~lock.results.csv# create mode 100644 System/Downloads/results.csv delete mode 120000 System/System create mode 100644 System/Uploads/donovanTestScript.py create mode 100644 System/Uploads/upload.py mode change 100755 => 100644 System/__init__.py create mode 100644 System/donovanTestScript.py mode change 100755 => 100644 System/encoder.py create mode 100644 System/errorTestScript.py mode change 100755 => 100644 System/homework8.ipynb mode change 100755 => 100644 System/initialize_system.py mode change 100755 => 100644 System/motor.py create mode 100644 System/results.csv create mode 100644 System/samTestScript.py mode change 100755 => 100644 System/swingUp.py mode change 100755 => 100644 System/system.py mode change 100755 => 100644 System/system_swingup_test.py mode change 100755 => 100644 System/system_swingup_test_2.py mode change 100755 => 100644 System/test_Encoder.py mode change 100755 => 100644 System/test_Motor.py mode change 100755 => 100644 System/test_Return_Home.py mode change 100755 => 100644 System/test_System.py mode change 100755 => 100644 Web/PI/PI.py mode change 100755 => 100644 Web/PI/Results/PLACEHOLDER.txt mode change 100755 => 100644 Web/PI/Uploads/PLACEHOLDER mode change 100755 => 100644 Web/PI/test2.py mode change 100755 => 100644 Web/Server/Results/PLACEHOLDER mode change 100755 => 100644 Web/Server/Results/results.csv mode change 100755 => 100644 Web/Server/Server.py mode change 100755 => 100644 Web/Server/static/Server.css mode change 100755 => 100644 Web/Server/static/Server.js mode change 100755 => 100644 Web/Server/templates/base.html mode change 100755 => 100644 Web/Server/templates/index.html mode change 100755 => 100644 Web/Server/templates/results.html mode change 100755 => 100644 Web/requirements.txt mode change 100755 => 100644 Web/test.py create mode 100644 test_script_results.csv diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/PI.PI.old.py b/PI.PI.old.py new file mode 100644 index 0000000..52e16ab --- /dev/null +++ b/PI.PI.old.py @@ -0,0 +1,64 @@ +#handle a POST request +from flask import Flask, render_template, request, url_for, jsonify +import subprocess +import os +import RPi.GPIO as GPIO +app = Flask(__name__) + +UPLOAD_DESTINATION = "Uploads/ee4951W_pendulum_web/app/app/FileProcessing/Uploads" +SYSTEM_DESTINATION = "System/" +RESULTS_DESTINATION = "Uploads/ee4951W_pendulum_web/app/app/FileProcessing/Results" + +INITIALIZE_SYSTEM = "initialize_system.py" + +@app.route('/') +def home(): + return "ANDI'S PIE" + +@app.route('/tests/endpoint', methods=['POST']) +def my_test_endpoint(): + # Receive post + input_json = request.get_json(force=True) + + # Put file content into a file caled upload.py + filename=input_json['filename'].encode("ascii") + file_content=input_json['file_content'].encode("ascii") + filename=input_json['filename'] + file_content=input_json['file_content'] + upload = open(UPLOAD_DESTINATION + filename, "w+") + upload.write(file_content) + upload.close() + + # Run python script + process = subprocess.Popen(["python3", UPLOAD_DESTINATION + filename]) + try: + process.wait() + print("Program exited normally!\n") + except: + print("Exception occurred running program!\n") + process.terminate() + finally: + GPIO.cleanup() + + # Get results file + results_filename = filename.split(".")[0] + results_filename = results_filename + "_results.csv" + with open(RESULTS_DESTINATION + results_filename, 'r') as results: + results_content = results.read() + results.close() + + # Remove test file and results file now that were done with them + os.remove(UPLOAD_DESTINATION + filename) + os.remove(RESULTS_DESTINATION + results_filename) + + # Return results file content + dictToReturn = {'results_filename':results_filename, 'results_content':results_content} + return jsonify(dictToReturn) + +# This will run on system bootup. +if __name__ == '__main__': + os.chdir('/home/pi/pendulum') + # Initialize the system before accepting any files. + subprocess.call(["python3", SYSTEM_DESTINATION + INITIALIZE_SYSTEM]) + # Run the web client to start receiving files. + app.run(host="192.168.1.10", port=8000) diff --git a/PI.py b/PI.py deleted file mode 100755 index 2157cbd..0000000 --- a/PI.py +++ /dev/null @@ -1,64 +0,0 @@ -#handle a POST request -from flask import Flask, render_template, request, url_for, jsonify -import subprocess -import os -import RPi.GPIO as GPIO -app = Flask(__name__) - -UPLOAD_DESTINATION = "Uploads/" -SYSTEM_DESTINATION = "System/" -RESULTS_DESTINATION = "Results/" - -INITIALIZE_SYSTEM = "initialize_system.py" - -@app.route('/') -def home(): - return "ANDI'S PIE" - -@app.route('/tests/endpoint', methods=['POST']) -def my_test_endpoint(): - # Receive post - input_json = request.get_json(force=True) - - # Put file content into a file caled upload.py - filename=input_json['filename'].encode("ascii") - file_content=input_json['file_content'].encode("ascii") - filename=input_json['filename'] - file_content=input_json['file_content'] - upload = open(UPLOAD_DESTINATION + filename, "w+") - upload.write(file_content) - upload.close() - - # Run python script - process = subprocess.Popen(["python3", UPLOAD_DESTINATION + filename]) - try: - process.wait() - print("Program exited normally!\n") - except: - print("Exception occurred running program!\n") - process.terminate() - finally: - GPIO.cleanup() - - # Get results file - results_filename = filename.split(".")[0] - results_filename = results_filename + "_results.csv" - with open(RESULTS_DESTINATION + results_filename, 'r') as results: - results_content = results.read() - results.close() - - # Remove test file and results file now that were done with them - os.remove(UPLOAD_DESTINATION + filename) - os.remove(RESULTS_DESTINATION + results_filename) - - # Return results file content - dictToReturn = {'results_filename':results_filename, 'results_content':results_content} - return jsonify(dictToReturn) - -# This will run on system bootup. -if __name__ == '__main__': - os.chdir('/home/pi/pendulum') - # Initialize the system before accepting any files. - subprocess.call(["python3", SYSTEM_DESTINATION + INITIALIZE_SYSTEM]) - # Run the web client to start receiving files. - app.run(host="192.168.1.10", port=8000) diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/System/Downloads/.~lock.results.csv# b/System/Downloads/.~lock.results.csv# new file mode 100644 index 0000000..e78d75a --- /dev/null +++ b/System/Downloads/.~lock.results.csv# @@ -0,0 +1 @@ +,pi,raspberrypi,17.11.2021 01:58,file:///home/pi/.config/libreoffice/4; \ No newline at end of file diff --git a/System/Downloads/results.csv b/System/Downloads/results.csv new file mode 100644 index 0000000..3bb6442 --- /dev/null +++ b/System/Downloads/results.csv @@ -0,0 +1,255 @@ +timestamp,angle(Radians),position(inches),speed(percentage) +this is a test with speed 4 +timestamp,angle(Radians),position(inches),speed(percentage) +16:05:38.576364,151.875000,-8.439453,4.000000 +16:05:38.681444,163.828125,-7.929688,4.000000 +16:05:38.786566,181.757812,-7.250000,4.000000 +16:05:38.891516,169.804688,-6.570312,4.000000 +16:05:38.995733,212.343750,-6.003906,4.000000 +16:05:39.100758,226.406250,-5.437500,4.000000 +16:05:39.205412,240.820312,-4.814453,4.000000 +16:05:39.310307,253.828125,-4.304688,4.000000 +16:05:39.415478,267.890625,-3.738281,4.000000 +16:05:39.520592,286.875000,-3.001953,4.000000 +16:05:39.625938,169.804688,-2.265625,4.000000 +16:05:39.731885,325.898438,-1.416016,4.000000 +16:05:39.836757,349.453125,-0.566406,4.000000 +16:05:39.941132,3.867188,0.169922,4.000000 +16:05:40.045609,18.984375,0.679688,4.000000 +16:05:40.150155,33.750000,1.302734,4.000000 +16:05:40.254815,46.054688,1.812500,4.000000 +16:05:40.359374,59.062500,2.322266,4.000000 +16:05:40.464077,72.070312,2.888672,4.000000 +16:05:40.569240,85.078125,3.341797,4.000000 +16:05:40.673757,100.898438,3.964844,4.000000 +16:05:40.778099,120.234375,4.814453,4.000000 +16:05:40.882811,135.000000,5.380859,4.000000 +16:05:40.987922,150.117188,5.947266,4.000000 +16:05:41.093497,164.531250,6.570312,4.000000 +16:05:41.198542,310.078125,6.117188,4.000000 +16:05:41.303724,194.765625,7.816406,4.000000 +this is a test with speed 5 +timestamp,angle(Radians),position(inches),speed(percentage) +16:05:49.596340,151.523438,-8.439453,5.000000 +16:05:49.702042,164.882812,-7.986328,5.000000 +16:05:49.806746,182.109375,-7.250000,5.000000 +16:05:49.911113,200.039062,-6.457031,5.000000 +16:05:50.016017,217.265625,-5.833984,5.000000 +16:05:50.120927,233.789062,-5.154297,5.000000 +16:05:50.226005,246.796875,-4.531250,5.000000 +16:05:50.331501,264.023438,-3.908203,5.000000 +16:05:50.436136,280.195312,-3.228516,5.000000 +16:05:50.540434,300.234375,-2.435547,5.000000 +16:05:50.644997,310.078125,-1.642578,5.000000 +16:05:50.749780,338.554688,-0.962891,5.000000 +16:05:50.854710,359.648438,-0.113281,5.000000 +16:05:50.959321,14.765625,0.566406,5.000000 +16:05:51.064479,28.476562,1.076172,5.000000 +16:05:51.169904,41.835938,1.642578,5.000000 +16:05:51.274321,53.789062,2.095703,5.000000 +16:05:51.379558,82.265625,2.718750,5.000000 +16:05:51.485216,86.484375,3.455078,5.000000 +16:05:51.589896,103.359375,4.078125,5.000000 +16:05:51.694795,118.828125,4.701172,5.000000 +16:05:51.799843,135.000000,5.380859,5.000000 +16:05:51.905289,153.281250,6.117188,5.000000 +16:05:52.010447,168.046875,6.740234,5.000000 +16:05:52.115766,184.570312,7.363281,5.000000 +this is a test with speed 6 +timestamp,angle(Radians),position(inches),speed(percentage) +16:06:00.402833,155.742188,-8.212891,6.000000 +16:06:00.507380,170.859375,-7.703125,6.000000 +16:06:00.611857,192.304688,-6.796875,6.000000 +16:06:00.716536,212.343750,-6.003906,6.000000 +16:06:00.821368,229.570312,-5.210938,6.000000 +16:06:00.926219,248.554688,-4.531250,6.000000 +16:06:01.030902,268.242188,-3.738281,6.000000 +16:06:01.135153,291.093750,-2.888672,6.000000 +16:06:01.240387,310.429688,-2.039062,6.000000 +16:06:01.346681,337.500000,-1.019531,6.000000 +16:06:01.451072,357.890625,-0.169922,6.000000 +16:06:01.555432,14.765625,0.509766,6.000000 +16:06:01.659765,31.640625,1.189453,6.000000 +16:06:01.764515,47.109375,1.925781,6.000000 +16:06:01.869452,84.726562,1.982422,6.000000 +16:06:01.974763,81.210938,3.228516,6.000000 +16:06:02.080037,110.390625,4.417969,6.000000 +16:06:02.184478,133.242188,5.267578,6.000000 +16:06:02.288869,159.257812,6.343750,6.000000 +16:06:02.394059,178.593750,7.136719,6.000000 +this is a test with speed 7 +timestamp,angle(Radians),position(inches),speed(percentage) +16:06:10.787039,155.742188,-8.326172,7.000000 +16:06:10.891894,172.265625,-7.589844,7.000000 +16:06:10.996373,197.226562,-6.683594,7.000000 +16:06:11.101025,220.078125,-5.720703,7.000000 +16:06:11.205584,241.875000,-4.814453,7.000000 +16:06:11.310519,264.726562,-3.851562,7.000000 +16:06:11.415853,287.929688,-2.945312,7.000000 +16:06:11.521213,316.054688,-1.869141,7.000000 +16:06:11.626844,339.960938,-0.792969,7.000000 +16:06:11.731536,4.570312,0.056641,7.000000 +16:06:11.836571,24.257812,0.906250,7.000000 +16:06:11.941584,45.000000,1.699219,7.000000 +16:06:12.046068,67.148438,2.662109,7.000000 +16:06:12.150479,87.187500,3.455078,7.000000 +16:06:12.255299,110.390625,4.417969,7.000000 +16:06:12.360261,132.187500,5.324219,7.000000 +16:06:12.465326,164.179688,6.343750,7.000000 +16:06:12.570285,247.148438,7.306641,7.000000 +this is a test with speed 8 +timestamp,angle(Radians),position(inches),speed(percentage) +16:06:21.067404,146.953125,-8.609375,8.000000 +16:06:21.172426,167.343750,-7.816406,8.000000 +16:06:21.277701,194.062500,-6.740234,8.000000 +16:06:21.382108,221.132812,-5.607422,8.000000 +16:06:21.487238,246.445312,-4.587891,8.000000 +16:06:21.591897,272.812500,-3.681641,8.000000 +16:06:21.696160,299.531250,-2.492188,8.000000 +16:06:21.800504,333.632812,-1.189453,8.000000 +16:06:21.905406,3.867188,0.056641,8.000000 +16:06:22.010322,27.773438,1.076172,8.000000 +16:06:22.115327,50.273438,1.982422,8.000000 +16:06:22.220967,310.078125,2.888672,8.000000 +16:06:22.325576,102.656250,4.021484,8.000000 +16:06:22.429865,131.132812,5.267578,8.000000 +16:06:22.534194,158.203125,6.343750,8.000000 +16:06:22.638637,183.515625,7.306641,8.000000 +this is a test with speed 9 +timestamp,angle(Radians),position(inches),speed(percentage) +16:06:31.031310,156.445312,-8.156250,9.000000 +16:06:31.135897,178.593750,-7.363281,9.000000 +16:06:31.240262,207.773438,-6.173828,9.000000 +16:06:31.344854,235.195312,-5.154297,9.000000 +16:06:31.449848,262.265625,-3.964844,9.000000 +16:06:31.554751,295.312500,-2.662109,9.000000 +16:06:31.659333,328.359375,-1.416016,9.000000 +16:06:31.764724,358.945312,-0.113281,9.000000 +16:06:31.870791,28.125000,1.076172,9.000000 +16:06:31.975477,51.679688,2.095703,9.000000 +16:06:32.080707,78.750000,3.001953,9.000000 +16:06:32.186322,107.578125,4.304688,9.000000 +16:06:32.290125,135.703125,5.380859,9.000000 +16:06:32.393809,161.015625,6.513672,9.000000 +16:06:32.497669,184.921875,7.419922,9.000000 +this is a test with speed 10 +timestamp,angle(Radians),position(inches),speed(percentage) +16:06:40.786494,165.937500,-7.816406,10.000000 +16:06:40.890933,189.492188,-6.966797,10.000000 +16:06:40.995809,220.429688,-5.664062,10.000000 +16:06:41.100863,251.367188,-4.417969,10.000000 +16:06:41.205687,169.804688,-3.115234,10.000000 +16:06:41.310919,318.867188,-1.416016,10.000000 +16:06:41.416911,7.382812,0.226562,10.000000 +16:06:41.521777,37.265625,1.472656,10.000000 +16:06:41.626084,63.632812,2.435547,10.000000 +16:06:41.730686,93.867188,3.681641,10.000000 +16:06:41.835368,129.023438,5.210938,10.000000 +16:06:41.939942,166.640625,6.513672,10.000000 +16:06:42.044809,197.226562,7.873047,10.000000 +this is a test with speed 11 +timestamp,angle(Radians),position(inches),speed(percentage) +16:06:50.543685,310.078125,-8.099609,11.000000 +16:06:50.648804,186.679688,-7.136719,11.000000 +16:06:50.753326,217.968750,-5.777344,11.000000 +16:06:50.857634,248.906250,-4.474609,11.000000 +16:06:50.962427,286.875000,-3.058594,11.000000 +16:06:51.068607,16.171875,-1.416016,11.000000 +16:06:51.174180,7.031250,0.169922,11.000000 +16:06:51.279678,39.726562,1.472656,11.000000 +16:06:51.384272,68.554688,2.718750,11.000000 +16:06:51.488482,103.359375,4.078125,11.000000 +16:06:51.593232,139.921875,5.607422,11.000000 +16:06:51.698487,177.539062,7.136719,11.000000 +this is a test with speed 12 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:00.197329,159.257812,-8.099609,12.000000 +16:07:00.301685,185.976562,-7.136719,12.000000 +16:07:00.406330,220.429688,-5.720703,12.000000 +16:07:00.511087,255.585938,-4.248047,12.000000 +16:07:00.616240,298.476562,-2.662109,12.000000 +16:07:00.721471,342.773438,-0.849609,12.000000 +16:07:00.826835,336.796875,0.849609,12.000000 +16:07:00.931624,55.195312,2.095703,12.000000 +16:07:01.035890,91.054688,3.511719,12.000000 +16:07:01.141184,145.898438,5.777344,12.000000 +16:07:01.245834,196.523438,7.929688,12.000000 +this is a test with speed 13 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:09.743638,153.632812,-8.382812,13.000000 +16:07:09.847816,182.812500,-7.250000,13.000000 +16:07:09.952134,219.726562,-5.664062,13.000000 +16:07:10.056729,256.992188,-4.304688,13.000000 +16:07:10.161448,304.453125,-2.378906,13.000000 +16:07:10.266560,354.375000,-0.339844,13.000000 +16:07:10.371654,30.937500,1.189453,13.000000 +16:07:10.477023,71.367188,2.718750,13.000000 +16:07:10.581384,120.585938,4.757812,13.000000 +16:07:10.685667,170.156250,6.796875,13.000000 +16:07:10.790022,215.156250,8.552734,13.000000 +this is a test with speed 14 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:19.597447,160.664062,-8.042969,14.000000 +16:07:19.702667,193.007812,-6.910156,14.000000 +16:07:19.808553,234.140625,-5.210938,14.000000 +16:07:19.913233,278.437500,-3.398438,14.000000 +16:07:20.018636,330.468750,-1.189453,14.000000 +16:07:20.123250,17.578125,0.623047,14.000000 +16:07:20.227511,56.601562,2.208984,14.000000 +16:07:20.331845,98.437500,3.908203,14.000000 +16:07:20.436379,148.359375,5.777344,14.000000 +16:07:20.541330,194.062500,7.759766,14.000000 +this is a test with speed 15 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:28.935194,159.609375,-8.099609,15.000000 +16:07:29.039480,191.601562,-6.853516,15.000000 +16:07:29.144157,232.382812,-5.097656,15.000000 +16:07:29.249377,281.250000,-3.398438,15.000000 +16:07:29.354193,340.312500,-0.962891,15.000000 +16:07:29.458554,26.367188,1.019531,15.000000 +16:07:29.563759,73.828125,2.492188,15.000000 +16:07:29.668658,116.015625,4.531250,15.000000 +16:07:29.773489,169.101562,6.796875,15.000000 +16:07:29.877867,215.507812,8.552734,15.000000 +this is a test with speed 16 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:38.582762,165.585938,-7.816406,16.000000 +16:07:38.688051,199.687500,-6.513672,16.000000 +16:07:38.792437,241.523438,-4.814453,16.000000 +16:07:38.897530,292.500000,-2.945312,16.000000 +16:07:39.003307,351.210938,-0.509766,16.000000 +16:07:39.108681,36.562500,1.472656,16.000000 +16:07:39.214399,81.210938,3.171875,16.000000 +16:07:39.319046,134.296875,5.210938,16.000000 +16:07:39.423418,189.492188,7.476562,16.000000 +this is a test with speed 17 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:48.023090,168.750000,-7.703125,17.000000 +16:07:48.128140,204.609375,-6.400391,17.000000 +16:07:48.232817,249.960938,-4.531250,17.000000 +16:07:48.337239,309.726562,-2.039062,17.000000 +16:07:48.443361,11.250000,0.283203,17.000000 +16:07:48.548089,58.007812,2.208984,17.000000 +16:07:48.652292,110.039062,4.361328,17.000000 +16:07:48.756551,170.156250,6.683594,17.000000 +16:07:48.862183,223.945312,8.835938,17.000000 +this is a test with speed 18 +timestamp,angle(Radians),position(inches),speed(percentage) +16:07:57.567597,157.148438,-8.156250,18.000000 +16:07:57.672093,195.820312,-6.796875,18.000000 +16:07:57.776988,246.093750,-4.644531,18.000000 +16:07:57.881749,307.617188,-2.152344,18.000000 +16:07:57.986505,11.953125,0.339844,18.000000 +16:07:58.091505,61.523438,2.378906,18.000000 +16:07:58.195897,120.585938,4.814453,18.000000 +16:07:58.300081,182.109375,7.136719,18.000000 +this is a test with speed 19 +timestamp,angle(Radians),position(inches),speed(percentage) +16:08:06.795459,149.062500,-8.552734,19.000000 +16:08:06.900815,190.195312,-7.023438,19.000000 +16:08:07.005599,248.554688,-4.587891,19.000000 +16:08:07.110350,318.515625,-1.755859,19.000000 +16:08:07.214857,23.554688,0.736328,19.000000 +16:08:07.319972,75.234375,2.888672,19.000000 +16:08:07.425617,139.218750,5.437500,19.000000 +16:08:07.530277,202.148438,8.099609,19.000000 diff --git a/System/System b/System/System deleted file mode 120000 index 6a04314..0000000 --- a/System/System +++ /dev/null @@ -1 +0,0 @@ -./ \ No newline at end of file diff --git a/System/Uploads/donovanTestScript.py b/System/Uploads/donovanTestScript.py new file mode 100644 index 0000000..4a51f08 --- /dev/null +++ b/System/Uploads/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/Uploads/upload.py b/System/Uploads/upload.py new file mode 100644 index 0000000..4a51f08 --- /dev/null +++ b/System/Uploads/upload.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/__init__.py b/System/__init__.py old mode 100755 new mode 100644 diff --git a/System/donovanTestScript.py b/System/donovanTestScript.py new file mode 100644 index 0000000..4a51f08 --- /dev/null +++ b/System/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/encoder.py b/System/encoder.py old mode 100755 new mode 100644 diff --git a/System/errorTestScript.py b/System/errorTestScript.py new file mode 100644 index 0000000..cb029d5 --- /dev/null +++ b/System/errorTestScript.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/homework8.ipynb b/System/homework8.ipynb old mode 100755 new mode 100644 diff --git a/System/initialize_system.py b/System/initialize_system.py old mode 100755 new mode 100644 index 6df880f..38b7134 --- a/System/initialize_system.py +++ b/System/initialize_system.py @@ -4,6 +4,15 @@ from system import System import RPi.GPIO as GPIO # Main program +print("Got to init") sys = System() sys.initialize() GPIO.cleanup() + + +##debug version +#print("alive") +#sys = System() +#limit_negative_pin = 19 +#while(1): +# print(GPIO.input(limit_negative_pin)) \ No newline at end of file diff --git a/System/motor.py b/System/motor.py old mode 100755 new mode 100644 index b22dbe2..427d393 --- a/System/motor.py +++ b/System/motor.py @@ -2,6 +2,7 @@ # Import required modules import RPi.GPIO as GPIO +from time import sleep # Constants: parameters that the caller cannot modify # Frequency: We have determined that the optimal frequency for our motor is 1kHz @@ -22,11 +23,15 @@ class Motor: GPIO.setup(self.reverse_pin, GPIO.OUT) # Set speed pin as a PWM output self.speed_pwm = GPIO.PWM(speed_pin, pwm_frequency) + self.current_speed = 0. # END __init__ # Move the motor at a given speed, given as a floating point percentage (-100 <= x <= 100) # If speed is less than 0, motor will run in reverse, otherwise it will run forward def move(self, speed): + if speed == self.current_speed: + # do not attempt to readjust speed; this can cause erratic behavior + return if speed < -100.0 or speed > 100.0: return # Stop any previous movements @@ -43,6 +48,8 @@ class Motor: GPIO.output(self.reverse_pin, GPIO.LOW) # Start the PWM output to start moving the motor self.speed_pwm.start(abs(speed)) + self.current_speed = speed + sleep((1./pwm_frequency) * 3) # END Move # Stop the motor from spinning. @@ -53,6 +60,7 @@ class Motor: # Set the direction outputs to brake GPIO.output(self.forward_pin, GPIO.HIGH) GPIO.output(self.reverse_pin, GPIO.HIGH) + self.current_speed = 0. # END Brake # Set the motor to coast (i.e. Do not provide power to the motor, but still allow it to spin) @@ -63,5 +71,6 @@ class Motor: # Set the direction outputs to coast GPIO.output(self.forward_pin, GPIO.LOW) GPIO.output(self.reverse_pin, GPIO.LOW) + self.current_speed = 0. # END Coast \ No newline at end of file diff --git a/System/results.csv b/System/results.csv new file mode 100644 index 0000000..ca22685 --- /dev/null +++ b/System/results.csv @@ -0,0 +1,252 @@ +this is a test with speed 1 +timestamp,angle(Radians),position(inches),speed(percentage) +21:11:03.518250,3.638602,11.781250,1.000000 +this is a test with speed 2 +timestamp,angle(Radians),position(inches),speed(percentage) +21:11:10.747827,3.141593,0.000000,2.000000 +21:11:10.951560,3.141593,0.000000,2.000000 +21:11:11.155652,3.141593,0.000000,2.000000 +21:11:11.359968,3.141593,0.000000,2.000000 +21:11:11.564011,3.196816,10.648438,2.000000 +this is a test with speed 1 +timestamp,angle(Radians),position(inches),speed(percentage) +21:21:23.365529,3.061826,-12.347656,1.000000 +21:21:23.569516,3.061826,-12.347656,1.000000 +21:21:23.774907,3.061826,-12.291016,1.000000 +21:21:23.978789,3.074097,-12.234375,1.000000 +21:21:24.182513,3.098641,-11.951172,1.000000 +21:21:24.387526,3.172272,-11.328125,1.000000 +21:21:24.593523,3.190680,-10.535156,1.000000 +21:21:24.797276,3.135457,-9.628906,1.000000 +21:21:25.000997,3.092505,-8.666016,1.000000 +21:21:25.204894,3.123185,-7.589844,1.000000 +21:21:25.409312,3.178408,-6.457031,1.000000 +21:21:25.613246,3.178408,-5.494141,1.000000 +21:21:25.816969,3.129321,-4.248047,1.000000 +21:21:26.020770,3.098641,-2.888672,1.000000 +21:21:26.224634,3.117049,-1.642578,1.000000 +21:21:26.428394,3.160000,-0.453125,1.000000 +21:21:26.632123,3.160000,0.623047,1.000000 +21:21:26.836130,3.129321,1.416016,1.000000 +21:21:27.041016,3.123185,2.322266,1.000000 +21:21:27.245016,3.153864,3.398438,1.000000 +21:21:27.448770,3.172272,4.757812,1.000000 +21:21:27.652601,3.147729,6.003906,1.000000 +21:21:27.857510,3.123185,7.250000,1.000000 +21:21:28.061582,3.129321,8.212891,1.000000 +21:21:28.265318,3.153864,9.062500,1.000000 +21:21:28.469456,3.160000,9.798828,1.000000 +21:21:28.674342,3.166136,10.931641,1.000000 +this is a test with speed 2 +timestamp,angle(Radians),position(inches),speed(percentage) +21:21:40.385974,3.123185,-11.328125,2.000000 +21:21:40.589873,3.153864,-11.328125,2.000000 +21:21:40.793628,3.153864,-11.328125,2.000000 +21:21:40.997389,3.123185,-11.271484,2.000000 +21:21:41.201337,3.123185,-11.101562,2.000000 +21:21:41.405074,3.160000,-10.478516,2.000000 +21:21:41.608862,3.172272,-9.685547,2.000000 +21:21:41.812892,3.147729,-8.496094,2.000000 +21:21:42.017833,3.123185,-7.250000,2.000000 +21:21:42.226387,3.123185,-6.117188,2.000000 +21:21:42.430203,3.141593,-5.041016,2.000000 +21:21:42.634253,3.153864,-3.908203,2.000000 +21:21:42.838705,3.147729,-2.605469,2.000000 +21:21:43.042663,3.135457,-1.189453,2.000000 +21:21:43.246393,3.153864,0.396484,2.000000 +21:21:43.450282,3.153864,1.699219,2.000000 +21:21:43.654589,3.147729,3.171875,2.000000 +21:21:43.858462,3.117049,4.701172,2.000000 +21:21:44.062365,3.110913,6.003906,2.000000 +21:21:44.266291,3.147729,7.136719,2.000000 +21:21:44.470675,3.166136,8.156250,2.000000 +21:21:44.675230,3.160000,9.289062,2.000000 +21:21:44.879104,3.123185,10.308594,2.000000 +this is a test with speed 3 +timestamp,angle(Radians),position(inches),speed(percentage) +21:21:56.181311,3.129321,-11.667969,3.000000 +21:21:56.385221,3.135457,-11.667969,3.000000 +21:21:56.588969,3.135457,-11.611328,3.000000 +21:21:56.792985,3.147729,-11.328125,3.000000 +21:21:56.997731,3.172272,-10.705078,3.000000 +21:21:57.201605,3.166136,-9.515625,3.000000 +21:21:57.405341,3.153864,-7.986328,3.000000 +21:21:57.609332,3.129321,-6.400391,3.000000 +21:21:57.813877,3.117049,-4.984375,3.000000 +21:21:58.017821,3.141593,-3.455078,3.000000 +21:21:58.221548,3.153864,-1.585938,3.000000 +21:21:58.425285,3.153864,0.113281,3.000000 +21:21:58.629381,3.141593,1.642578,3.000000 +21:21:58.833311,3.141593,3.341797,3.000000 +21:21:59.037050,3.123185,5.097656,3.000000 +21:21:59.240776,3.123185,6.740234,3.000000 +21:21:59.445332,3.147729,8.156250,3.000000 +21:21:59.649453,3.153864,9.515625,3.000000 +21:21:59.853174,3.141593,10.875000,3.000000 +this is a test with speed 4 +timestamp,angle(Radians),position(inches),speed(percentage) +21:22:10.551392,3.074097,-11.667969,4.000000 +21:22:10.755403,3.166136,-11.611328,4.000000 +21:22:10.959199,3.209088,-11.611328,4.000000 +21:22:11.162979,3.141593,-11.611328,4.000000 +21:22:11.367035,3.067962,-11.667969,4.000000 +21:22:11.571220,3.092505,-11.667969,4.000000 +21:22:11.775098,3.172272,-26.167969,4.000000 +21:22:11.978903,3.190680,-26.111328,4.000000 +21:22:12.182761,3.129321,-26.167969,4.000000 +this is a test with speed 1 +timestamp,angle(Radians),position(inches),speed(percentage) +21:24:03.238594,3.049554,-10.988281,1.000000 +21:24:03.443363,3.319534,-11.384766,1.000000 +21:24:03.647160,3.460661,-11.384766,1.000000 +21:24:03.850915,3.252039,-11.328125,1.000000 +21:24:04.055110,3.055690,-10.421875,1.000000 +21:24:04.259089,3.147729,-8.439453,1.000000 +21:24:04.462815,3.294991,-7.080078,1.000000 +21:24:04.666720,3.294991,-6.287109,1.000000 +21:24:04.871045,3.209088,-5.210938,1.000000 +21:24:05.075400,3.166136,-3.738281,1.000000 +21:24:05.279280,3.215224,-1.812500,1.000000 +21:24:05.483051,3.270447,-0.056641,1.000000 +21:24:05.687202,3.258175,1.472656,1.000000 +21:24:05.891495,3.196816,3.171875,1.000000 +21:24:06.095450,3.172272,5.154297,1.000000 +21:24:06.299177,3.202952,6.853516,1.000000 +21:24:06.503022,3.227496,7.986328,1.000000 +21:24:06.707304,3.221360,8.779297,1.000000 +21:24:06.911174,3.209088,9.515625,1.000000 +21:24:07.115038,3.227496,10.535156,1.000000 +this is a test with speed 2 +timestamp,angle(Radians),position(inches),speed(percentage) +21:24:17.195756,3.288855,-26.621094,2.000000 +21:24:17.400051,3.233632,-26.621094,2.000000 +21:24:17.603796,3.160000,-26.564453,2.000000 +21:24:17.807579,3.258175,-25.261719,2.000000 +21:24:18.011603,3.313399,-23.505859,2.000000 +21:24:18.216375,3.202952,-22.373047,2.000000 +21:24:18.422944,3.086369,-21.523438,2.000000 +21:24:18.627284,3.166136,-20.900391,2.000000 +21:24:18.831221,3.331806,-19.937500,2.000000 +21:24:19.035149,3.362486,-18.521484,2.000000 +21:24:19.238927,3.196816,-16.708984,2.000000 +21:24:19.443200,3.067962,-14.953125,2.000000 +21:24:19.647538,3.153864,-13.650391,2.000000 +21:24:19.852128,3.319534,-12.404297,2.000000 +21:24:20.055988,3.325670,-11.214844,2.000000 +21:24:20.259682,3.209088,-9.572266,2.000000 +21:24:20.463588,3.110913,-7.873047,2.000000 +21:24:20.667910,3.160000,-6.626953,2.000000 +21:24:20.871916,3.270447,-5.607422,2.000000 +21:24:21.075676,3.301127,-4.474609,2.000000 +21:24:21.279456,3.209088,-3.341797,2.000000 +21:24:21.483292,3.129321,-2.208984,2.000000 +21:24:21.687757,3.123185,-2.039062,2.000000 +21:24:21.891745,3.245903,-2.039062,2.000000 +21:24:22.095769,3.325670,-2.039062,2.000000 +21:24:22.299703,3.258175,-2.095703,2.000000 +21:24:22.503702,3.202952,-2.095703,2.000000 +21:24:22.707592,3.270447,-2.095703,2.000000 +21:24:22.911564,3.276583,-2.208984,2.000000 +21:24:23.115698,3.264311,-3.681641,2.000000 +21:24:23.320113,3.307263,-6.060547,2.000000 +21:24:23.523990,3.368622,-8.835938,2.000000 +21:24:23.727764,3.423845,-12.177734,2.000000 +21:24:23.931581,3.479068,-14.896484,2.000000 +21:24:24.135508,3.491340,-17.162109,2.000000 +21:24:24.339394,3.331806,-17.445312,2.000000 +21:24:24.543121,3.184544,-17.388672,2.000000 +21:24:24.747104,3.141593,-17.388672,2.000000 +21:24:24.951503,3.209088,-17.388672,2.000000 +21:24:25.155448,3.282719,-17.388672,2.000000 +21:24:25.359181,3.258175,-17.388672,2.000000 +21:24:25.563220,3.184544,-17.445312,2.000000 +21:24:25.767602,3.160000,-17.388672,2.000000 +21:24:25.971902,3.221360,-17.388672,2.000000 +21:24:26.175822,3.270447,-17.388672,2.000000 +21:24:26.379473,3.239767,-17.445312,2.000000 +21:24:26.583204,3.184544,-17.388672,2.000000 +21:24:26.787312,3.178408,-17.388672,2.000000 +21:24:26.991191,3.227496,-17.388672,2.000000 +21:24:27.195040,3.258175,-17.388672,2.000000 +21:24:27.398920,3.233632,-17.445312,2.000000 +21:24:27.602646,3.190680,-17.388672,2.000000 +21:24:27.806773,3.196816,-17.445312,2.000000 +21:24:28.010824,3.227496,-17.445312,2.000000 +21:24:28.214705,3.239767,-17.388672,2.000000 +21:24:28.418434,3.215224,-17.445312,2.000000 +21:24:28.622173,3.196816,-17.445312,2.000000 +21:24:28.827388,3.209088,-17.445312,2.000000 +21:24:29.031949,3.227496,-17.388672,2.000000 +21:24:29.235813,3.227496,-17.388672,2.000000 +21:24:29.439567,3.215224,-17.388672,2.000000 +21:24:29.643433,3.209088,-17.445312,2.000000 +21:24:29.847229,3.221360,-17.388672,2.000000 +21:24:30.051008,3.221360,-17.388672,2.000000 +21:24:30.254897,3.221360,-17.445312,2.000000 +21:24:30.460323,3.215224,-17.445312,2.000000 +21:24:30.664998,3.215224,-17.445312,2.000000 +21:24:30.868735,3.215224,-17.388672,2.000000 +21:24:31.072555,3.221360,-17.388672,2.000000 +21:24:31.278097,3.221360,-17.388672,2.000000 +21:24:31.482317,3.215224,-17.388672,2.000000 +21:24:31.686053,3.221360,-17.388672,2.000000 +21:24:31.889814,3.215224,-17.445312,2.000000 +21:24:32.094156,3.215224,-17.445312,2.000000 +21:24:32.298057,3.215224,-17.445312,2.000000 +21:24:32.501811,3.215224,-17.445312,2.000000 +21:24:32.705567,3.209088,-17.558594,2.000000 +21:24:32.909636,3.123185,-19.031250,2.000000 +21:24:33.113681,3.129321,-20.957031,2.000000 +21:24:33.317471,3.258175,-22.882812,2.000000 +21:24:33.521209,3.331806,-24.808594,2.000000 +21:24:33.725343,3.270447,-26.224609,2.000000 +21:24:33.929347,3.135457,-27.414062,2.000000 +21:24:34.133069,3.141593,-28.263672,2.000000 +21:24:34.336813,3.270447,-28.830078,2.000000 +21:24:34.540822,3.350214,-28.773438,2.000000 +21:24:34.745675,3.368622,-27.074219,2.000000 +21:24:34.949791,3.233632,-24.242188,2.000000 +21:24:35.153530,3.061826,-21.353516,2.000000 +21:24:35.357278,3.037282,-19.824219,2.000000 +21:24:35.561108,3.209088,-18.748047,2.000000 +21:24:35.765374,3.362486,-17.785156,2.000000 +21:24:35.969290,3.301127,-16.935547,2.000000 +21:24:36.173039,3.080233,-16.539062,2.000000 +21:24:36.377081,3.049554,-16.425781,2.000000 +21:24:36.580936,3.239767,-16.425781,2.000000 +21:24:36.785009,3.380894,-16.425781,2.000000 +21:24:36.988996,3.294991,-16.482422,2.000000 +21:24:37.192991,3.104777,-16.425781,2.000000 +21:24:37.396751,3.074097,-16.425781,2.000000 +21:24:37.600523,3.239767,-16.425781,2.000000 +21:24:37.804401,3.362486,-16.425781,2.000000 +21:24:38.008162,3.276583,-16.425781,2.000000 +21:24:38.212000,3.110913,-16.425781,2.000000 +21:24:38.416104,3.098641,-16.425781,2.000000 +21:24:38.619845,3.252039,-16.425781,2.000000 +21:24:38.823609,3.344078,-16.425781,2.000000 +21:24:39.027425,3.258175,-16.425781,2.000000 +21:24:39.231822,3.117049,-16.425781,2.000000 +21:24:39.435720,3.117049,-16.425781,2.000000 +this is a test with speed 1 +timestamp,angle(Radians),position(inches),speed(percentage) +21:26:03.992735,3.153864,-11.611328,1.000000 +21:26:04.196730,3.086369,-11.611328,1.000000 +21:26:04.400491,3.055690,-10.818359,1.000000 +21:26:04.604225,3.055690,-9.968750,1.000000 +21:26:04.807985,3.086369,-9.119141,1.000000 +21:26:05.011982,3.110913,-8.269531,1.000000 +21:26:05.215941,3.080233,-7.419922,1.000000 +21:26:05.419661,3.043418,-6.683594,1.000000 +21:26:05.623503,3.055690,-6.003906,1.000000 +21:26:05.827343,3.104777,-5.097656,1.000000 +21:26:06.032396,3.123185,-4.021484,1.000000 +21:26:06.236582,3.086369,-2.548828,1.000000 +21:26:06.440336,3.067962,-0.849609,1.000000 +21:26:06.644314,3.098641,1.019531,1.000000 +21:26:06.848124,3.110913,2.775391,1.000000 +21:26:07.051824,3.067962,4.701172,1.000000 +21:26:07.256424,3.055690,6.853516,1.000000 +21:26:07.460299,3.049554,8.269531,1.000000 +21:26:07.664164,3.055690,9.232422,1.000000 +21:26:07.867919,3.086369,10.195312,1.000000 diff --git a/System/samTestScript.py b/System/samTestScript.py new file mode 100644 index 0000000..5f9312f --- /dev/null +++ b/System/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/swingUp.py b/System/swingUp.py old mode 100755 new mode 100644 index f14ef37..fb5d4c0 --- a/System/swingUp.py +++ b/System/swingUp.py @@ -20,16 +20,16 @@ class SwingUpEnv(gym.Env): Observation: Type: Box(4) - Num Observation Min Max - 0 Cart Position -4.8 4.8 - 1 Cart Velocity -Inf Inf - 2 Pole Angle -Inf Inf - 3 Pole Velocity At Tip -Inf Inf + Num Observation Min Max + 0 Cart Position -4.8 4.8 + 1 Cart Velocity -Inf Inf + 2 Pole Angle -Inf Inf + 3 Pole Velocity At Tip -Inf Inf Actions: Type: Box(1) - Num Action Min Max - 0 Push cart -1 1 + Num Action Min Max + 0 Push cart -1 1 Note: The amount the velocity that is reduced or increased is not fixed; it depends on the angle the pole is pointing. This is because the center of gravity of the pole increases the amount of energy needed to move the cart underneath it @@ -94,7 +94,7 @@ class SwingUpEnv(gym.Env): state = self.state x, x_dot, theta, theta_dot = state force = self.force_mag * action[0] - + costheta = math.cos(theta) sintheta = math.sin(theta) diff --git a/System/system.py b/System/system.py old mode 100755 new mode 100644 index 7b2ffcf..ff7c778 --- a/System/system.py +++ b/System/system.py @@ -7,6 +7,14 @@ from time import sleep import RPi.GPIO as GPIO import sys import os +count2 = 0 +## +import cmath +## + + + + from threading import Thread, Lock # IO pin definitions @@ -15,19 +23,26 @@ motor_speed_pin = 17 motor_forward_pin = 27 motor_reverse_pin = 22 ### Encoder pins (shared by both encoders) -encoder_clock_pin = 2 -encoder_data_pin = 3 +encoder_clock_pin = 3 +encoder_data_pin = 2 ### Angular encoder pins encoder_angular_cs_pin = 4 ### Linear encoder pins -encoder_linear_cs_pin = 14 +encoder_linear_cs_pin = 23 ### Limit switch pins (configured to PULLUP) -limit_negative_pin = 19 -limit_positive_pin = 26 + +#FLIPPING THESE BELOW +#limit_negative_pin = 19 +#limit_positive_pin = 26 +limit_negative_pin = 26 +limit_positive_pin = 19 # System parameters system_max_x = 16.5 system_min_x = -16.5 +downloads_reference_dest = "." +default_results_fileName = "results.csv" + # System Class # This is the primary interface a student will use to control the pendulum. @@ -74,9 +89,11 @@ class System: # Create and setup results file (to be sent back to the server and displayed/downloaded to the user) # Results file is a CSV with the following entries: angle, position, speed - self.result_filename = "Results/" + os.path.basename(sys.argv[0]).split('.')[0] + "_results.csv" - - result_file = open(self.result_filename, "w+") + self.result_filename = downloads_reference_dest + "/Downloads/" + default_results_fileName + print("self.result_filename") + print(self.result_filename) + # Open the file for write mode. The file contents will get cleared and overwritten + result_file = open(self.result_filename, "w") result_file.write("timestamp,angle(" + angular_units + "),position(inches),speed(percentage)\n") result_file.close() @@ -97,6 +114,7 @@ class System: # END __del__() def initialize(self): + print("begin initialize") # Temporarily disable the limit switch interrupts: we do not want the program to exit if the switch is triggered GPIO.remove_event_detect(limit_negative_pin) GPIO.remove_event_detect(limit_positive_pin) @@ -106,8 +124,10 @@ class System: pressed = True while pressed != False: pressed = GPIO.input(limit_negative_pin) + #print(pressed) sleep(0.01) self.motor.brake() + print("hit negative end stop") # Set zero at the negative end of the track for easy reference in determining the extent self.encoder_linear.set_zero() sleep(1) @@ -119,6 +139,7 @@ class System: pressed = GPIO.input(limit_positive_pin) sleep(0.01) self.motor.brake() + print("hit positive endstop") # Get the current position (the extent of the track) extent = self.linear_position # Move back towards the center until we reach position extent/2 @@ -127,6 +148,7 @@ class System: self.motor.move(-4) while position >= (extent / 2.): position = self.linear_position + #print(position) sleep(0.015) self.motor.brake() # Set zero again: this is the real zero @@ -134,6 +156,7 @@ class System: # Re-enable the limit switch interrupts GPIO.add_event_detect(limit_negative_pin, GPIO.FALLING, callback=self.negative_limit_callback, bouncetime=300) GPIO.add_event_detect(limit_positive_pin, GPIO.FALLING, callback=self.positive_limit_callback, bouncetime=300) + print("Finsihed the initaialize func") # END initialize # Return home, cleanup IO. This should be called when exiting the program @@ -308,9 +331,32 @@ class Linear_Encoder: # Reset the internal position counter self.rotations = 0. self.last_position = 0. + ###sam debug + self.last_position_filter = 0. + ###sam debug def read_position(self): + ###sam debug + global count2 + test = 0 + count = 0 + while test == 0: + count += 1 + position = float(self.encoder.read_position('Raw') & 0b1111111100) + complex_current = cmath.exp(((position*2*math.pi)/1023)*1j) + complex_last = cmath.exp(((self.last_position*2*math.pi)/1023)*1j) + distance = math.sqrt((complex_current.real-complex_last.real)**2 + (complex_current.imag-complex_last.imag)**2) + if distance < 0.5 or count > 5: #this corresponds to a difference of 50 in the raw encoder position + test = 1 + #print(count) + count2 = count2 + count - 1 + print("global count") + print(count2) + ###sam debug + # Read the position of the encoder (apply a noise filter, we don't need that much precision here) - position = float(self.encoder.read_position('Raw') & 0b1111111100) + #position = float(self.encoder.read_position('Raw') & 0b1111111100) + + # Compare to last known position # NOTE: For now, assume that we are moving the smallest possible distance (i.e. 5 -> 1 is -4, not 1020) if (position - self.last_position) > 768.: @@ -322,4 +368,6 @@ class Linear_Encoder: self.last_position = position # compute the position based on the system parameters # linear position = (2pi*r)(n) + (2pi*r)(position/1024) = (2pi*r)(n + position/1024) = (pi*d)(n + position/1024) - return (self.PROPORTION)*(self.rotations + position/1024.) + print("sled positin in inches") + print(self.PROPORTION*(self.rotations + position/1024.)) + return((self.PROPORTION)*(self.rotations + position/1024.)) diff --git a/System/system_swingup_test.py b/System/system_swingup_test.py old mode 100755 new mode 100644 diff --git a/System/system_swingup_test_2.py b/System/system_swingup_test_2.py old mode 100755 new mode 100644 index cb646ef..fc02ed6 --- a/System/system_swingup_test_2.py +++ b/System/system_swingup_test_2.py @@ -6,7 +6,14 @@ import math from gym import spaces, logger from gym.utils import seeding +### +import sys +sys.path.insert(0, '/home/pi/pendulum/System') +### + + from System.system import System +#from . import System import time from sys import exit @@ -103,14 +110,20 @@ class SwingUpEnv(): self.last_time = current_time new_theta, new_x = self.sys.measure() - theta_dot = (new_theta - theta) / tau + if (theta >= 0 and theta < math.pi/2.) and (new_theta > 3.*math.pi/2.): + theta_dot = (new_theta - (theta + 2.*math.pi)) / tau + elif (new_theta >= 0 and new_theta < math.pi/2.) and (theta > 3.*math.pi/2.): + theta_dot = ((new_theta + 2.*math.pi) - theta) / tau + else: + theta_dot = (new_theta - theta) / tau x_dot = (new_x - x) / tau self.state = (new_x, x_dot, new_theta, theta_dot) self.sys.add_results(new_theta, new_x, force) - done = theta_dot < -self.theta_dot_threshold \ + '''done = theta_dot < -self.theta_dot_threshold \ or theta_dot > self.theta_dot_threshold \ - or self.done == True + or self.done == True''' + done = self.done '''done = x < -self.x_threshold \ or x > self.x_threshold \ @@ -325,7 +338,7 @@ gamma = .95 agent = deepQagent(5,numActions,20,2,epsilon=5e-2,gamma=gamma,batch_size=20, c= 100,alpha=1e-4) -maxSteps = 2e5 +maxSteps = 2e6 # This is a helper to deal with the fact that x[2] is actually an angle x_to_y = lambda x : np.array([x[0], x[1], np.cos(x[2]), np.sin(x[2]), x[3]]) @@ -379,4 +392,4 @@ except: exit(-1) finally: env.end() - exit(0) \ No newline at end of file + exit(0) diff --git a/System/test_Encoder.py b/System/test_Encoder.py old mode 100755 new mode 100644 index d0b7ef8..bb6e3e4 --- a/System/test_Encoder.py +++ b/System/test_Encoder.py @@ -3,9 +3,9 @@ import time import RPi.GPIO as GPIO # Decide which pins to hook up to on the Pi before running -clk_pin = 2 -cs_pin = 4 -data_pin = 3 +clk_pin = 3 +cs_pin = 23 +data_pin = 2 e = Encoder(clk_pin, cs_pin, data_pin) e.set_zero() @@ -19,3 +19,5 @@ except: finally: # Perform GPIO cleanup. Things may get weird otherwise... GPIO.cleanup() + + diff --git a/System/test_Motor.py b/System/test_Motor.py old mode 100755 new mode 100644 diff --git a/System/test_Return_Home.py b/System/test_Return_Home.py old mode 100755 new mode 100644 index 244f99f..04e19cb --- a/System/test_Return_Home.py +++ b/System/test_Return_Home.py @@ -2,8 +2,11 @@ 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)) diff --git a/System/test_System.py b/System/test_System.py old mode 100755 new mode 100644 diff --git a/Web/PI/PI.py b/Web/PI/PI.py old mode 100755 new mode 100644 diff --git a/Web/PI/Results/PLACEHOLDER.txt b/Web/PI/Results/PLACEHOLDER.txt old mode 100755 new mode 100644 diff --git a/Web/PI/Uploads/PLACEHOLDER b/Web/PI/Uploads/PLACEHOLDER old mode 100755 new mode 100644 diff --git a/Web/PI/test2.py b/Web/PI/test2.py old mode 100755 new mode 100644 diff --git a/Web/Server/Results/PLACEHOLDER b/Web/Server/Results/PLACEHOLDER old mode 100755 new mode 100644 diff --git a/Web/Server/Results/results.csv b/Web/Server/Results/results.csv old mode 100755 new mode 100644 diff --git a/Web/Server/Server.py b/Web/Server/Server.py old mode 100755 new mode 100644 diff --git a/Web/Server/static/Server.css b/Web/Server/static/Server.css old mode 100755 new mode 100644 diff --git a/Web/Server/static/Server.js b/Web/Server/static/Server.js old mode 100755 new mode 100644 diff --git a/Web/Server/templates/base.html b/Web/Server/templates/base.html old mode 100755 new mode 100644 diff --git a/Web/Server/templates/index.html b/Web/Server/templates/index.html old mode 100755 new mode 100644 diff --git a/Web/Server/templates/results.html b/Web/Server/templates/results.html old mode 100755 new mode 100644 diff --git a/Web/requirements.txt b/Web/requirements.txt old mode 100755 new mode 100644 diff --git a/Web/test.py b/Web/test.py old mode 100755 new mode 100644 diff --git a/test_script_results.csv b/test_script_results.csv new file mode 100644 index 0000000..ea92e7c --- /dev/null +++ b/test_script_results.csv @@ -0,0 +1 @@ +Negative hardware limit has been reached! -- cgit v1.2.3