Example #1
0
    def default(self):
        if core.UPDATING:
            updating = 'true'
        else:
            updating = 'false'

        doc = dominate.document(title='Watcher')

        with doc.head:
            meta(name='enable_notifs', content='false')
            meta(name='updating', content=updating)
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/update.css?v=01.16')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}/update.css?v=01.16'.format(
                     core.CONFIG['Server']['theme']))
            script(type='text/javascript',
                   src=core.URL_BASE + '/static/js/update/main.js?v=01.01')

        with doc:
            with div(id='content'):
                div(id='thinker')
                span(u'Updating', cls='msg')

        return doc.render()
Example #2
0
    def default(self):
        doc = dominate.document(title='Watcher')
        doc.attributes['lang'] = 'en'

        with doc.head:
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/status.css')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}/status.css'.format(core.THEME))
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/movie_status_popup.css')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}/movie_status_popup.css'.format(core.THEME))
            script(type='text/javascript',
                   src=core.URL_BASE + '/static/js/status/main.js?v=12.27')

        with doc:
            Header.insert_header(current="status")
            with div(id='content'):
                self.movie_list()
            div(id='overlay')
            div(id='status_pop_up')

        return doc.render()
    def __init__(self, simulation=True):
        """Initializes various aspects of the Fetch.
        
        TODOs: get things working, also use `simulation` flag to change ROS
        topic names if necessary (especially for the cameras!). UPDATE: actually
        I don't think this is necessary now, they have the same topic names.
        """
        rospy.init_node("fetch")
        self.arm = Arm()
        self.arm_joints = ArmJoints()
        self.base = Base()
        self.camera = RGBD()
        self.head = Head()
        self.gripper = Gripper(self.camera)
        self.torso = Torso()
        self.joint_reader = JointStateReader()

        # Tucked arm starting joint angle configuration
        self.names = ArmJoints().names()
        self.tucked = [1.3200, 1.3999, -0.1998, 1.7199, 0.0, 1.6600, 0.0]
        self.tucked_list = [(x, y) for (x, y) in zip(self.names, self.tucked)]

        # Initial (x,y,yaw) position of the robot wrt map origin. We keep this
        # fixed so that we can reset to this position as needed. The HSR's
        # `omni_base.pose` (i.e., the start pose) returns (x,y,yaw) where yaw is
        # the rotation about that axis (intuitively, the z axis). For the base,
        # `base.odom` supplies both `position` and `orientation` attributes.
        start = copy.deepcopy(self.base.odom.position)
        yaw = Base._yaw_from_quaternion(self.base.odom.orientation)
        self.start_pose = np.array([start.x, start.y, yaw])
        self.TURN_SPEED = 0.3

        self.num_restarts = 0
Example #4
0
    def default(self):
        doc = dominate.document(title='Watcher')

        with doc.head:
            Head.insert()
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/add_movie.css')
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/{}/add_movie.css'.format(core.THEME))
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/movie_info_popup.css')
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/{}/movie_info_popup.css'.format(core.THEME))
            script(type='text/javascript', src=core.URL_BASE + '/static/js/add_movie/main.js?v=01.03')

        with doc:
            Header.insert_header(current="add_movie")
            with div(id='search_box'):
                input(id='search_input', type="text", placeholder="Search...", name="search_term")
                with button(id="search_button"):
                    i(cls='fa fa-search')
            div(id='thinker')
            with div(id="database_results"):
                ul(id='movie_list')

            div(id='overlay')

            div(id='info_pop_up')

        return doc.render()
Example #5
0
    def __init__(self, simulation=True):
        """Initializes various aspects of the Fetch."""
        rospy.init_node("fetch")
        rospy.loginfo("initializing the Fetch...")
        self.arm = Arm()
        self.arm_joints = ArmJoints()
        self.base = Base()
        self.camera = RGBD()
        self.head = Head()
        self.gripper = Gripper(self.camera)
        self.torso = Torso()
        self.joint_reader = JointStateReader()

        # Tucked arm starting joint angle configuration
        self.names = ArmJoints().names()
        self.tucked = [1.3200, 1.3999, -0.1998, 1.7199, 0.0, 1.6600, 0.0]
        self.tucked_list = [(x,y) for (x,y) in zip(self.names, self.tucked)]

        # Initial (x,y,yaw) position of the robot wrt map origin. We keep this
        # fixed so that we can reset to this position as needed. The HSR's
        # `omni_base.pose` (i.e., the start pose) returns (x,y,yaw) where yaw is
        # the rotation about that axis (intuitively, the z axis). For the base,
        # `base.odom` supplies both `position` and `orientation` attributes.
        start = copy.deepcopy(self.base.odom.position)
        yaw = Base._yaw_from_quaternion(self.base.odom.orientation)
        self.start_pose = np.array([start.x, start.y, yaw])
        rospy.loginfo("...finished initialization!")
Example #6
0
    def default(self):
        doc = dominate.document(title='Watcher')
        doc.attributes['lang'] = 'en'

        with doc.head:
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/status.css?v=02.22')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}status.css?v=02.22'.format(
                     core.CONFIG['Server']['theme']))
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/movie_status_popup.css?v=02.22')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}movie_status_popup.css?v=02.22'.format(
                     core.CONFIG['Server']['theme']))
            script(type='text/javascript',
                   src=core.URL_BASE + '/static/js/status/main.js?v=02.17')

        with doc:
            Header.insert_header(current="status")
            with div(id='content'):
                with div(id='view_config'):
                    span('Display: ')
                    with select(id='list_style'):
                        options = ['Posters', 'List', 'Compact']
                        for opt in options:
                            option(opt, value=opt.lower())
                    span('Order By: ')
                    with select(id='list_sort'):
                        options = ['Status', 'Title', 'Year']
                        option('Title', value='title')
                        option('Year', value='year')
                        option('Status', value='status_sort')
                with div(id='key'):
                    span(cls='wanted')
                    span('Wanted')
                    span(cls='found')
                    span('Found')
                    span(cls='snatched')
                    span('Snatched')
                    span(cls='finished')
                    span('Finished')
                self.movie_list()

            with div(id='import'):
                with a(href=u'{}/import_library'.format(core.URL_BASE)):
                    i(cls='fa fa-hdd-o', id='import_library')
                    span('Import existing library.')

            div(id='overlay')
            div(id='status_pop_up')

        return doc.render()
Example #7
0
 def init(self):
     PlayState.TICK_LENGTH = 0.1
     self.tick_time = 0
     self.head = Head(PlayState.GRID_SIZE)
     self.body = []
     for i in range(PlayState.INITIAL_BODY_SIZE):
         self.__add_body__()
     self.food = Food(PlayState.GRID_SIZE, self.head.pos)
     self.hud = HUD()
     pass
Example #8
0
 def handle_new_player_msg(self, msg):
     self.his_id = int(msg[1])
     if self.his_id == 0:
         self.his_head = Head(self.his_id, self.game_path.p0path,
                              self.width, self.height, self.my_head)
     elif self.his_id == 1:
         self.his_head = Head(self.his_id, self.game_path.p1path,
                              self.width, self.height, self.my_head)
     self.my_head.stranger = self.his_head
     self.head_group.add(self.his_head)
