forked from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#1 from USERNAME88831/debugFeatures
Adding debug features to the program
- Loading branch information
Showing
2 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# TODO: Create features that are useful in debug mode. | ||
from pybricks.tools import DataLog, StopWatch, wait | ||
from threading import * | ||
|
||
|
||
class Logger: | ||
def __init__(self, motor, sensorFunction, leftMotor, rightMotor, thirdMotor): # TODO: Change name when we find the use of the third motor | ||
""" | ||
The logger logs everything that the robot is doing in a file \n | ||
""" | ||
self.motor = motor | ||
self.sensorFunction = sensorFunction | ||
self.leftMotor = leftMotor | ||
self.rightMotor = rightMotor | ||
self.thirdMotor = thirdMotor | ||
|
||
self.data = DataLog("leftSensorDistance", | ||
"rightSensorDistance", | ||
"frontSensorDistance", | ||
"colorSensorReflection" | ||
"leftWheelAngle", # Individual wheel | ||
"rightWheelAngle", # Individual wheel | ||
"thirdMotorAngle", # TODO: Change name when we find the use of the third motor | ||
"robotSpeed" | ||
) | ||
|
||
self.thread = Thread(target=self._logFunc) | ||
self.thread.setDaemon(True) # Since it runs in the background, it will immediatly end when the non-dameon threads end. | ||
|
||
|
||
|
||
def _logFunc(self): | ||
""" | ||
this function is to log stuff during the entire program | ||
""" | ||
while True: | ||
leftSide, rightSide, frontSide, lightReflected = self.sensorFunction() | ||
leftWheelAngle = self.leftMotor.angle() | ||
rightWheelAngle = self.rightMotor.angle() | ||
thirdMotorAngle = self.thirdMotor.angle() | ||
_, robotSpeed, _, _ = self.motor | ||
self.data.log(leftSide, | ||
rightSide, | ||
frontSide, | ||
lightReflected, | ||
leftWheelAngle, | ||
rightWheelAngle, | ||
thirdMotorAngle, | ||
robotSpeed) | ||
|
||
def startLogging(self): | ||
self.thread.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters