示例#1
0
    def __init__(self, dump=True, dump_size=3600, dump_dir='experience/'):
        self.dump = dump
        self.dump_size = dump_size
        self.dump_dir = dump_dir

        # TODO This might not always be accurate.
        dolphin_dir = os.path.expanduser('~/.local/share/dolphin-emu')

        self.state = ssbm.GameMemory()
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations(dolphin_dir)

        self.fox = fox.Fox()
        self.agent = agent.Agent()
        self.mm = menu_manager.MenuManager()

        try:
            print('Creating MemoryWatcher.')
            self.mw = memory_watcher.MemoryWatcher(
                dolphin_dir + '/MemoryWatcher/MemoryWatcher')
            print('Creating Pad. Open dolphin now.')
            self.pad = pad.Pad(dolphin_dir + '/Pipes/phillip')
            self.initialized = True
        except KeyboardInterrupt:
            self.initialized = False

        self.init_stats()
    def test_clone_delete(self):
        """ Test that the app is cloned and then deleted 
        """
        self.assertFalse(self.app_exists_on_disk(self.config["app_directory"]))
        sm = state_manager.StateManager(self.config)

        print("downloading app")
        sm.download_app()
        self.assertTrue(self.app_exists_on_disk(self.config["app_directory"]))

        print("deleting app")
        sm.delete_app()
        self.assertFalse(self.app_exists_on_disk(self.config["app_directory"]))
    def test_start_stop(self):
        """ Test that the app starts up and shuts down cleanly
        """
        sm = state_manager.StateManager(self.config)
        sm.delete_app()
        sm.download_app()
        sm.run()
        print(f"app started. running: {app_running()}")
        self.assertTrue(app_running())

        print("killing app")
        sm.kill_app()
        self.assertFalse(app_running())
    def __init__(self, map_name, n_duckies, t_requests):
        self.node_name = rospy.get_name()

        self.state_manager = state_manager.StateManager(
            map_name, n_duckies, t_requests)

        # Subscribers
        self.sub_paths = rospy.Subscriber('/flock_simulator/commands',
                                          FlockCommand,
                                          self.cbCommands,
                                          queue_size=1)

        # Publishers
        self.pub_state = rospy.Publisher('/flock_simulator/state',
                                         FlockState,
                                         queue_size=1)
        self.msg_state = FlockState()

        self.isUpdating = False
示例#5
0
    def __init__(self, **kwargs):
        Default.__init__(self, **kwargs)

        self.toggle = False

        self.user = os.path.expanduser(self.user)

        self.state = ssbm.GameMemory()
        # track players 1 and 2 (pids 0 and 1)
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations()

        if self.tag is not None:
            random.seed(self.tag)

        self.pids = [1]
        self.cpus = {1: None}
        self.characters = {1: self.p2}

        self.pids.append(0)
        cpu_level = None if self.human else self.cpu
        if cpu_level == 0:
            cpu_level = random.choice(list(range(1, 10)),
                                      p=([.06, .04] + [.03] * 5 + [.05, 0.7]))
        print('Playing against CPU Level: ' + str(cpu_level))
        self.cpus[0] = cpu_level
        self.characters[0] = self.p1

        print('Creating MemoryWatcher.')
        mwType = memory_watcher.MemoryWatcher
        if self.zmq:
            mwType = memory_watcher.MemoryWatcherZMQ
        self.mw = mwType(self.user + '/MemoryWatcher/MemoryWatcher')

        pipe_dir = self.user + '/Pipes/'
        print('Creating Pads at %s. Open dolphin now.' % pipe_dir)
        util.makedirs(self.user + '/Pipes/')

        paths = [pipe_dir + 'phillip%d' % i for i in self.pids]
        self.get_pads = util.async_map(Pad, paths)

        self.init_stats()