Example #9
0
def webControl(x, y):
    x = int(x)
    y = int(y)
    usrMsgLogger = DataLogger()
    evobot = EvoBot("/dev/tty.usbmodemfa131", usrMsgLogger)
    head = Head(evobot)
    syringe = Syringe(evobot, 9)
    syringe.plungerSetConversion(1)
    evobot.home()

    head.move(x, y)
Example #10
0
class Redirect(BaseAction):
    """
    Returns a 303 See Other status code along with a `location` header back
    to the client.

    :param loc: The location to which the client should be redirect to
    :type loc: str
    """
    def __init__(self, loc):
        self.head = Head("303 SEE OTHER")
        self.head.add_header("Location", loc)
def webControl(x,y):
    x=int(x)
    y=int(y)
    usrMsgLogger = DataLogger()
    evobot = EvoBot("/dev/tty.usbmodemfa131", usrMsgLogger)
    head = Head( evobot )
    syringe =  Syringe( evobot, 9)
    syringe.plungerSetConversion( 1 )
    evobot.home()
    
    
    head.move(x,y)
Example #12
0
 def handle_id_msg(self, msg):
     self.id = int(msg[1])
     if self.id == 0:
         self.my_head = Head(self.id, self.game_path.p0path, self.width,
                             self.height, self.his_head)
     elif self.id == 1:
         self.my_head = Head(self.id, self.game_path.p1path, self.width,
                             self.height, self.his_head)
     self.head_group.add(self.my_head)
     msg_out = ('balls ' + ' '.join(
         str(self.my_head.ball_list[i])
         for i in range(len(self.my_head.ball_list))) + '\n')
     self.send_msg(msg_out)
Example #13
0
    def default(self):
        doc = dominate.document(title='Watcher')
        doc.attributes['lang'] = 'en'

        with doc.head:
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/import_library.css?v=04.04')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}import_library.css?v=04.04'.format(
                     core.CONFIG['Server']['theme']))
            script(type='text/javascript',
                   src=core.URL_BASE +
                   '/static/js/import_library/main.js?v=04.07')

        with doc:
            Header.insert_header(current=None)
            with div(id='content'):
                h1('Import Library')
                with div(id='import_sources'):
                    with div():
                        with a(href=core.URL_BASE +
                               '/import_library/couchpotato'):
                            img(src=core.URL_BASE +
                                '/static/images/couchpotato.png',
                                alt='CouchPotato',
                                cls='import_source_icon')
                            br()
                            span('CouchPotato')
                    with div():
                        with a(href=core.URL_BASE + '/import_library/kodi'):
                            img(src=core.URL_BASE + '/static/images/kodi.png',
                                alt='Kodi',
                                cls='import_source_icon')
                            br()
                            span('Kodi')
                    with div():
                        with a(href=core.URL_BASE + '/import_library/plex'):
                            img(src=core.URL_BASE + '/static/images/plex.png',
                                alt='Plex',
                                cls='import_source_icon')
                            br()
                            span('Plex')
                    with div():
                        with a(href=core.URL_BASE +
                               '/import_library/directory'):
                            i(cls='fa fa-folder import_source_icon')
                            br()
                            span('Directory')
        return doc.render()
Example #14
0
    def index(self):
        doc = dominate.document(title='Watcher')

        with doc.head:
            Head.insert()
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/shutdown.css')
            script(type='text/javascript', src=core.URL_BASE + '/static/js/shutdown/main.js?v=12.27')

        with doc:
            with div(id='content'):
                div(id='thinker')
                span('Shutting Down', cls='msg')

        return doc.render()
Example #15
0
    def testParseBytesToInt(self):
        parser = Parser(INT_ENCODED)
        parser_test_function(self,
                             parser=parser,
                             code="D",
                             dtype="I",
                             length=2,
                             payload=257,
                             remaining=256)

        head = Head(code=parser.code,
                    dtype=parser.dtype,
                    length=parser.length,
                    remaining=parser.remaining)
        head_test_function(self,
                           head=head,
                           code="D",
                           dtype="I",
                           length=2,
                           remaining=256)

        payload = Payload(data=parser.payload,
                          dtype=parser.dtype,
                          length=parser.length)
        payload_test_function(self,
                              payload=payload,
                              data=257,
                              dtype="I",
                              length=2)
Example #16
0
    def default(self):
        doc = dominate.document(title='Watcher')

        with doc.head:
            meta(name='enable_notifs', content='false')
            Head.insert()
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/shutdown.css?v=01.16')
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/{}/shutdown.css?v=01.16'.format(core.CONFIG['Server']['theme']))
            script(type='text/javascript', src=core.URL_BASE + '/static/js/shutdown/main.js?v=12.27')

        with doc:
            with div(id='content'):
                div(id='thinker')
                span(u'Shutting Down', cls='msg')

        return doc.render()
Example #17
0
 def testParseHandshakeToBytes(self):
     parser = Parser(HANDSHAKE_ENCODED)
     parser_test_function(self,
                          parser=parser,
                          code="H",
                          dtype="B",
                          length=0,
                          payload=b"",
                          remaining=0)
     head = Head(code=parser.code,
                 dtype=parser.dtype,
                 length=parser.length,
                 remaining=parser.remaining)
     head_test_function(self,
                        head=head,
                        code="H",
                        dtype="B",
                        length=0,
                        remaining=0)
     payload = Payload(data=parser.payload,
                       dtype=parser.dtype,
                       length=parser.length)
     payload_test_function(self,
                           payload=payload,
                           data=b"",
                           dtype="B",
                           length=0)
Example #18
0
def reset():
    global data, score, snakeHead, isPlaying, isApple
    score = 0   
    for i in range(48):
            data[i] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    isApple = False
    snakeHead = Head((0, 149, 238),(mapWidth/2, mapHeight/2), pps)
Example #19
0
    def testParseBytesToBytes(self):
        # b'DB\x04\x00\x00\x00\x00\x00\x00\x00ABCD1997'
        parser = Parser(BYTES_ENCODED)
        parser_test_function(self,
                             parser=parser,
                             code="D",
                             dtype="B",
                             length=4,
                             payload=b'ABCD',
                             remaining=0)

        head = Head(code=parser.code,
                    dtype=parser.dtype,
                    length=parser.length,
                    remaining=parser.remaining)
        head_test_function(self,
                           head=head,
                           code="D",
                           dtype="B",
                           length=4,
                           remaining=0)

        payload = Payload(data=parser.payload,
                          dtype=parser.dtype,
                          length=parser.length)
        payload_test_function(self,
                              payload=payload,
                              data=b'ABCD',
                              dtype="B",
                              length=4)
Example #20
0
    def testParseBytesToStr(self):
        # b'DS\x04\x00\x00\x00\x00\x00\x00\x00ABCD1997'
        parser = Parser(data=STR_ENCODED)
        parser_test_function(self,
                             parser=parser,
                             code="D",
                             dtype="S",
                             length=4,
                             payload="ABCD",
                             remaining=0)

        head = Head(code=parser.code,
                    dtype=parser.dtype,
                    length=parser.length,
                    remaining=parser.remaining)
        head_test_function(self,
                           head=head,
                           code="D",
                           dtype="S",
                           length=4,
                           remaining=0)

        payload = Payload(data=parser.payload,
                          dtype=parser.dtype,
                          length=parser.length)
        payload_test_function(self,
                              payload=payload,
                              data="ABCD",
                              dtype="S",
                              length=4)
