Ejemplo n.º 1
0
    def __init__(self,
                 device_serial,
                 is_emulator=True,
                 output_dir=None,
                 use_hierarchy_viewer=False):
        """
        create a device
        :param device_serial: serial number of target device
        :param is_emulator: boolean, type of device, True for emulator, False for real device
        :return:
        """
        self.logger = logging.getLogger("Device")

        self.serial = device_serial
        self.is_emulator = is_emulator
        self.adb = None
        self.telnet = None
        self.monkeyrunner = None
        self.view_client = None
        self.settings = {}
        self.display_info = None
        self.sdk_version = None
        self.release_version = None
        self.ro_debuggable = None
        self.ro_secure = None

        self.output_dir = output_dir
        if self.output_dir is None:
            self.output_dir = os.path.abspath("droidbot_out")
        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)

        self.use_hierarchy_viewer = use_hierarchy_viewer

        if self.is_emulator:
            self.adb_enabled = True
            self.telnet_enabled = True
            self.monkeyrunner_enabled = False
            self.view_client_enabled = True
        else:
            self.adb_enabled = True
            self.telnet_enabled = False
            self.monkeyrunner_enabled = False
            self.view_client_enabled = True

        self.is_connected = False
        self.connect()
        self.get_sdk_version()
        self.get_release_version()
        self.get_ro_secure()
        self.get_ro_debuggable()
        self.get_display_info()
        self.logcat = self.redirect_logcat()
        from state_monitor import StateMonitor
        self.state_monitor = StateMonitor(device=self)
        self.state_monitor.start()
        self.unlock()
    def __init__(self, action_server):
        # action server for getting requests from AI
        self._action_server = action_server

        # current state of motion coordinator
        self._task = None
        self._first_task_seen = False

        # used for timeouts & extrapolating
        self._time_of_last_task = None
        self._timeout_vel_sent = False

        # to keep things thread safe
        self._lock = threading.RLock()

        # handles monitoring of state of drone
        self._state_monitor = StateMonitor()

        # handles communicating between tasks and LLM
        self._task_command_handler = TaskCommandHandler()

        self._idle_obstacle_avoider = IdleObstacleAvoider()
        self._avoid_magnitude = rospy.get_param("~obst_avoid_magnitude")
        self._kickout_distance = rospy.get_param('~kickout_distance')
        self._new_task_distance = rospy.get_param('~new_task_distance')
        self._safe_distance = rospy.get_param('~safe_distance')

        # safety
        self._safety_client = SafetyClient('motion_command_coordinator')
        self._safety_land_complete = False
        self._safety_land_requested = False

        # Create action client to request a safety landing
        self._action_client = actionlib.SimpleActionClient(
            "motion_planner_server", QuadMoveAction)
        try:
            # update rate for motion coordinator
            self._update_rate = rospy.get_param('~update_rate')
            # task timeout values
            self._task_timeout = rospy.Duration(
                rospy.get_param('~task_timeout'))
            # startup timeout
            self._startup_timeout = rospy.Duration(
                rospy.get_param('~startup_timeout'))
        except KeyError as e:
            rospy.logerr('Could not lookup a parameter for motion coordinator')
            raise
def run_test(load_balancer, workload, debug):
    sm = StateMonitor()
    create_count = 0  # Keeps track of how many creates went through
    remove_count = 0  # Keeps track of how many removes went through
    with open(workload) as f:
        # returns (None, sm.failed) if there are any errors
        # otherwise runs through the workload
        for line in tqdm.tqdm(f, total=get_num_lines(workload)):

            # Parse command
            command, arg = line.split()

            if command == 'create':

                if debug: print('\n{} {}'.format(command, arg))

                try:
                    check_valid(sm, load_balancer.shards, debug)
                except Error as e:
                    print('\nbefore create {}\n{}'.format(create_count, e))
                    return None, sm.failed

                load_balancer.add_shard(arg)

                try:
                    check_valid(sm, load_balancer.shards, debug)
                except Error as e:
                    print('\nafter create {}\n{}'.format(create_count, e))
                    return None, sm.failed

                create_count += 1

            elif command == 'remove':

                if debug: print('\n{} {}'.format(command, arg))

                try:
                    check_valid(sm, load_balancer.shards, debug)
                except Error as e:
                    print('\nbefore remove {}\n{}'.format(create_count, e))
                    return None, sm.failed

                load_balancer.remove_shard(arg)

                try:
                    check_valid(sm, load_balancer.shards, debug)
                except Error as e:
                    print('\nafter remove {}\n{}'.format(create_count, e))
                    return None, sm.failed

                remove_count += 1

            elif command == 'put':

                load_balancer.put(arg)
                sm.put(arg)

        # Final check
        try:
            check_valid(sm, load_balancer.shards, debug)
        except Error as e:
            print('\nat the end\n{}'.format(e))
            return None, sm.failed

        stats = sm.get_stats(load_balancer.shards, debug)
        return stats, sm.failed