Skip to content

Commit

Permalink
Update robot.__init__
Browse files Browse the repository at this point in the history
Fix minor bug in sleep and gyro methods
  • Loading branch information
dmaccarthy committed Nov 22, 2023
1 parent a332d9b commit ebf13ce
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions sc8pr/robot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def run(self):
if self.log:
print('{} is running in thread {}.'.format(*args), file=stderr)
try:
r._uptime = 0
while r._startup: r.sleep()
# r._startTime = time()
r._uptime = 0
r.brain()
if hasattr(r, "shutdown"): r.shutdown()
r._uptime = None
Expand Down Expand Up @@ -105,7 +105,7 @@ def gyro(self):

@gyro.setter
def gyro(self, g):
self._gyro = (g - self.angle) % 360
self._gyro = (self.angle - g) % 360

@property
def stopped(self):
Expand Down Expand Up @@ -136,14 +136,21 @@ def updateSensors(self, wait=None):
return self

def sleep(self, t=None):
"Sleep for the specified time"
"Sleep for the specified time; updated v3.0.4"
if not self.active: raise InactiveError()
fTime = 1 / self.sketch.frameRate
if t:
t1 = self._uptime + t
while t1 - self.uptime > fTime:
sleep(t)
else: sleep(fTime)
dt = 1 / self.sketch.frameRate
t = self.uptime + (t if t else dt)
while self.uptime < t: sleep(dt)

# def sleep(self, t=None):
# "Sleep for the specified time"
# if not self.active: raise InactiveError()
# fTime = 1 / self.sketch.frameRate
# if t:
# t1 = self._uptime + t
# while t1 - self.uptime > fTime:
# sleep(t)
# else: sleep(fTime)

@property
def motors(self): return self._motors
Expand Down

0 comments on commit ebf13ce

Please sign in to comment.