Example #21
0
    def __init__(self, color=colors.skins_snake, name=0):
        ''' Создает новую змею в случайном месте, длиной 50 шариков.
        Координатой змеи считаются координаты центра головы. '''
        '''
        Не готово:
        1) Имя змеи
        '''
        if color == colors.skins_snake:
            self.colors = random.choice(colors.skins_snake)
        else:
            self.colors = color
        self.num = len(self.colors)
        self.name = name
        self.energy = 0

        self.x = 500
        self.y = 500
        self.coords = Vector2d(self.x, self.y)
        self.r = 5
        config.snake_radius = self.r
        self.length = 0
        self.life = 1

        self.balls = []
        head = Head(color=self.colors[0], x=self.x, y=self.y)
        self.balls += [head]
        self.length += 1
        for i in range(9):
            color = self.colors[(i + 1) % self.num]
            new_ball = Ball(x=self.x, y=self.y, color=color, r=5)
            self.balls += [new_ball]
            self.length += 1
        self.energy = self.length
        self.speed_timer = 0
 def __init__(self, config):
     self.replica_count = config.replica_count
     self.head = Head(config.init_object)
     self.tail = Tail(config.init_object)
     # create inner_replicas with chains
     inner_replicas = [Replica(config.init_object) * self.replica_count]
     self.replicas = [head] + inner_replicas + [tail]
     pass
Example #23
0
    def default(self):
        doc = dominate.document(title='Watcher')
        doc.attributes['lang'] = 'en'

        with doc.head:
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/import_library.css?v=02.17')
            link(rel='stylesheet',
                 href=core.URL_BASE +
                 '/static/css/{}/import_library.css?v=02.17'.format(
                     core.CONFIG['Server']['theme']))
            script(type='text/javascript',
                   src=core.URL_BASE +
                   '/static/js/import_library/main.js?v=02.17')

        with doc:
            Header.insert_header(current=None)
            with div(id='content'):
                h1('Import Library')
                with div(id='scan_dir'):
                    with div(id='directory_info'):
                        span('Library directory: ')
                        input(id='directory',
                              type='text',
                              placeholder=' /movies')
                        br()
                        span('Minimum file size to import: ')
                        input(id='minsize', type='number', value='500')
                        span('MB.')
                        br()
                        i(cls='fa fa-check-square checkbox',
                          id='recursive',
                          value='True')
                        span('Scan recursively.')
                        with div():
                            with span(id='start_scan'):
                                i(cls='fa fa-binoculars', id='start_scan')
                                span('Start scan')
                with div(id='wait'):
                    span('Scanning library for new movies.')
                    br()
                    span('This may take several minutes.')

            div(id='thinker')
        return doc.render()
Example #24
0
    def __init__(self, N, M, in_size, out_size, batch_size, lstm=False):
        super(NTM, self).__init__()

        if lstm:
            self.controller = LSTMController(in_size, out_size, M, batch_size)
        else:
            self.controller = FeedForwardController(in_size, out_size, M, batch_size)

        self.read_head = Head(batch_size, N, M)
        self.write_head = Head(batch_size, N, M)
        self.batch_size = batch_size
        self.N = N
        self.M = M
        self.eps = 1e-8
        self.memory = None
        self.register_parameter('memory_bias',
                                nn.Parameter(torch.randn(1, N, M) / math.sqrt(N)))
Example #25
0
def instantiate_objects():
    """After connection has been made, instatiate the various robot objects
    """

    global perm_dir_path
    global dir_path

    logger.debug('instantiate_objects called')
    #get default json file
    def_start_protocol = FileIO.get_dict_from_json(
        os.path.join(dir_path, 'data/default_startup_protocol.json'))
    #FileIO.get_dict_from_json('/home/pi/PythonProject/default_startup_protocol.json')

    #instantiate the head
    head = Head(def_start_protocol['head'], publisher, perm_dir_path)
    logger.debug('head string: ')
    logger.debug(str(head))
    logger.debug('head representation: ')
    logger.debug(repr(head))
    #use the head data to configure the head
    head_data = {}
    head_data = prot_dict['head']  #extract the head section from prot_dict

    logger.debug("Head configured!")

    #instantiate the script keeper (sk)

    #instantiate the deck
    deck = Deck(def_start_protocol['deck'], publisher, perm_dir_path)
    logger.debug('deck string: ')
    logger.debug(str(deck))
    logger.debug('deck representation: ')
    logger.debug(repr(deck))

    runner = ProtocolRunner(head, publisher)

    #use the deck data to configure the deck
    deck_data = {}
    deck_data = prot_dict['deck']  #extract the deck section from prot_dict
    #    deck = RobotLib.Deck({})        #instantiate an empty deck
    deck.configure_deck(deck_data)  #configure the deck from prot_dict data
    logger.debug("Deck configured!")

    #do something with the Ingredient data
    ingr_data = {}
    ingr_data = prot_dict[
        'ingredients']  #extract the ingredient section from prot_dict
    ingr = Ingredients({})

    ingr.configure_ingredients(
        ingr_data)  #configure the ingredienets from prot_dict data
    logger.debug('Ingredients imported!')

    publisher.set_head(head)
    publisher.set_runner(runner)
    subscriber.set_deck(deck)
    subscriber.set_head(head)
    subscriber.set_runner(runner)
Example #26
0
 def init(self):
     self.tray = Tray(self)
     self.head = Head(self)
     self.agenda = Agenda(self)
     self.set = Set(self)
     # qss
     with open('style.QSS', 'r') as fp:
         self.setStyleSheet(fp.read())
         fp.close()
Example #27
0
    def heads(self):
        """
        A list of ``Head`` objects representing the branch heads in
        this repo

        Returns
            ``git.Head[]``
        """
        return Head.find_all(self)
Example #28
0
    def index():

        doc = dominate.document(title='Watcher')

        with doc.head:
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/fourohfour.css')
            style

        with doc:
            with div(id='content'):
                with span(cls='msg'):
                    span('404')
                    br()
                    span('Page Not Found')

        return doc.render()
Example #29
0
    def default(self):
        doc = dominate.document(title='Watcher')

        with doc.head:
            meta(name='enable_notifs', content='false')
            Head.insert()
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/restart.css?v=01.16')
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/{}/restart.css?v=01.16'.format(core.CONFIG['Server']['theme']))
            script(type='text/javascript', src=core.URL_BASE + '/static/js/restart/main.js?v=12.27')

        with doc:
            with div(id='content'):
                div(id='thinker')
                span(u'Restarting', cls='msg')
                with span(u'Timeout Exceeded.', cls='error'):
                    p(u'Watcher is taking too long to restart, please check your logs and restart manually.')

        return doc.render()
Example #30
0
    def page_template(self):
        config = core.CONFIG
        doc = dominate.document(title='Watcher')

        with doc.head:
            meta(name='git_url', content=core.GIT_URL)
            Head.insert()
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/settings.css?v=01.23')
            link(rel='stylesheet', href=core.URL_BASE + '/static/css/{}/settings.css?v=01.23'.format(core.CONFIG['Server']['theme']))
            script(type='text/javascript', src=core.URL_BASE + '/static/js/settings/main.js?v=01.23')
            script(type='text/javascript', src=core.URL_BASE + '/static/js/settings/save_settings.js?v=01.23')

        with doc:
            Header.insert_header(current="settings")
            with div(id="content", cls=page.__name__):
                page(self, config)

        return doc.render()