示例#6
0
    def reset(self):
        try:
            os.system("killall -s KILL dolphin-emu")
        except:
            pass
        dolphin_dir = find_dolphin_dir()
        if dolphin_dir is None:
            print('Could not find dolphin config dir.')
            return

        self.state = st.State()
        self.sm = state_manager.StateManager(self.state)
        write_locations(dolphin_dir, self.sm.locations())

        self.stats = stat.Stats()

        print('Start dolphin now. Press ^C to stop ')
        from subprocess import Popen
        Popen([
            "dolphin-emu", "--movie=/home/sci/workspace/Athena/falcon.dtm",
            "--exec=/home/sci/Downloads/Super Smash Bros. Melee (USA) (En,Ja) (v1.02).iso"
        ])
        self.mw = memory_watcher.MemoryWatcher(dolphin_dir +
                                               '/MemoryWatcher/MemoryWatcher')
        self.pad = p.Pad(dolphin_dir + '/Pipes/p3')
        #run(state, sm, mw, pad, stats)
        self.mm = menu_manager.MenuManager()
        self.last_frame = self.state.frame
        print(vars(self))
        #        while self.state.frame <= self.last_frame:
        #            self.last_frame = self.state.frame
        #            res = next(self.mw)
        #            if res is not None:
        #                self.sm.handle(*res)
        #               # print (res)
        #        print(vars(self))
        self.stall(0)
        d3 = self.get_data(copy.deepcopy(self.state))
        return d3
from nav_msgs.msg import Odometry
from std_msgs.msg import String
from std_msgs.msg import Empty
from std_msgs.msg import Bool
from geometry_msgs.msg import Vector3
from geometry_msgs.msg import Twist
from geometry_msgs.msg import PoseStamped
from geometry_msgs.msg import Point
from geometry_msgs.msg import Pose
from geometry_msgs.msg import Quaternion

PUB = rospy.Publisher('/bebop/cmd_vel', Twist, queue_size=10)
PUB_TAKEOFF = rospy.Publisher('/bebop/takeoff', Empty, queue_size=10)
PUB_LANDING = rospy.Publisher('/bebop/land', Empty, queue_size=10)
MSG_EMPTY = Empty()
STATE_MANAGER = state_manager.StateManager()
IS_KEYREADER_FINISHED = False
IS_RUNNING = False
SPEED_LIMIT = 0.5


class NonBlockingConsole(object):
    def __enter__(self):
        self.old_settings = termios.tcgetattr(sys.stdin)
        tty.setcbreak(sys.stdin.fileno())
        return self
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.old_settings)

    def get_data(self):
        try:
            if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
示例#8
0
import state_manager
from state_manager import State

if __name__ == "__main__":
    manager = state_manager.StateManager()
    state = manager.get_state(19)
    print(state)
    manager.close_db()
示例#9
0
    def __init__(self, **kwargs):
        Default.__init__(self, **kwargs)

        self.model = self.agent.model
        self.rlConfig = self.model.rlConfig

        if self.dump:
            try:
                import zmq
            except ImportError as err:
                print("ImportError: {0}".format(err))
                sys.exit("Install pyzmq to dump experiences")

            context = zmq.Context()

            self.socket = context.socket(zmq.PUSH)
            self.sock_addr = "tcp://%s:%d" % (self.dump,
                                              util.port(self.model.name))
            print("Connecting to " + self.sock_addr)
            self.socket.connect(self.sock_addr)

            self.dump_size = self.rlConfig.experience_length
            self.dump_state_actions = (self.dump_size *
                                       ssbm.SimpleStateAction)()

            self.dump_frame = 0
            self.dump_count = 0

        self.first_frame = True
        self.action_counter = 0
        self.toggle = False

        self.user = os.path.expanduser(self.user)

        self.state = ssbm.GameMemory()
        # track players 1 and 2 (pids 0 and 1)
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations()

        if self.tag is not None:
            random.seed(self.tag)

        self.pids = [1]
        self.agents = {1: self.agent}
        self.characters = {1: self.agent.char or self.p2}

        reload_every = self.rlConfig.experience_length
        self.agent.reload_every = reload_every

        enemy = None
        if self.self_play:
            enemy = agent.Agent(reload_every=self.self_play * reload_every,
                                swap=True,
                                **kwargs)
        elif self.enemy:
            with open(self.enemy + 'agent', 'r') as f:
                import json
                enemy_kwargs = json.load(f)
            enemy_kwargs.update(reload_every=None,
                                swap=True,
                                dump=None,
                                path=self.enemy)
            enemy = agent.Agent(**enemy_kwargs)

        if enemy:
            self.pids.append(0)
            self.agents[0] = enemy
            self.characters[0] = enemy.char or self.p1

        self.menu_managers = {
            i: MenuManager(characters[c], pid=i)
            for i, c in self.characters.items()
        }

        print('Creating MemoryWatcher.')
        mwType = memory_watcher.MemoryWatcher
        if self.zmq:
            mwType = memory_watcher.MemoryWatcherZMQ
        self.mw = mwType(self.user + '/MemoryWatcher/MemoryWatcher')

        pipe_dir = self.user + '/Pipes/'
        print('Creating Pads at %s. Open dolphin now.' % pipe_dir)
        util.makedirs(self.user + '/Pipes/')

        paths = [pipe_dir + 'phillip%d' % i for i in self.pids]
        self.get_pads = util.async_map(Pad, paths)

        self.init_stats()

        # sets the game mode and random stage
        self.movie = movie.Movie(movie.endless_netplay +
                                 movie.stages[self.stage])
