Skip to content

Commit

Permalink
Merge pull request github#1 from USERNAME88831/debugFeatures
Browse files Browse the repository at this point in the history
Adding debug features to the program
  • Loading branch information
USERNAME88831 authored Feb 26, 2023
2 parents 9c25628 + 45017c6 commit 2aeb178
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
53 changes: 53 additions & 0 deletions debugFeatures.py
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()
6 changes: 3 additions & 3 deletions robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile

from debugFeatures import Logger



Expand All @@ -30,7 +30,7 @@ def __init__(self, M1Port, M2Port, M3Port, ColorSensorPort, FrontSensorPort,

self.debugMode = debugMode # enables certain features to test the robot.


self.logger = Logger(self.motor, self.sensorOutput, self.LeftWheel, self.RightWheel, self.m3)

self.brick = EV3Brick()
self.slowDownDistance = 500 # slows down when it is near this distance
Expand All @@ -39,7 +39,7 @@ def __init__(self, M1Port, M2Port, M3Port, ColorSensorPort, FrontSensorPort,
self.LeftWheel = Motor(M1Port)
self.RightWheel = Motor(M2Port)
self.motor = DriveBase(self.LeftWheel, self.RightWheel, self.wheelDiameter, self.axleTrack) # The class used to drive robots
self.M3 = Motor(M3Port) # TODO: find use of the third motor
self.m3 = Motor(M3Port) # TODO: find use of the third motor
self.colorSensor = ColorSensor(ColorSensorPort) # Should be used to track the lines
self.frontSensor = UltrasonicSensor(FrontSensorPort)
self.leftSensor = UltrasonicSensor(LeftSensorPort)
Expand Down

0 comments on commit 2aeb178

Please sign in to comment.