Example #31
0
    def heads(self):
        """
        A list of ``Head`` objects representing the branch heads in
        this repo

        Returns
            ``git.Head[]``
        """
        return Head.find_all(self)
Example #32
0
    def index(self):
        doc = dominate.document(title='Watcher')

        with doc.head:
            Head.insert()
            link(rel='stylesheet',
                 href=core.URL_BASE + '/static/css/restart.css')
            script(type='text/javascript',
                   src=core.URL_BASE + '/static/js/restart/main.js?v=12.27')

        with doc:
            with div(id='content'):
                div(id='thinker')
                span('Restarting', cls='msg')
                with span('Timeout Exceeded.', cls='error'):
                    p('Watcher is taking too long to restart, please check your logs and restart manually.'
                      )

        return doc.render()
Example #33
0
    def __init__ (self):
        rospy.Subscriber("/head_camera/rgb/image_raw",Image,self.RGBImageCallback)
        rospy.Subscriber("/head_camera/depth_registered/image_raw",Image,self.DepthImageCallback)
        rospy.Subscriber("/ar_pose_marker",AlvarMarkers,self.GetArPosesCallBack)
        self.bridge = CvBridge()

        self.Arm = Arm()
        self.Gripper = Gripper()
        self.Head = Head()
        self.PoseProcessing = PoseProcessing()
Example #34
0
    def __init__(self, torso_center, lower_body_flag):
        self._body_center = torso_center
        self._lower_body_flag = lower_body_flag
        self.head = Head(Point(torso_center.x, torso_center.y+15, torso_center.z))
        self.torso = Torso(Point(torso_center.x, torso_center.y, torso_center.z))
        self.left_arm = Arm(Point(torso_center.x+6.6, torso_center.y+8, torso_center.z))
        self.right_arm = Arm(Point(torso_center.x-6.6, torso_center.y+8, torso_center.z))

        self.right_arm.set_slocal_rotate_angle(180, 0, 0)


        if self._lower_body_flag:
            self.left_leg = Leg(Point(torso_center.x+4, torso_center.y-10.6, torso_center.z))
            self.right_leg = Leg(Point(torso_center.x-4, torso_center.y-10.6, torso_center.z))
            self.right_leg.set_hlocal_rotate_angle(180, 0, 0)
Example #35
0
 def __init__(self, head, structure, morphology={}):
     self.parent = None
     self.head = Head(head, structure["head"])
     self.components = copy.deepcopy(structure["components"])
     if self.components is None:
         self.components = {}
         self.order = ["head"]
     else:
         self.order = copy.deepcopy(structure["order"])
     if "agreement" in structure:
         self.agreement = copy.deepcopy(structure["agreement"])
     else:
         self.agreement = {}
     if "governance" in structure:
         self.governance = copy.deepcopy(structure["governance"])
     else:
         self.governance = {}
     self.morphology = copy.deepcopy(morphology)
Example #36
0
class Phrase:
    def __init__(self, head, structure, morphology={}):
        self.parent = None
        self.head = Head(head, structure["head"])
        self.components = copy.deepcopy(structure["components"])
        if self.components is None:
            self.components = {}
            self.order = ["head"]
        else:
            self.order = copy.deepcopy(structure["order"])
        if "agreement" in structure:
            self.agreement = copy.deepcopy(structure["agreement"])
        else:
            self.agreement = {}
        if "governance" in structure:
            self.governance = copy.deepcopy(structure["governance"])
        else:
            self.governance = {}
        self.morphology = copy.deepcopy(morphology)

    def resolve_agreement(self):
        forms = {}
        for key in self.agreement:
            if key == "parent":
                morphology = self.parent.morphology
            elif key.startswith("parent->"):
                key_p = key[8:]
                morphology = self.parent.components[key_p].morphology
            else:
                morphology = self.components[key].morphology
            for agreement_type in self.agreement[key]:
                forms[agreement_type] = morphology[agreement_type]
        return forms

    def to_string(self, received_governance = {}):
        self.morphology.update(received_governance)
        string_representation = ""
        for item in self.order:
            if item == "head":
                head_word = self.head.get_form(self.morphology, self.resolve_agreement())
                string_representation = string_representation + " " + head_word
            else:
                phrase = self.components[item]
                if type(phrase) is str or type(phrase) is unicode:
                    #Data not set
                    pass
                else:
                    phrase.parent = self
                    governance = {}
                    if item in self.governance:
                        governance = self.governance[item]
                    string_representation = string_representation + " " + phrase.to_string(governance)
        return string_representation.strip()

    def __str__(self):
        text = self.to_string()
        #remove multiple spaces
        text = re.sub("\s\s+", " ", text)
        #remove spaces before punctuation
        text = self.__remove_spaces_punct__(text)
        return text.strip()

    def __remove_spaces_punct__(self, text):
        puncts = ".,;:?!"
        for punct in puncts:
            if " "+punct in text:
                text = text.replace(" " + punct, punct)
        return text
Example #37
0
 def __init__(self, loc):
     self.head = Head("303 SEE OTHER")
     self.head.add_header("Location", loc)