示例#10
0
 def setUp(self):
     self.state = State()
     self.state_manager = state_manager.StateManager(self.state)
示例#11
0
    def __init__(self, **kwargs):
        for k, v in default_args.items():
            if k in kwargs and kwargs[k] is not None:
                setattr(self, k, kwargs[k])
            else:
                setattr(self, k, v)

        self.fps = 60 // self.act_every
        self.experience_length = self.experience_time * self.fps

        if self.dump:
            self.dump_dir = self.path + "/experience/"
            os.makedirs(self.dump_dir, exist_ok=True)
            self.dump_tag = "" if self.tag is None else str(self.tag) + "-"
            self.dump_size = self.experience_length
            self.dump_state_actions = (self.dump_size *
                                       ssbm.SimpleStateAction)()

            self.dump_frame = 0
            self.dump_count = 0

        self.reward_logfile = self.path + '/rewards.log'
        self.first_frame = True
        self.action_counter = 0
        self.toggle = False

        self.dolphin_dir = os.path.expanduser(self.dolphin_dir)

        self.state = ssbm.GameMemory()
        # track players 1 and 2 (pids 0 and 1)
        self.sm = state_manager.StateManager([0, 1])
        self.write_locations(self.dolphin_dir)

        self.fox = fox.Fox()
        if self.tag is not None:
            random.seed(self.tag)

        self.cpus = [0, 1] if self.self_play else [1]
        self.agents = []

        reload_every = self.experience_length
        if self.self_play:
            self.enemy = agent.Agent(reload_every=self.self_play *
                                     reload_every,
                                     swap=True,
                                     **kwargs)
            self.agents.append(self.enemy)
        self.agent = agent.Agent(reload_every=reload_every, **kwargs)
        self.agents.append(self.agent)

        self.characters = [self.p1, self.p2] if self.self_play else [self.p2]
        self.menu_managers = [
            MenuManager(characters[c], pid=i)
            for c, i in zip(self.characters, self.cpus)
        ]

        print('Creating MemoryWatcher.')
        mwType = memory_watcher.MemoryWatcher
        if self.zmq:
            mwType = memory_watcher.MemoryWatcherZMQ
        self.mw = mwType(self.dolphin_dir + '/MemoryWatcher/MemoryWatcher')

        pipe_dir = self.dolphin_dir + '/Pipes/'
        print('Creating Pads at %s. Open dolphin now.' % pipe_dir)
        os.makedirs(self.dolphin_dir + '/Pipes/', exist_ok=True)

        paths = [pipe_dir + 'phillip%d' % i for i in self.cpus]
        self.get_pads = util.async_map(Pad, paths)

        self.init_stats()

        # sets the game mode and random stage
        self.movie = movie.Movie(movie.endless_netplay_battlefield)
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.old_settings)

    def get_data(self):
        try:
            if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
                return sys.stdin.read(1)
        except:
            return '[CTRL-C]'
        return False

    def __exit__(self, type, value, traceback):
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.old_settings)


#reads the current state of the drone: Landed, hovering, etc.
copter_state_manager = state_manager.StateManager()
odom_current = Odometry()
bebop_pose = Pose()


def odometry_callback(Odometry):
    global odom_current
    global odom_time
    odom_current = Odometry
    odom_time = rospy.get_time()


def pose_callback(Pose):
    global bebop_pose
    bebop_pose = Pose