Skip to content

Commit

Permalink
Cut out a lot of now-useless code, commented stuff better, especially…
Browse files Browse the repository at this point in the history
… robot.py
  • Loading branch information
computer-whisperer committed Nov 6, 2014
1 parent 3af3345 commit d66bef5
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 294 deletions.
2 changes: 1 addition & 1 deletion framework/datastreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def push(self, data, subsystem, autolock=False):

#Check to see if we should automatically lock the stream to subsystem
if autolock:
self._lock = subsystem
self.lock(subsystem)

#Check lock
if self._lock is not None and self._lock is not subsystem:
Expand Down
9 changes: 7 additions & 2 deletions framework/events.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""
This is an event system
This is an event system. Modules can add callbacks to events, which will be run in a new thread once triggered.
This is the primary mechanism for starting and stopping run loops.
On the flip side, events can be either "triggered" which is a one-time call (For example: shoot_cannon or reset_gyro),
or they can be started and then stopped, for events with duration (For example: run, teleoperated, or enabled).
The main difference is that when modules are freshly loaded, the refresh_events method is called, which then finds all
of the "started" events and triggers them for the new module.
"""

import logging
import threading
import framework.module_engine
from framework.record import recorder

__author__ = 'christian'

Expand Down
4 changes: 2 additions & 2 deletions framework/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
root_dir = ""

#The directory to store all logs and recordings from this run session
log_dir = os.path.join(root_dir, "recs")
log_dir = os.path.join(root_dir, "logs")

#The log file, which is a dump of all console output
log_file = os.path.join(log_dir, "main.log")
Expand All @@ -34,7 +34,7 @@ def gen_paths():
global log_dir, events_file, log_file, datastream_dir

#The root log directory
log_root_dir = os.path.join(root_dir, "recs")
log_root_dir = os.path.join(root_dir, "logs")

#Figure out what log file index we should use
#The log file index is a 4-digit number corresponding to an unused log folder
Expand Down
1 change: 0 additions & 1 deletion framework/record/__init__.py

This file was deleted.

109 changes: 0 additions & 109 deletions framework/record/playback.py

This file was deleted.

55 changes: 0 additions & 55 deletions framework/record/recorder.py

This file was deleted.

6 changes: 6 additions & 0 deletions framework/wpiwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def init_wpilib_refrence(self, name, port):

def set_semi_period(self):
#TODO Remove this try/except once pyfrc is updated with my commit
#I submitted a patch to pyfrc with the (previously missing) function stub. But it appears that it may not have fully propogated to the
# public release yet.
try:
self.wpiobject.SetSemiPeriodMode(True)
except AttributeError:
Expand Down Expand Up @@ -340,14 +342,18 @@ def init_wpilib_refrence(self, name, port):

def get(self):
angle = self.wpiobject.GetAngle()

#Run the value by the dog
self.statmsg, self.status = self.dog.sniff(angle)

#If the dog says it is a bad value, raise an error
if not self.status:
raise DeviceInErrorStateError(self.statmsg)
else:
return angle

def reset(self):
#Let the dog know, so he doesen't alert when the value jumps to zero
self.dog.reset()
return self.wpiobject.Reset()

Expand Down
14 changes: 7 additions & 7 deletions modules/christian/auto/1-ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
#Register autonomous event callback
events.add_callback("autonomous", self.subsystem, callback=self.run, inverse_callback=self.stop)

class EndAuto(Exception):
class EndAutoError(Exception):
"""This is just a way to stop the autonomous routine at any time if we are told to"""
pass

Expand All @@ -42,14 +42,13 @@ def run(self):
config = self.autonomous_config.get({"second_shot": 7, "first_shot": 12, "distance_from_tape": 3, "start_position": 1})

#Configure navigator
self.navigator_config.push({"max_values": [5, 4], "cycles_per_second": 10, "precision": .2}, self.subsystem, autolock=True)
self.navigator_config.push({"max_values": [5, 5], "cycles_per_second": 10, "precision": .2}, self.subsystem, autolock=True)

#Mark drivetrain
events.trigger_event("drivetrain.mark", self.subsystem)

#Drop Arms
self.intake_stream.lock(self.subsystem)
self.intake_stream.push({"arms_down": True, "flipper_out": True, "intake_motor": 0}, self.subsystem)
self.intake_stream.push({"arms_down": True, "flipper_out": True, "intake_motor": 0}, self.subsystem, autolock=True)

#Trigger Vision
wpilib.SmartDashboard.PutNumber("hot goal", 0)
Expand All @@ -65,7 +64,7 @@ def run(self):
# or the light sensor reports that we are on the line.
while self.navigator_status.get(1) is 0 and time.time() - start_time < 5 and self.light_sensor.get() < 2.5:
if self.stop_flag:
raise self.EndAuto()
raise self.EndAutoError()
time.sleep(.2)

#Stop the bot
Expand Down Expand Up @@ -98,7 +97,7 @@ def run(self):
while self.navigator_status.get(1) is 0 and time.time() - start_time < 5 and abs(pos["distance"] - shot_point) > 1:
pos = self.drivetrain_state_stream.get({"distance": 0})
if self.stop_flag:
raise self.EndAuto()
raise self.EndAutoError()
time.sleep(.1)

#Shoot
Expand All @@ -107,14 +106,15 @@ def run(self):
#Wait for shooting to end
time.sleep(.5)

except self.EndAuto:
except self.EndAutoError:
pass

#STOP!!!
events.stop_event("navigator.run", self.subsystem)

def stop(self):
logging.info("Stopping autonomous")
events.stop_event("navigator.run", self.subsystem)
self.stop_flag = True


Expand Down
Loading

0 comments on commit d66bef5

Please sign in to comment.