Example #38
0
    def __init__(self, context):
        super(WaterPulse, self).__init__(context)
        self.setObjectName('WaterPulse')
        self._widget = QWidget()
        self._widget.setFixedSize(600, 600)
        self._sound_client = SoundClient()
        rospy.Subscriber('robotsound', SoundRequest, self.sound_cb)

        self.l_joint_names = ['l_shoulder_pan_joint',
                              'l_shoulder_lift_joint',
                              'l_upper_arm_roll_joint',
                              'l_elbow_flex_joint',
                              'l_forearm_roll_joint',
                              'l_wrist_flex_joint',
                              'l_wrist_roll_joint']
 
        l_traj_contoller_name = None
        l_traj_controller_name = '/l_arm_controller/joint_trajectory_action'
	self.l_traj_action_client = SimpleActionClient(l_traj_controller_name,
		JointTrajectoryAction)
	rospy.loginfo('Waiting for a response from the trajectory '
		+ 'action server for LEFT arm...')
	self.l_traj_action_client.wait_for_server()

         
        QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
        self.sound_sig.connect(self.sound_sig_cb)
        
        large_box = QtGui.QVBoxLayout()

        # Textbox to enter words for PR2 to say 
        sound_textbox = QtGui.QLineEdit("Squirtle Squirtle")  # Default Text
        sound_textbox.setFixedWidth(450)
        self.marker_publisher = rospy.Publisher('visualization_marker', Marker)
        
        # Set a handler on the textbox to retrieve the text when button clicked
        self.sound_textbox = sound_textbox

        button_box = QtGui.QHBoxLayout()
        button_box.addItem(QtGui.QSpacerItem(15,20))
        button_box.addWidget(self.create_button('Speak', self.command_cb))
        button_box.addWidget(sound_textbox)
        button_box.addStretch(1)
        large_box.addLayout(button_box)
        
        # 'Trick or Treat' & 'Thank You' Buttons
        halloween_box = QtGui.QHBoxLayout()
        halloween_box.addItem(QtGui.QSpacerItem(15,20))
        halloween_box.addWidget(self.create_button('Trick or Treat', self.command_cb))
        halloween_box.addWidget(self.create_button('Thank You', self.command_cb))
        halloween_box.addStretch(1)
        large_box.addLayout(halloween_box)
        
        # Buttons to move the PR2's head
        up_head = Head(Head.UP, self)
        head_box = QtGui.QVBoxLayout()
        up_head_box = QtGui.QHBoxLayout()
        up_head_button = self.create_button('^', up_head.create_closure())
        down_head = Head(Head.DOWN, self)
        down_head_box = QtGui.QHBoxLayout()
        down_head_button = self.create_button('v', down_head.create_closure())
        right_head = Head(Head.RIGHT, self)
        right_head_button = self.create_button('>', right_head.create_closure())
        left_head = Head(Head.LEFT, self)
        left_head_button = self.create_button('<', left_head.create_closure())
        left_right_head_box = QtGui.QHBoxLayout()

        head_speed_sld = QtGui.QSlider(QtCore.Qt.Horizontal)
        head_speed_sld.setFocusPolicy(QtCore.Qt.NoFocus)
        head_speed_sld.setMinimum(1)
        head_speed_sld.setMaximum(5)
        head_speed_sld.valueChanged[int].connect(Head.set_speed)

        up_head_box.addItem(QtGui.QSpacerItem(235,20))
        up_head_box.addWidget(up_head_button)
        up_head_box.addItem(QtGui.QSpacerItem(275,20))
        left_right_head_box.addItem(QtGui.QSpacerItem(160,20))
        left_right_head_box.addWidget(left_head_button)
        left_right_head_box.addItem(QtGui.QSpacerItem(60,20))
        left_right_head_box.addWidget(right_head_button)
        left_right_head_box.addItem(QtGui.QSpacerItem(225,20))
        down_head_box.addItem(QtGui.QSpacerItem(235,20))
        down_head_box.addWidget(down_head_button)
        down_head_box.addItem(QtGui.QSpacerItem(275,20))
        head_sld_box = QtGui.QHBoxLayout()
        head_sld_box.addItem(QtGui.QSpacerItem(225,20))
        head_sld_box.addWidget(head_speed_sld)
        head_sld_box.addItem(QtGui.QSpacerItem(225,20))
        head_box.addLayout(up_head_box)
        head_box.addLayout(left_right_head_box)
        head_box.addLayout(down_head_box)
        head_box.addLayout(head_sld_box)
        large_box.addLayout(head_box)        

        # Buttons to move the grippers
        gripper = Gripper(Gripper.RIGHT, Gripper.OPEN, self)
        right_gripper = self.create_button('Right gripper',
                gripper.create_closure())
        gripper = Gripper(Gripper.LEFT, Gripper.OPEN, self)
        left_gripper = self.create_button('Left gripper', gripper.create_closure()) 
        knock_button = self.create_button('Knock', self.knock)
        large_box.addItem(QtGui.QSpacerItem(100,250))
        gripper_box = QtGui.QHBoxLayout()
        gripper_box.addItem(QtGui.QSpacerItem(75,20))
        gripper_box.addWidget(left_gripper)
        gripper_box.addWidget(knock_button)
        gripper_box.addItem(QtGui.QSpacerItem(450,20))
        gripper_box.addWidget(right_gripper)
        gripper_box.addItem(QtGui.QSpacerItem(75,20))
        large_box.addLayout(gripper_box)

        # Buttons to move the base
        base_box = QtGui.QVBoxLayout()
        large_box.addItem(QtGui.QSpacerItem(100,100))
        forward_base_box = QtGui.QHBoxLayout()
        forward_base = Base(Base.FORWARD, self)
        forward_base_button = self.create_button('move forward', forward_base.create_closure())
        forward_base_box.addItem(QtGui.QSpacerItem(400,20))
        forward_base_box.addWidget(forward_base_button)
        forward_base_box.addItem(QtGui.QSpacerItem(400,20))
        base_box.addLayout(forward_base_box)

        left_right_base_box = QtGui.QHBoxLayout()
        left_base= Base(Base.LEFT, self)
        left_base_button = self.create_button('move left',
                left_base.create_closure())

        right_base= Base(Base.RIGHT, self)
        right_base_button= self.create_button('move right',
                right_base.create_closure())
        left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
        left_right_base_box.addWidget(left_base_button)
        left_right_base_box.addItem(QtGui.QSpacerItem(50,20))
        left_right_base_box.addWidget(right_base_button)
        left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
        base_box.addLayout(left_right_base_box)

        backward_base_box = QtGui.QHBoxLayout()
        backward_base= Base(Base.BACKWARD, self)
        backward_base_button = self.create_button('move backward',
                backward_base.create_closure())
        backward_base_box.addItem(QtGui.QSpacerItem(400,20))
        backward_base_box.addWidget(backward_base_button)
        backward_base_box.addItem(QtGui.QSpacerItem(400,20))
        base_box.addLayout(backward_base_box)

        large_box.addLayout(base_box)
        
        turn_base_box = QtGui.QHBoxLayout()

        counter_base= Base(Base.COUNTER, self)
        counter_base_button = self.create_button('\\\n        -->',
                counter_base.create_closure())
        
        clockwise_base= Base(Base.CLOCKWISE, self)
        clockwise_base_button = self.create_button('        /\n<--',
                clockwise_base.create_closure())
        turn_base_box.addItem(QtGui.QSpacerItem(75,20))
        turn_base_box.addWidget(counter_base_button)
        turn_base_box.addItem(QtGui.QSpacerItem(225,20))
        turn_base_box.addWidget(clockwise_base_button)
        turn_base_box.addItem(QtGui.QSpacerItem(100,20))
        large_box.addLayout(turn_base_box)

        self._widget.setObjectName('WaterPulse')
        self._widget.setLayout(large_box)
        context.add_widget(self._widget)
        self._widget.setStyleSheet("QWidget { image: url(%s) }" %
                (str(os.path.dirname(os.path.realpath(__file__))) +
                "/../../rosie_background.jpg"))
