def __init__(self, sensors, actuators, motorController, timer, utils): super(BreakFreeState, self).__init__(sensors, actuators, motorController, timer, utils) print "Break Free State. Starting by backing up..." random.seed(time.time()) self.backUpTimeout = timeout.Timeout(random.randrange(3, 6)) self.stateTimeout = timeout.Timeout(10) self.substate = "backUp" self.BACK_UP_SPEED = -100
def __init__(self, sensors, actuators, motorController, timer, utils): super(BlindWallFollowingState, self).__init__(sensors, actuators, motorController, timer, utils) print "starting blindWallFollowingState. This state performs 10 seconds of wall following without looking for blocks. It is meant to recover from not being able to move to a block." self.timeout = timeout.Timeout(15) self.WALL_FOLLOW_SPEED = 80 self.wallFollowPID = PID(3, 2, .15)
def __init__(self, sensors, actuators, motorController, timer, utils): super(StrictWallFollowingState, self).__init__(sensors, actuators, motorController, timer, utils) print "Strict Wall Following State starting. In this state, we don't chase a block unless we are close to it..." self.timeout = timeout.Timeout( 10) #attempt to get closer for 10 seconds self.STRICT_BLOCK_DISTANCE_THRESHOLD = 8 #distance at which we start chasing block
def __init__(self, sensors, actuators, motorController, timer, utils): super(MoveToBlockState, self).__init__(sensors, actuators, motorController, timer, utils) print "MoveToBlockState" self.timeout = timeout.Timeout(30) self.CLOSE_ENOUGH_DISTANCE = 4 #make this such that the forward sensors will not detect a potential 90-degree corner while in approach mode self.ANGLE_EPSILON = 10 self.DRIVE_SPEED = 60 #needs calibration self.EAT_DISTANCE = 7.1 #distance in inches we will drive forward to eat block self.ROBOT_RADIUS = 7.5 self.CAMERA_OFFSET = 2.96 self.start_gyro_angle = 0 self.MIN_DISTANCE_TO_START_FLANK_MANEUVER = 12 #don't even try the flank if we are further than 15 inches away self.FLANK_APPROACH_LENGHT = 2.5 #we hope the Flank Maneuver leaves us in a position straight in front of the block, 2.5 inches away self.FLANK_MANEUVER_MAX_ATTEMPTS = 3 self.flank_first_angle = 0 self.flank_second_angle = 0 self.flank_target_distance = 0 self.flank_is_left = False self.flank_maneuver_attempts = 0 self.flank_initial_distance_from_block = 0 self.MIN_DRAG_BLOCK_DISTANCE = 1.1 self.DRAG_TURN_RATE = 3 self.DRAG_MAX_ATTEMPTS = 3 self.drag_attempts = 0 self.substate = "ApproachBlock" self.FlankManeuverStage = "Turn1"
def __init__(self, sensors, actuators, motorController, timer, utils): super(TurnToBlockState, self).__init__(sensors, actuators, motorController, timer, utils) print "Turn to block state" self.BLOCK_ANGLE_EPSILON = 3 self.timeout = timeout.Timeout(20) self.motorController.fwdVel = 0
def test_wait_expire(self): idle = timeout.Timeout() self.assertEqual(idle.active, False) self.assertEqual(idle.expired, False) idle.wait(0.1) self.assertEqual(idle.active, False) self.assertEqual(idle.expired, True)
def test_wait_expire_raise(self): idle = timeout.Timeout(raise_e=True) secs = 0.1 try: idle.wait(secs) except Exception as e: self.assertEqual(type(e), timeout.TimeLimitExpired) self.assertEqual(list(e.args)[0], secs)
def __init__(self, sensors, actuators, motorController, timer, utils): super(PickUpBlockState, self).__init__(sensors, actuators, motorController, timer, utils) print "PickUpBlockState starting..." self.timeout = timeout.Timeout(15) self.pickupTimeout = timeout.Timeout(5) self.substate = "WallDetect" self.startAngle = 0 self.pickUpBlockStartTime = 0 #start off stationary self.driveStraight(0) self.SCAN_SPEED=40 self.JOSTLE_TIMEOUT = 7 self.MIN_SAFE_DISTANCE = 5 #an approximation of the distance in inches we'd need to read from a 90-degree corner pointing at the middle of the robot to life the block safely self.motorController.fwdVel=0
def activate_timeout(self): days, hours, minutes, seconds = self.get_time_entry() self.timeout = timeout.Timeout() self.timeout.set_new_timeout(days, hours, minutes, seconds) self.timeout.activate_timeout() self.update_clock()
def __init__(self, startTime, totalGameTime): self.startTime = startTime self.totalGameTime = totalGameTime #in seconds self.isGameStarted = False self.navTimeout = timeout.Timeout( 60 ) #timeout for navigation states, i.e. WallFollowingState and LookingForBlockState self.ourBlockColor = "Red" self.wfPID = PID(10, 5, .15)
def init_timeout(self, config): """ Initialize the timeout tracker """ self.timeout = timeout.Timeout(self, config) # track all connected users keys = self.redis.keys('user:*') for key in keys: tag = key.split(':', 1)[1] self.timeout.update(tag)
def activate_timeout(self): try: days, hours, minutes, seconds = self.get_time_entry() self.label_error_entry_time.grid_forget() self.timeout = timeout.Timeout() self.timeout.set_new_timeout(days, hours, minutes, seconds) self.timeout.activate_timeout() self.update_clock() except Exception: self.label_error_entry_time.grid(row=1, column=2)
def __init__(self, sensors, actuators, motorController, timer, utils): super(RandomTravelingState, self).__init__(sensors, actuators, motorController, timer, utils) print "Starting RandomtTravelingState..." self.timeout = timeout.Timeout(30) self.substate = "RandomTraveling" self.TURN_SPEED = 40 self.DRIVE_SPEED = 40 self.SIDE_COLLISION_DISTANCE = 1 self.FRONT_COLLISION_DISTANCE = 3.5 #meant to prevent the worst case: we head into a 90-degree angle and it gets inside our front opening, jamming us. self.RANDOM_ANGLE_RANGE = 35 #randomness of 30 degrees, to avoid bouncing back and forth between two walls self.lastTurnNegative = False self.intialGyroAngle = 0 random.seed(time.time())
def __init__(self, sensors, actuators, motorController, timer, utils): super(EatBlockState, self).__init__(sensors, actuators, motorController, timer, utils) print "EatBlockState" self.timeout = timeout.Timeout(30) self.DRIVE_SPEED = 60 #needs calibration self.eat_distance = 16 #distance in inches we will drive forward to eat block self.start_gyro_angle = 0 self.DRAG_TURN_RATE = 30 self.substate = "EatBlock" self.sensors.encoders.resetEncoders()
def activate_timeout(self): try: days, hours, minutes, seconds = self.get_time_entry() self.label_error_entry_time.grid_forget() self.timeout = timeout.Timeout() self.timeout.set_new_timeout(days, hours, minutes, seconds) self.timeout.activate_timeout() self.update_clock() except TimeEntryException: self.inputs["error_entry_time"].set("Timeout has maximum 4 fields") self.label_error_entry_time.grid(row=1, column=2) except ValueError: self.inputs["error_entry_time"].set( "You entered a character input") self.label_error_entry_time.grid(row=1, column=2)
def _kill_ssh_master(self): if self.ssh_master: try: os.unlink(self.ssh_master) except OSError as e: if e.errno != errno.ENOENT: raise self.ssh_master = None if self.ssh_process: self.message("killing ssh master process", str(self.ssh_process.pid)) self.ssh_process.stdin.close() self.ssh_process.terminate() self.ssh_process.stdout.close() with timeoutlib.Timeout( seconds=90, error_message= "Timeout while waiting for ssh master to shut down"): self.ssh_process.wait() self.ssh_process = None
def wait_user_login(self): """Wait until logging in as non-root works. Most tests run as the "admin" user, so we make sure that user sessions are allowed before declaring a test machine as "booted". Returns the boot id of the system, or None if ssh timed out. """ tries_left = 60 while (tries_left > 0): try: with timeoutlib.Timeout(seconds=30): return self.execute( "! test -f /run/nologin && cat /proc/sys/kernel/random/boot_id", direct=True) except subprocess.CalledProcessError: pass except RuntimeError: # timeout; assume that ssh just went down during reboot, go back to wait_boot() return None tries_left = tries_left - 1 time.sleep(1) raise exceptions.Failure( "Timed out waiting for /run/nologin to disappear")
def setUp(self): self.tm = timeout.Timeout(1)
def __init__(self, sensors, actuators, motorController, timer, utils): super(LookingForBlocksState, self).__init__(sensors, actuators, motorController, timer, utils) print "Looking For Blocks State" self.SCAN_SPEED=30 self.initialAngle=self.sensors.gyro.gyroCAngle self.timeout = timeout.Timeout(20)
def execute(self, command=None, script=None, input=None, environment={}, stdout=None, quiet=False, direct=False, timeout=120, ssh_env=["env", "-u", "LANGUAGE", "LC_ALL=C"]): """Execute a shell command in the test machine and return its output. Either specify @command or @script Arguments: command: The string to execute by /bin/sh. script: A multi-line script to execute in /bin/sh input: Input to send to the command environment: Additional environment variables timeout: Applies if not already wrapped in a #Timeout context Returns: The command/script output as a string. """ assert command or script assert self.ssh_address if not direct: self._ensure_ssh_master() env_script = "" env_command = [] if environment and isinstance(environment, dict): for name, value in environment.items(): env_script += "%s='%s'\n" % (name, value) env_script += "export %s\n" % name env_command.append("{}={}".format(name, value)) elif environment == {}: pass else: raise Exception( "enviroment support dict or list items given: {0}".format( environment)) default_ssh_params = [ "ssh", "-p", str(self.ssh_port), "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "LogLevel=ERROR", "-o", "BatchMode=yes", "-l", self.ssh_user, self.ssh_address ] additional_ssh_params = [] cmd = [] if direct: additional_ssh_params += ["-i", self.identity_file] else: additional_ssh_params += ["-o", "ControlPath=" + self.ssh_master] if command: if getattr(command, "strip", None): # Is this a string? cmd += [command] if not quiet: self.message("+", command) else: cmd += command if not quiet: self.message("+", *command) else: assert not input, "input not supported to script" cmd += ["sh", "-s"] if self.verbose: cmd += ["-x"] input = env_script input += script command = "<script>" command_line = ssh_env + default_ssh_params + additional_ssh_params + env_command + cmd with timeoutlib.Timeout(seconds=timeout, error_message="Timed out on '%s'" % command, machine=self): if stdout: subprocess.call(command_line, stdout=stdout) return output = "" proc = subprocess.Popen(command_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdin_fd = proc.stdin.fileno() stdout_fd = proc.stdout.fileno() stderr_fd = proc.stderr.fileno() rset = [stdout_fd, stderr_fd] wset = [stdin_fd] while len(rset) > 0 or len(wset) > 0: ret = select.select(rset, wset, [], 10) for fd in ret[0]: if fd == stdout_fd: data = os.read(fd, 1024) if not data: rset.remove(stdout_fd) proc.stdout.close() else: if self.verbose: os.write(sys.__stdout__.fileno(), data) output += data.decode('utf-8', 'replace') elif fd == stderr_fd: data = os.read(fd, 1024) if not data: rset.remove(stderr_fd) proc.stderr.close() elif not quiet or self.verbose: os.write(sys.__stderr__.fileno(), data) for fd in ret[1]: if fd == stdin_fd: if input: num = os.write(fd, input.encode('utf-8')) input = input[num:] if not input: wset.remove(stdin_fd) proc.stdin.close() proc.wait() if proc.returncode != 0: raise subprocess.CalledProcessError(proc.returncode, command, output=output) return output
def activate_timeout(self): self.timeout = timeout.Timeout() self.timeout.set_new_timeout(minutes=25) self.timeout.activate_timeout() self.update_clock()