aboutsummaryrefslogtreecommitdiffstats
path: root/System/system.py
diff options
context:
space:
mode:
authorRaspberry Pi <raspberrypi@umn.edu>2019-11-26 19:55:38 -0600
committerRaspberry Pi <raspberrypi@umn.edu>2019-11-26 19:55:38 -0600
commit50c1d34f709997fbac75e94940d247e6c48ef45a (patch)
tree9928a0b8bf8d04aba7c3fe8ef2db315fea20cccd /System/system.py
parentMerge remote-tracking branch 'origin/library_encoder_thread' (diff)
downloadee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.tar
ee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.tar.gz
ee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.tar.bz2
ee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.tar.lz
ee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.tar.xz
ee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.tar.zst
ee4511w-50c1d34f709997fbac75e94940d247e6c48ef45a.zip
Improve logging: add timestamps for each log. Add a new function to add other messages to the log file. Update swingup test to use new logging behavior.
Diffstat (limited to 'System/system.py')
-rw-r--r--System/system.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/System/system.py b/System/system.py
index 63d0ecc..8dd9f38 100644
--- a/System/system.py
+++ b/System/system.py
@@ -77,7 +77,7 @@ class System:
self.result_filename = "Results/" + os.path.basename(sys.argv[0]).split('.')[0] + "_results.csv"
result_file = open(self.result_filename, "w+")
- result_file.write("angle(" + angular_units + "),position(inches),speed(percentage)\n")
+ result_file.write("timestamp,angle(" + angular_units + "),position(inches),speed(percentage)\n")
result_file.close()
# Setup a thread to constantly be measuring encoder positions
@@ -173,7 +173,7 @@ class System:
self.motor.brake()
# Print negative soft limit violation to the results file.
result_file = open(self.result_filename, "a")
- result_file.write("Negative software limit %f has been reached!" % self.negative_soft_limit)
+ result_file.write("Negative software limit %f has been reached!\n" % self.negative_soft_limit)
result_file.close()
# Fire the limit trigger method
self.sw_limit_routine()
@@ -185,7 +185,7 @@ class System:
self.motor.brake()
# Print positive soft limit violation to the results file.
result_file = open(self.result_filename, "a")
- result_file.write("Positive software limit %f has been reached!" % self.positive_soft_limit)
+ result_file.write("Positive software limit %f has been reached!\n" % self.positive_soft_limit)
result_file.close()
# Fire the limit trigger method
self.sw_limit_routine()
@@ -220,13 +220,24 @@ class System:
# open the results file
result_file = open(self.result_filename, "a")
# Write the results
- result_file.write("%f," % angle) # Write angle
- result_file.write("%f," % position) # Write position
- result_file.write("%f\n" % speed) # Write speed (end of line)
+ result_file.write("%s," % datetime.now().strftime("%H:%M:%S.%f")) # Write current time
+ result_file.write("%f," % angle) # Write angle
+ result_file.write("%f," % position) # Write position
+ result_file.write("%f\n" % speed) # Write speed (end of line)
# Close the results file
result_file.close()
# END add_results
+ def add_log(self, message):
+ # open the results file
+ result_file = open(self.result_filename, "a")
+ # Write the log
+ result_file.write("%s\n" % message)
+ # re-write the csv headers for next logging
+ result_file.write("timestamp,angle(" + self.angular_units + "),position(inches),speed(percentage)\n")
+ # Close the results file
+ result_file.close()
+
# Go back to the zero position (linear) so that the next execution starts in the correct place.
def return_home(self):
position = self.linear_position