Example #39
0
    def __init__(self, context):
        super(SimpleGUI, self).__init__(context)
        self.setObjectName('SimpleGUI')
        self._widget = QWidget()
	self._widget.setFixedSize(600, 600)
        self._sound_client = SoundClient()
        rospy.Subscriber('robotsound', SoundRequest, self.sound_cb)

        QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
        self.sound_sig.connect(self.sound_sig_cb)
        
        large_box = QtGui.QVBoxLayout()

        #Sound textbox
        sound_textbox = QtGui.QLineEdit("Squirtle Squirtle") #Default Text
        sound_textbox.setFixedWidth(450)
        #Set a handle on the textbox to retrieve the text when button clicked
        self.sound_textbox = sound_textbox

        button_box = QtGui.QHBoxLayout()
	button_box.addItem(QtGui.QSpacerItem(15,20))
        button_box.addWidget(self.create_button('Speak', self.command_cb))
    	button_box.addWidget(sound_textbox)
        button_box.addStretch(1)
        large_box.addLayout(button_box)

	speech_box = QtGui.QHBoxLayout()
	speech_box.addItem(QtGui.QSpacerItem(15, 20))
        self.speech_label = QtGui.QLabel('Robot has not spoken yet.')
        palette = QtGui.QPalette()
        palette.setColor(QtGui.QPalette.Foreground,QtCore.Qt.blue)
        self.speech_label.setPalette(palette)
        speech_box.addWidget(self.speech_label)

        large_box.addLayout(speech_box)
        large_box.addStretch(1)

	#large_box.addItem(QtGui.QSpacerItem(50,20))

        up_head = Head(Head.UP)
	head_box = QtGui.QVBoxLayout()
	up_head_box = QtGui.QHBoxLayout()
        up_head_button = self.create_button('^', up_head.create_closure())
        #large_box.addWidget(up_head_button)
        down_head = Head(Head.DOWN)
	down_head_box = QtGui.QHBoxLayout()
        down_head_button = self.create_button('v', down_head.create_closure())
        #large_box.addWidget(down_head_button)
        right_head = Head(Head.RIGHT)
        right_head_button = self.create_button('>', right_head.create_closure())
        #large_box.addWidget(right_head_button)
        left_head = Head(Head.LEFT)
        left_head_button = self.create_button('<', left_head.create_closure())
	left_right_head_box = QtGui.QHBoxLayout()

	up_head_box.addItem(QtGui.QSpacerItem(235,20))
	up_head_box.addWidget(up_head_button)
	up_head_box.addItem(QtGui.QSpacerItem(275,20))
	left_right_head_box.addItem(QtGui.QSpacerItem(160,20))
	left_right_head_box.addWidget(left_head_button)
	left_right_head_box.addItem(QtGui.QSpacerItem(60,20))
	left_right_head_box.addWidget(right_head_button)
	left_right_head_box.addItem(QtGui.QSpacerItem(225,20))
	down_head_box.addItem(QtGui.QSpacerItem(235,20))
	down_head_box.addWidget(down_head_button)
	down_head_box.addItem(QtGui.QSpacerItem(275,20))
	head_box.addLayout(up_head_box)
	head_box.addLayout(left_right_head_box)
	head_box.addLayout(down_head_box)
	large_box.addLayout(head_box)
	#large_box.addItem(QtGui.QSpacerItem(500,20))
        #large_box.addWidget(left_head_button)

        gripper = Gripper(Gripper.RIGHT, Gripper.OPEN)
        right_gripper = self.create_button('Right gripper!', gripper.create_closure())
        gripper = Gripper(Gripper.LEFT, Gripper.OPEN)
        left_gripper = self.create_button('Left gripper!', gripper.create_closure()) 
	large_box.addItem(QtGui.QSpacerItem(100,250))

	gripper_box = QtGui.QHBoxLayout()
	gripper_box.addItem(QtGui.QSpacerItem(75,20))
        gripper_box.addWidget(left_gripper)
	gripper_box.addItem(QtGui.QSpacerItem(450,20))
        gripper_box.addWidget(right_gripper)
	gripper_box.addItem(QtGui.QSpacerItem(75,20))
        large_box.addLayout(gripper_box)
	

	base_box = QtGui.QVBoxLayout()

	large_box.addItem(QtGui.QSpacerItem(100,100))

        #forward
	forward_base_box = QtGui.QHBoxLayout()
        forward_base = Base(Base.FORWARD)
        forward_base_button = self.create_button('move forward', forward_base.create_closure())
	forward_base_box.addItem(QtGui.QSpacerItem(400,20))
	forward_base_box.addWidget(forward_base_button)
	forward_base_box.addItem(QtGui.QSpacerItem(400,20))
	base_box.addLayout(forward_base_box)
        #large_box.addWidget(forward_base_button)

        #left
	left_right_base_box = QtGui.QHBoxLayout()
        left_base= Base(Base.LEFT)
      	left_base_button = self.create_button('move left', left_base.create_closure())
        #large_box.addWidget(left_base_button)

        #right
        right_base= Base(Base.RIGHT)
      	right_base_button= self.create_button('move right', right_base.create_closure())
	left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
	left_right_base_box.addWidget(left_base_button)
	left_right_base_box.addItem(QtGui.QSpacerItem(50,20))
	left_right_base_box.addWidget(right_base_button)
	left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
        base_box.addLayout(left_right_base_box)
	#large_box.addWidget(right_base_button)

        #backward
	backward_base_box = QtGui.QHBoxLayout()
        backward_base= Base(Base.BACKWARD)
      	backward_base_button = self.create_button('move backward', backward_base.create_closure())
	backward_base_box.addItem(QtGui.QSpacerItem(400,20))
	backward_base_box.addWidget(backward_base_button)
	backward_base_box.addItem(QtGui.QSpacerItem(400,20))
        base_box.addLayout(backward_base_box)
	#large_box.addWidget(backward_base_button)

	large_box.addLayout(base_box)
        
	turn_base_box = QtGui.QHBoxLayout()

	#turn left
        turnleft_base= Base(Base.TURNLEFT)
      	turnleft_base_button = self.create_button('        /\n<--', turnleft_base.create_closure())
	#large_box.addWidget(turnleft_base_button)
        
	#turn right
        turnright_base= Base(Base.TURNRIGHT)
      	turnright_base_button = self.create_button('\\\n        -->', turnright_base.create_closure())
	turn_base_box.addItem(QtGui.QSpacerItem(75,20))
	turn_base_box.addWidget(turnright_base_button)
	turn_base_box.addItem(QtGui.QSpacerItem(225,20))
	turn_base_box.addWidget(turnleft_base_button)
	turn_base_box.addItem(QtGui.QSpacerItem(100,20))
	large_box.addLayout(turn_base_box)
	#large_box.addWidget(turnright_base_button)
	self._widget.setObjectName('SimpleGUI')
        self._widget.setLayout(large_box)
        context.add_widget(self._widget)
 	self._widget.setStyleSheet("QWidget { image: url(%s) }" % "/home/vjampala/catkin_ws/src/cse481/hw1/rqt_simplegui/rosie_background.jpg")
