def run(modifier): """ Given a callback, perform the following sequence: * RTDB get simulation scene * modify it using callback, validate * RTDB put simulation scene """ # Create instance of RtDB2Store and read databases from disk path = RTDB2_DEFAULT_PATH agent = 0 key = "SIMULATION_SCENE" rtdb2Store = RtDB2Store(path, False) # don't start in read-only # Get current value item = rtdb2Store.get(agent, key, timeout=False) # Modify value modifier(item.value) # Sanity checks validateScene(item.value) # Store and finish rtdb2Store.put(agent, key, item.value) rtdb2Store.closeAll()
def __init__(self, path, agent, key): self.agent = agent self.key = key # Create instance of RtDB2Store and read databases from disk self.rtdb2Store = RtDB2Store(path, False) # don't start in read-only
def minimum_score(self, team, expected_str): rtdb = RtDB2Store(RTDB2_DEFAULT_PATH, False) actual = rtdb.get(0, "MATCH_STATE").value["goalsOwn"] expected = int(expected_str) if actual < expected: raise AssertionError( "Score too low. Actual score: {0} Expected minimum score: {1}" .format(actual, expected))
def __init__(self, robotId): self.rtdb2Store = RtDB2Store(RTDB2_DEFAULT_PATH, True) # read mode self.rtdb2Store.refresh_rtdb_instances() self.robotId = robotId self.robotStatus = {} self.robotPosition = {} self.robotVelocity = {} self.robotHasBall = {} self.frequency = 20 self.stopFlag = False self.updateThread = None self.ball = None
def run(args): # Load the yaml f = open(args.yamlfile, mode='r') y = yaml.load(f.read(), Loader=yaml.FullLoader) f.close() # Create instance of RtDB2Store and read databases from disk rtdb2Store = RtDB2Store(args.path, False) # don't start in read-only # Get current value # It is typically only written once when a process initializes, so do not use timeout flag item = rtdb2Store.get(args.agent, args.key, timeout=None) if item is None: # It is possible the key does not exist yet. # So write the the entire YAML to RtDB. print( "WARNING: Failed to get key='{}' with agent='{}' from RtDB. Assuming key does not yet exist, and writing new values to RtDB." .format(args.key, args.agent)) itemvalue = {} SmartAssignment(itemvalue, y, hook=enumConverter, targetName="rtdb", sourceName="yaml", strict=False) # Store key in RtDB rtdb2Store.put(args.agent, args.key, itemvalue) else: # Assign yaml values, like # item.value = y # but with more features: # * type checks # * completeness checks # * enum/string conversions SmartAssignment(item.value, y, hook=enumConverter, targetName="rtdb", sourceName="yaml", strict=(not args.nostrict)) # Store key back to RtDB rtdb2Store.put(args.agent, args.key, item.value) # cleanup rtdb2Store.closeAll()
def __init__(self): BallData.__init__(self) self.rtdb2Store = RtDB2Store(RTDB2_DEFAULT_PATH) self.key2function = {} self.key2function["BALL_CANDIDATES_FCS"] = self.feedBallCandidates self.key2function["BALLS"] = self.feedBallResults self.key2function["DIAG_WORLDMODEL_LOCAL"] = self.feedBallDiagnostics self.key2function["MATCH_STATE"] = self.feedMatchState self.lastItem = {} # to detect change in state self.onChange = None # since we spawn a thread while also having a GUI active, # we must setup a signal handler for proper shutdown self.ok = True #signal.signal(signal.SIGINT, self.signalHandler) TODO can remove? # continuously monitor RTDB contents t = threading.Thread(target=self.run) t.start()
def __init__(self, robot, rci=None): self.robot = int(robot) # settings which can be customized self.dof = 'Rz' self.speed = 0.5 self.duration = 1.0 self.sleep = 1.0 self.repeats = 2 self.disableVisionLoc = True self.accelerationLimit = None # remaining initialization self.rtdb2Store = RtDB2Store(RTDB2_DEFAULT_PATH, False) item = self.rtdb2Store.get(robot, "ROBOT_STATE") if item == None: raise RuntimeError("Error: robot software not active") if rci == None: rci = robotControlInterface.RobotControlInterface(self.robot) rci.connect() self.rci = rci
def __init__(self, agent, frequency=30.0, rtdbpath=RTDB2_DEFAULT_PATH): """ Monitor RTDB keys and show their values. """ # store arguments self.agent = agent self.frequency = frequency # other control options, can be overridden after construction self.prependTimestamp = False self.showOnce = False self.afterInit = None # callback # the keys to monitor and actions associated to them self.keys = set() self.handles = {} self.lastItemTimestamp = defaultdict(lambda: "") # setup RTDB connection self.rtdb2Store = RtDB2Store(rtdbpath) # setup signal handler for cleanup self.done = False signal.signal(signal.SIGINT, self.cleanup)
def has_scored_once(self, team): rtdb = RtDB2Store(RTDB2_DEFAULT_PATH, False) actual_score = rtdb.get(0, "MATCH_STATE").value["goalsOwn"] if actual_score < 1: raise AssertionError("Not scored yet")
default=[]) parser.add_argument('-k', '--key', help='keys to display, default all', type=str, nargs='*', default=[]) parser.add_argument('-p', '--path', help='database path to use', type=str, default=RTDB2_DEFAULT_PATH) args = parser.parse_args() # Create instance of RtDB2Store and get data rtdb2Store = RtDB2Store(args.path) items = rtdb2Store.getAllRtDBItems() # Sort items items.sort(key=lambda a: a.key) items.sort(key=lambda a: a.agent) # Display table header print("{:5s} {:<30s} {:<6s} {:6s} {:<s}".format("agent", "key", "type", "age ", "value")) # Display table for item in items: show = True if len(args.agent) > 0 and item.agent not in args.agent: show = False
# (the procedure was something like: terminal 1 run cdrx, edit Makefile to select proper grab, make, in terminal 2 run cdmN where N is the appropriate robot, when done in terminal 1 run 'make kill') # # this script is useful when for instance developing dewarp or evaluating (dewarp) performance over time # and perhaps even to demonstrate how the multiCam system works (how the tools depend on each other) # maybe it can be used towards some kind of regression test suite import sys, os import signal import glob import argparse import threading, time import falconspy from rtdb2 import RtDB2Store, RTDB2_DEFAULT_PATH # setup RTDB rtdb2Store = RtDB2Store(RTDB2_DEFAULT_PATH, True) class TestGrabs(): def __init__(self, verbose=True, worldmodelmode=False, dryrun=False): self.verbose = verbose self.dryrun = dryrun if dryrun: self.verbose = True self.worldmodelmode = worldmodelmode self.coderoot = falconspy.FALCONS_CODE_PATH self.grabroot = falconspy.FALCONS_DATA_PATH + '/internal/vision/multiCam' # setup signal handler for proper shutdown signal.signal(signal.SIGINT, self.signalHandler) def make(self, clean=False):
parser = argparse.ArgumentParser( description=descriptionTxt, epilog=exampleTxt, formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-a', '--agent', help='agent ID to use', type=int, default=rtdb2tools.guessAgentId()) parser.add_argument('-p', '--path', help='database path to use', type=str, default=RTDB2_DEFAULT_PATH) parser.add_argument('key', help='RtDB key to write to') parser.add_argument( 'value', help='the value to put as string, should be mappable to target struct') args = parser.parse_args() # Create instance of RtDB2Store and read databases from disk rtdb2Store = RtDB2Store(args.path, False) # don't start in read-only # This put operation should try to preserve attributes, like shared value = eval( args.value ) # yikes! but, this prevents argument like '[1, 4]' being written into database as string, whereas we need an array of size 2 item = rtdb2Store.put(args.agent, args.key, value) rtdb2Store.closeAll()
# Jan Feitsma, February 2020 # Park all robots. # For description and usage hints, execute with '-h' import argparse import sys, os import time import threading import socket # for gethostname import falconspy from rtdb2 import RtDB2Store, RTDB2_DEFAULT_PATH # setup RTDB rtdb2Store = RtDB2Store(RTDB2_DEFAULT_PATH, False) def parse_arguments(): parser = argparse.ArgumentParser( description= "Park all robots. Works for real robots as well as for simulation.") parser.add_argument('--refbox', help='use refbox signal', action='store_true') parser.add_argument('--mode', help='sim or real mode, guess if not provided', default=None, choices=['sim', 'real']) parser.add_argument( "-r",
print("No agents where found in %s" % (DEFAULT_PATH, )) sys.exit(0) if len(agents) == 1: storage_path = os.path.join(DEFAULT_PATH, agents[0]) else: while True: print("Found agents: %s" % (agents, )) sys.stdout.write('Write agent number: ') agent = input() agent = "agent" + agent if agent in agents: storage_path = os.path.join(DEFAULT_PATH, agent) break else: storage_path = sys.argv[1] rtdb2Store = RtDB2Store(storage_path) window = RtDBCurses() try: while True: info = rtdb2Store.getAllRtDBItems() window.display_info(info) except KeyboardInterrupt: pass finally: window.exit_screen() rtdb2Store.closeAll()