Example #40
0
    def __init__(self, context):
        super(SimpleGUI, self).__init__(context)
        self.setObjectName('SimpleGUI')
        self._widget = QWidget()
        self._widget.setFixedSize(600, 600)
        self._sound_client = SoundClient()
        rospy.Subscriber('robotsound', SoundRequest, self.sound_cb)

        QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
        self.sound_sig.connect(self.sound_sig_cb)
        
        large_box = QtGui.QVBoxLayout()

        # Textbox to enter words for PR2 to say 
        sound_textbox = QtGui.QLineEdit("Squirtle Squirtle")  # Default Text
        sound_textbox.setFixedWidth(450)
        self.marker_publisher = rospy.Publisher('visualization_marker', Marker)
        
        # Set a handler on the textbox to retrieve the text when button clicked
        self.sound_textbox = sound_textbox

        button_box = QtGui.QHBoxLayout()
        button_box.addItem(QtGui.QSpacerItem(15,20))
        button_box.addWidget(self.create_button('Speak', self.command_cb))
        button_box.addWidget(sound_textbox)
        button_box.addStretch(1)
        large_box.addLayout(button_box)

        speech_box = QtGui.QHBoxLayout()
        speech_box.addItem(QtGui.QSpacerItem(15, 20))
        self.speech_label = QtGui.QLabel('Robot has not spoken yet')
        palette = QtGui.QPalette()
        palette.setColor(QtGui.QPalette.Foreground,QtCore.Qt.blue)
        self.speech_label.setPalette(palette)
        speech_box.addWidget(self.speech_label)

        large_box.addLayout(speech_box)
        large_box.addStretch(1)

        #large_box.addItem(QtGui.QSpacerItem(50,20))

        # Buttons to move the PR2's head
        up_head = Head(Head.UP, self)
        head_box = QtGui.QVBoxLayout()
        up_head_box = QtGui.QHBoxLayout()
        up_head_button = self.create_button('^', up_head.create_closure())
        down_head = Head(Head.DOWN, self)
        down_head_box = QtGui.QHBoxLayout()
        down_head_button = self.create_button('v', down_head.create_closure())
        right_head = Head(Head.RIGHT, self)
        right_head_button = self.create_button('>', right_head.create_closure())
        left_head = Head(Head.LEFT, self)
        left_head_button = self.create_button('<', left_head.create_closure())
        left_right_head_box = QtGui.QHBoxLayout()

        up_head_box.addItem(QtGui.QSpacerItem(235,20))
        up_head_box.addWidget(up_head_button)
        up_head_box.addItem(QtGui.QSpacerItem(275,20))
        left_right_head_box.addItem(QtGui.QSpacerItem(160,20))
        left_right_head_box.addWidget(left_head_button)
        left_right_head_box.addItem(QtGui.QSpacerItem(60,20))
        left_right_head_box.addWidget(right_head_button)
        left_right_head_box.addItem(QtGui.QSpacerItem(225,20))
        down_head_box.addItem(QtGui.QSpacerItem(235,20))
        down_head_box.addWidget(down_head_button)
        down_head_box.addItem(QtGui.QSpacerItem(275,20))
        head_box.addLayout(up_head_box)
        head_box.addLayout(left_right_head_box)
        head_box.addLayout(down_head_box)
        large_box.addLayout(head_box)

        # Buttons to move the grippers
        gripper = Gripper(Gripper.RIGHT, Gripper.OPEN, self)
        right_gripper = self.create_button('Right gripper',
                gripper.create_closure())
        gripper = Gripper(Gripper.LEFT, Gripper.OPEN, self)
        left_gripper = self.create_button('Left gripper', gripper.create_closure()) 
        large_box.addItem(QtGui.QSpacerItem(100,250))
        gripper_box = QtGui.QHBoxLayout()
        gripper_box.addItem(QtGui.QSpacerItem(75,20))
        gripper_box.addWidget(left_gripper)
        gripper_box.addItem(QtGui.QSpacerItem(450,20))
        gripper_box.addWidget(right_gripper)
        gripper_box.addItem(QtGui.QSpacerItem(75,20))
        large_box.addLayout(gripper_box)

        # Buttons to move the base
        base_box = QtGui.QVBoxLayout()
        large_box.addItem(QtGui.QSpacerItem(100,100))
        forward_base_box = QtGui.QHBoxLayout()
        forward_base = Base(Base.FORWARD, self)
        forward_base_button = self.create_button('move forward', forward_base.create_closure())
        forward_base_box.addItem(QtGui.QSpacerItem(400,20))
        forward_base_box.addWidget(forward_base_button)
        forward_base_box.addItem(QtGui.QSpacerItem(400,20))
        base_box.addLayout(forward_base_box)

        left_right_base_box = QtGui.QHBoxLayout()
        left_base= Base(Base.LEFT, self)
        left_base_button = self.create_button('move left',
                left_base.create_closure())

        right_base= Base(Base.RIGHT, self)
        right_base_button= self.create_button('move right',
                right_base.create_closure())
        left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
        left_right_base_box.addWidget(left_base_button)
        left_right_base_box.addItem(QtGui.QSpacerItem(50,20))
        left_right_base_box.addWidget(right_base_button)
        left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
        base_box.addLayout(left_right_base_box)

        backward_base_box = QtGui.QHBoxLayout()
        backward_base= Base(Base.BACKWARD, self)
        backward_base_button = self.create_button('move backward',
                backward_base.create_closure())
        backward_base_box.addItem(QtGui.QSpacerItem(400,20))
        backward_base_box.addWidget(backward_base_button)
        backward_base_box.addItem(QtGui.QSpacerItem(400,20))
        base_box.addLayout(backward_base_box)

        large_box.addLayout(base_box)
        
        turn_base_box = QtGui.QHBoxLayout()

        counter_base= Base(Base.COUNTER, self)
        counter_base_button = self.create_button('\\\n        -->',
                counter_base.create_closure())
        
        clockwise_base= Base(Base.CLOCKWISE, self)
        clockwise_base_button = self.create_button('        /\n<--',
                clockwise_base.create_closure())
        turn_base_box.addItem(QtGui.QSpacerItem(75,20))
        turn_base_box.addWidget(counter_base_button)
        turn_base_box.addItem(QtGui.QSpacerItem(225,20))
        turn_base_box.addWidget(clockwise_base_button)
        turn_base_box.addItem(QtGui.QSpacerItem(100,20))
        large_box.addLayout(turn_base_box)

        self._widget.setObjectName('SimpleGUI')
        self._widget.setLayout(large_box)
        context.add_widget(self._widget)
        self._widget.setStyleSheet("QWidget { image: url(%s) }" %
                (str(os.path.dirname(os.path.realpath(__file__))) +
                "/../../rosie_background.jpg"))
Example #41
0
class Body:
    def __init__(self, torso_center, lower_body_flag):
        self._body_center = torso_center
        self._lower_body_flag = lower_body_flag
        self.head = Head(Point(torso_center.x, torso_center.y+15, torso_center.z))
        self.torso = Torso(Point(torso_center.x, torso_center.y, torso_center.z))
        self.left_arm = Arm(Point(torso_center.x+6.6, torso_center.y+8, torso_center.z))
        self.right_arm = Arm(Point(torso_center.x-6.6, torso_center.y+8, torso_center.z))

        self.right_arm.set_slocal_rotate_angle(180, 0, 0)


        if self._lower_body_flag:
            self.left_leg = Leg(Point(torso_center.x+4, torso_center.y-10.6, torso_center.z))
            self.right_leg = Leg(Point(torso_center.x-4, torso_center.y-10.6, torso_center.z))
            self.right_leg.set_hlocal_rotate_angle(180, 0, 0)

    def horiz_move(self, gx, gy, gz):
        movement = tf.translate(Vector(gx, gy, gz)) # Affine matrix for horizontal movement.
        self._body_center = movement * self._init_torso_center

        self.head.horiz_move(x, y, z)
        self.torso.horiz_move(x, y, z)
        self.left_arm.horiz_move(x, y, z)
        self.right_arm.horiz_move(x, y, z)

        if self._lower_body_flag:
            self.left_leg.horiz_move(x, y, z)
            self.right_leg.horiz_move(x, y, z)

    def calc_body_center(self):
        return self._body_center

    def get_property_list(self):
        property_list = []
        property_list.extend(self.head.get_property_list())
        property_list.extend(self.torso.get_property_list())
        property_list.extend(self.left_arm.get_property_list())
        property_list.extend(self.right_arm.get_property_list())

        if self._lower_body_flag:
            property_list.extend(self.left_leg.get_property_list())
            property_list.extend(self.right_leg.get_property_list())

        return property_list

    def constr_json_data(self):
        # Construcat JSON data
        json_data_head = self.head.constr_json_data()
        json_data_torso = self.torso.constr_json_data()
        json_data_left_arm = self.left_arm.constr_json_data()
        json_data_right_arm = self.right_arm.constr_json_data()
        
        if self._lower_body_flag:
            json_data_left_leg = self.left_leg.constr_json_data()
            json_data_right_leg= self.right_leg.constr_json_data()

        json_data = {
            'joint_angle': {
                'left_shoulder': json_data_left_arm['joint_angle']['shoulder'],
                'left_elbow': json_data_left_arm['joint_angle']['elbow'],
                'right_shoulder': json_data_right_arm['joint_angle']['shoulder'],
                'right_elbow': json_data_right_arm['joint_angle']['elbow']

            },
            'true_position': {
                'head': json_data_head['true_position']['head'],
                'torso': json_data_torso['true_position']['torso'],
                'left_shouler': json_data_left_arm['true_position']['shoulder'],
                'left_elbow': json_data_left_arm['true_position']['elbow'],
                'left_hand': json_data_left_arm['true_position']['hand'],
                'right_shoulder': json_data_right_arm['true_position']['shoulder'],
                'right_elbow': json_data_right_arm['true_position']['elbow'],
                'right_hand': json_data_right_arm['true_position']['hand']
            }
        }

        if self._lower_body_flag:
            json_data['joint_angle']['left_hip'] = json_data_left_leg['joint_angle']['hip']
            json_data['joint_angle']['left_knee'] = json_data_left_leg['joint_angle']['knee']
            json_data['joint_angle']['right_hip'] = json_data_right_leg['joint_angle']['hip']
            json_data['joint_angle']['right_knee'] = json_data_right_leg['joint_angle']['knee']
            json_data['true_position']['left_hip'] = json_data_left_leg['true_position']['hip']
            json_data['true_position']['left_knee'] = json_data_left_leg['true_position']['knee']
            json_data['true_position']['left_foot'] = json_data_left_leg['true_position']['foot']
            json_data['true_position']['right_hip'] = json_data_right_leg['true_position']['hip']
            json_data['true_position']['right_knee'] = json_data_right_leg['true_position']['knee']
            json_data['true_position']['right_foot'] = json_data_right_leg['true_position']['foot']

        return json_data

    def set_from_json_data(self, json_data):
        # Set angle parameters from json data (not json file!)
        self.left_arm.set_from_json_data(json_data['joint_angle']['left_shoulder'], json_data['joint_angle']['left_elbow'])
        self.right_arm.set_from_json_data(json_data['joint_angle']['right_shoulder'], json_data['joint_angle']['right_elbow'])

        if self._lower_body_flag:
            self.left_leg.set_from_json_data(json_data['joint_angle']['left_hip'], json_data['joint_angle']['left_knee'])
            self.right_leg.set_from_json_data(json_data['joint_angle']['right_hip'], json_data['joint_angle']['right_knee'])

    def is_collision_body_parts(self):

        def collision_detection_generator():
            # left arm vs. cranicm
            yield self.left_arm.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

            # left arm vs. torso
            yield self.left_arm.is_collision_to_capsule(self.torso.calc_torso_upper_point(), self.torso.calc_torso_lower_point(), self.torso.get_torso_radius())

            # left arm vs. right upperarm
            yield self.left_arm.is_collision_to_capsule(self.right_arm.calc_shoulder_point(), self.right_arm.calc_upperarm_lower_point(), self.right_arm.get_upperarm_radius())

            # left arm vs. right elbow
            yield self.left_arm.is_collision_to_sphere(self.right_arm.calc_elbow_point(), self.right_arm.get_elbow_radius())

            # left arm vs. right forearm
            yield self.left_arm.is_collision_to_capsule(self.right_arm.calc_forearm_upper_point(), self.right_arm.calc_hand_point(), self.right_arm.get_forearm_radius())

            # right arm vs. cranicm
            yield self.right_arm.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

            # right arm vs. torso
            yield self.right_arm.is_collision_to_capsule(self.torso.calc_torso_upper_point(), self.torso.calc_torso_lower_point(), self.torso.get_torso_radius())

            if self._lower_body_flag:
                # left arm vs. left thigh
                yield self.left_arm.is_collision_to_capsule(self.left_leg.calc_hip_point(), self.left_leg.calc_thigh_lower_point(), self.left_leg.get_thigh_radius())

                # left arm vs. left knee
                yield self.left_arm.is_collision_to_sphere(self.left_leg.calc_knee_point(), self.left_leg.get_knee_radius())

                # left arm vs. left calf
                yield self.left_arm.is_collision_to_capsule(self.left_leg.calc_calf_upper_point(), self.left_leg.calc_foot_point(), self.left_leg.get_calf_radius())

                # left arm vs. right thigh
                yield self.left_arm.is_collision_to_capsule(self.right_leg.calc_hip_point(), self.right_leg.calc_thigh_lower_point(), self.right_leg.get_thigh_radius())

                # left arm vs. right knee
                yield self.left_arm.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # left arm vs. right calf
                yield self.left_arm.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

                # right arm vs. left thigh
                yield self.right_arm.is_collision_to_capsule(self.left_leg.calc_hip_point(), self.left_leg.calc_thigh_lower_point(), self.left_leg.get_thigh_radius())

                # right arm vs. left thigh
                yield self.right_arm.is_collision_to_capsule(self.left_leg.calc_hip_point(), self.left_leg.calc_thigh_lower_point(), self.left_leg.get_thigh_radius())

                # right arm vs. left knee
                yield self.right_arm.is_collision_to_sphere(self.left_leg.calc_knee_point(), self.left_leg.get_knee_radius())

                # right arm vs. left calf
                yield self.right_arm.is_collision_to_capsule(self.left_leg.calc_calf_upper_point(), self.left_leg.calc_foot_point(), self.left_leg.get_calf_radius())

                # right arm vs. right thigh
                yield self.right_arm.is_collision_to_capsule(self.right_leg.calc_hip_point(), self.right_leg.calc_thigh_lower_point(), self.right_leg.get_thigh_radius())

                # right arm vs. right knee
                yield self.right_arm.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # right arm vs. right calf
                yield self.right_arm.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

                # left leg vs. cranicm
                yield self.left_leg.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

                # left leg vs. right thigh
                yield self.left_leg.is_collision_to_capsule(self.right_leg.calc_hip_point(), self.right_leg.calc_thigh_lower_point(), self.right_leg.get_thigh_radius())

                # left leg vs. right knee
                yield self.left_leg.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # left leg vs. right calf
                yield self.left_leg.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

                # right leg vs. cranicm
                yield self.right_leg.is_collision_to_sphere(self.head.calc_cranicm_point(), self.head.get_cranicm_radius())

                # torso vs. left knee
                yield self.torso.is_collision_to_sphere(self.left_leg.calc_knee_point(), self.left_leg.get_knee_radius())

                # torso vs. left calf
                yield self.torso.is_collision_to_capsule(self.left_leg.calc_calf_upper_point(), self.left_leg.calc_foot_point(), self.left_leg.get_calf_radius())

                # torso vs. right knee
                yield self.torso.is_collision_to_sphere(self.right_leg.calc_knee_point(), self.right_leg.get_knee_radius())

                # torso vs. right calf
                yield self.torso.is_collision_to_capsule(self.right_leg.calc_calf_upper_point(), self.right_leg.calc_foot_point(), self.right_leg.get_calf_radius())

        for detection in collision_detection_generator():
            if detection:
                return True

        return False