def setItems(self, items=None): """ Set a list of items for the item pager to page-through """ itemsPerPage = int(self.itemsPerPage) if iterableLength(items) <= itemsPerPage: self.showAllButton.remove() elif self.showAllButton.toggled(): itemsPerPage = iterableLength(items) self._pages_ = PositionController(items=items or [], startIndex=self._index_.value(), itemsPerPage=itemsPerPage, pagesShownAtOnce=int( self.pagesShownAtOnce)) self._index_.setValue(self._pages_.startIndex)
def create_controllers(pack_path): cmd_queue, settings, cp_dict, s_objs, s_walls, c_objs, cam_dict = get_configs( pack_path) arm_s = settings['arm_planning'] pos_s = settings['navigation'] # Creates all the controllers necessary for scene execution. # Offsets according to URDF. Have to be adjusted in case of frame changes! For more info refer to constructor in ArmController.py. arm_ctrl = ArmController(jnt_st=arm_s['joint_state_topic'], eef_offset=arm_s['eef_offset'], f_off_x=arm_s['f_off_x'], f_off_y=arm_s['f_off_y'], f_off_w=arm_s['f_off_w'], rbt_name=pos_s['robot_name']) s_ldr = SceneLoader(arm_ctrl.get_scene(), world_ff='world') pos_ctrl = PositionController(pos_s['robot_name'], c_objs=c_objs) opt_s = pos_s['optimization'] pos_ctrl.set_opt_params(opt_s['local_threshold'], opt_s['local_timeout'], opt_s['global_threshold'], opt_s['global_timeout']) rbt_ctrl = RobotController(cmd_queue, cp_dict, arm_ctrl, pos_ctrl, s_ldr, s_objs, s_walls) # Enable geoometric Alternative to avoid being stuck in a pose. rbt_ctrl.set_geo_alt(arm_s['set_geo_alt']) return arm_ctrl, s_ldr, pos_ctrl, rbt_ctrl
def setItems(self, items=None): """ Set a list of items for the item pager to page-through """ itemsPerPage = int(self.itemsPerPage) if iterableLength(items) <= itemsPerPage: self.showAllButton.remove() elif self.showAllButton.toggled(): itemsPerPage = iterableLength(items) self._pages_ = PositionController(items=items or [], startIndex=self._index_.value(), itemsPerPage=itemsPerPage, pagesShownAtOnce=int(self.pagesShownAtOnce)) self._index_.setValue(self._pages_.startIndex)
class ItemPager(Layout.Vertical): """ Paged Results: Encapsulates the UI logic for paging multiple item from a database or other source. """ signals = Base.TemplateElement.signals + ['jsIndexChanged'] properties = Base.TemplateElement.properties.copy() properties['itemsPerPage'] = {'action':'classAttribute', 'type':'int'} properties['pagesShownAtOnce'] = {'action':'classAttribute', 'type':'int'} def __init__(self, id, name=None, parent=None): Layout.Vertical.__init__(self, id, name, parent) positionLayout = self.addChildElement(Layout.Horizontal()) label = positionLayout.addChildElement(Display.Label()) label.setText('Showing Results') label.addClass('Spaced Word') self.resultsStartAt = positionLayout.addChildElement(Display.Label()) self.resultsStartAt.strong = True self.resultsStartAt.setText('1') self.resultsStartAt.addClass('SpacedWord') label = positionLayout.addChildElement(Display.Label()) label.setText('-') label.addClass('Spaced Word') self.resultsEndAt = positionLayout.addChildElement(Display.Label()) self.resultsEndAt.strong = True self.resultsEndAt.setText('25') self.resultsEndAt.addClass('SpacedWord') label = positionLayout.addChildElement(Display.Label()) label.setText('out of') label.addClass('Spaced Word') self.numberOfResults = positionLayout.addChildElement(Display.Label()) self.numberOfResults.strong = True self.numberOfResults.setText('100') self.numberOfResults.addClass('SpacedWord') self.showAllButton = positionLayout.addChildElement(Buttons.ToggleButton('showAllButton')) self.showAllButton.setText("Show All") buttonLayout = self.addChildElement(Layout.Horizontal()) self.startButton = buttonLayout.addChildElement(Buttons.Link()) self.startButton.setText("<<") self.startButton.setDestination("#Link") self.backButton = buttonLayout.addChildElement(Buttons.Link()) self.backButton.setText("< Back") self.backButton.setDestination("#Link") self.backButton.addClass("SpacedWord") self.pageLinks = buttonLayout.addChildElement(Layout.Flow()) self.nextButton = buttonLayout.addChildElement(Buttons.Link()) self.nextButton.setText("Next >") self.nextButton.setDestination("#Link") self.lastButton = buttonLayout.addChildElement(Buttons.Link()) self.lastButton.setText(">>") self.lastButton.setDestination("#Link") self.lastButton.addClass("SpacedWord") self.pagesShownAtOnce = 15 self.itemsPerPage = 25 self._index_ = self.addChildElement(HiddenInputs.HiddenIntValue(id + 'Index')) self._pages_ = None self.connect('beforeToHtml', None, self, '_updateUI_') self.showAllButton.addJavascriptEvent('onclick', "JUReplaceElement(this, JUBuildThrobber());") self.showAllButton.connect('jsToggled', None, self, 'jsSetNavigationIndex', 0) self.showAllButton.connect('toggled', True, self.showAllButton, 'setValue', 'Show in Pages') self.showAllButton.connect('toggled', False, self.showAllButton, 'setValue', 'Show All') def setItems(self, items=None): """ Set a list of items for the item pager to page-through """ itemsPerPage = int(self.itemsPerPage) if iterableLength(items) <= itemsPerPage: self.showAllButton.remove() elif self.showAllButton.toggled(): itemsPerPage = iterableLength(items) self._pages_ = PositionController(items=items or [], startIndex=self._index_.value(), itemsPerPage=itemsPerPage, pagesShownAtOnce=int(self.pagesShownAtOnce)) self._index_.setValue(self._pages_.startIndex) def currentPageItems(self): """ The items contained in the currently highlighted page """ return self._pages_.currentPageItems def jsSetNavigationIndex(self, index): """ Creates the javascript to switch to a different position within the items: index - the first item you want to appear in your pages results """ return ("JUGetElement('%(id)sIndex').value = '%(index)d';%(handlers)s;" % {'id':self.jsId(), 'index':index, 'handlers':"\n".join(self.emit('jsIndexChanged'))}) def _updateUI_(self): """ Updates the ui to reflect the currently selected page and provide links to other pages """ if not self._pages_: return elif not self.currentPageItems(): self.hide() return self.resultsStartAt.setText(self._pages_.startPosition) self.resultsEndAt.setText(self._pages_.nextPageIndex) self.numberOfResults.setText(self._pages_.length) if self._pages_.areMore: self.nextButton.show() self.lastButton.show() self.nextButton.addJavascriptEvent('onclick', self.jsSetNavigationIndex(self._pages_.nextPageIndex)) self.lastButton.addJavascriptEvent('onclick', self.jsSetNavigationIndex(self._pages_.lastPageIndex)) else: self.nextButton.hide() self.lastButton.hide() if self._pages_.arePrev: self.backButton.show() self.startButton.show() self.backButton.addJavascriptEvent('onclick', self.jsSetNavigationIndex(self._pages_.prevPageIndex)) self.startButton.addJavascriptEvent('onclick', self.jsSetNavigationIndex(0)) else: self.backButton.hide() self.startButton.hide() pageList = self._pages_.pageList() if len(pageList) > 1: for page in self._pages_.pageList(): link = self.pageLinks.addChildElement(Buttons.Link()) link.setText(unicode(page / self._pages_.itemsPerPage + 1)) link.addClass('SpacedWord') if page != self._index_.value(): link.setDestination('#Link') link.addJavascriptEvent('onclick', self.jsSetNavigationIndex(page))
def main(): main_pack = 'robot_cinematics' # Initialize the ROS node to enable all ROS functions. rospy.init_node('robot_controller', anonymous=True) # Check if Gazebo is running. try: rospy.wait_for_service('/gazebo/get_physics_properties', timeout=1) except rospy.ROSException: rospy.logerr("Gazebo not running, no scene execution possible!") return valid = False rospack = rospkg.RosPack() pack_path = rospack.get_path(main_pack) # Choose a scene configuration. print('##########################################') print('######### Choose a scene number! #########') print('##########################################') while not valid: s_nr = input() s_path = pack_path + "/cinematics/scene/scene" + str(s_nr) + ".yaml" try: with open(s_path, 'r') as stream: data = yaml.safe_load(stream) cmd_queue = Queue.Queue(maxsize=0) for i in range(1,len(data.keys())+1): if 'eef_angle' in data['action'+str(i)].keys(): if 'pi' in str(data['action'+str(i)]['eef_angle']): data['action'+str(i)]['eef_angle'] = data['action'+str(i)]['eef_angle'].replace('pi',str(math.pi)) data['action'+str(i)]['eef_angle'] = eval(data['action'+str(i)]['eef_angle']) cmd_queue.put(data['action'+str(i)]) valid = True except IOError: valid = False print "Please choose a valid number!" settings, cp_dict, s_objs, s_walls, c_objs = load_files(pack_path) # Reads all config files. arm_s = settings['arm_planning'] pos_s = settings['navigation'] # Creates all the controllers necessary for scene execution. # Settings are read from the yaml file in the demo/config folder! arm_ctrl = ArmController(arm_group = arm_s['arm_group'], jnt_st = arm_s['joint_state_topic'], eef_offset=arm_s['eef_offset'], f_off_x=arm_s['f_off_x'], f_off_y=arm_s['f_off_y'], f_off_w=arm_s['f_off_w'], rbt_name=pos_s['robot_name']) arm_ctrl.set_grab_type(arm_s['grab_type']) s_ldr = SceneLoader(arm_ctrl.get_scene(),world_ff='world') pos_ctrl = PositionController(pos_s['robot_name'], c_objs=c_objs) opt_s = pos_s['optimization'] pos_ctrl.set_opt_params(opt_s['local_threshold'], opt_s['local_timeout'], opt_s['global_threshold'], opt_s['global_timeout']) rbt_ctrl = RobotController(cmd_queue,cp_dict,arm_ctrl,pos_ctrl,s_ldr,s_objs, s_walls) # Enable geoometric Alternative to avoid being stuck in a pose. rbt_ctrl.set_geo_alt(arm_s['set_geo_alt']) print('#########################################') print('########## Record scene? (y/n) ##########') print('#########################################') ans = raw_input() if ans in ['y', 'Y']: # Records the scene to pack_path/videos. Overrides already existing videos! print('#########################################') print('##### Files will be stored under: ######') print('##### robot_cinematics/videos ######') print('#########################################') uuid = roslaunch.rlutil.get_or_generate_uuid(None, False) roslaunch.configure_logging(uuid) launch = roslaunch.parent.ROSLaunchParent(uuid, [pack_path + '/launch/camera_manager.launch']) launch.start() rospy.loginfo("Started camera manager.") rbt_ctrl.exec_scene() rospy.sleep(1) if ans in ['y', 'Y']: launch.shutdown()
class ItemPager(Layout.Vertical): """ Paged Results: Encapsulates the UI logic for paging multiple item from a database or other source. """ __slots__ = ( "resultsStartAt", "numberOfResults", "showAllButton", "startButton", "backButton", "pageLinks", "nextButton", "lastButton", "pagesShownAtOnce", "itemsPerPage", "_index_", "_pages_", "resultsEndAt", ) signals = Base.TemplateElement.signals + ["jsIndexChanged"] properties = Base.TemplateElement.properties.copy() properties["itemsPerPage"] = {"action": "classAttribute", "type": "int"} properties["pagesShownAtOnce"] = {"action": "classAttribute", "type": "int"} def __init__(self, id, name=None, parent=None, **kwargs): Layout.Vertical.__init__(self, id, name, parent, **kwargs) positionLayout = self.addChildElement(Layout.Horizontal()) positionLayout.addClass("WActions") label = positionLayout.addChildElement(Display.Label()) label.setText("Showing Results") label.addClass("WSpaced") self.resultsStartAt = positionLayout.addChildElement(Display.Label()) self.resultsStartAt.makeStrong() self.resultsStartAt.setText("1") self.resultsStartAt.addClass("WSpaced") label = positionLayout.addChildElement(Display.Label()) label.setText("-") label.addClass("WSpaced") self.resultsEndAt = positionLayout.addChildElement(Display.Label()) self.resultsEndAt.makeStrong() self.resultsEndAt.setText("25") self.resultsEndAt.addClass("WSpaced") label = positionLayout.addChildElement(Display.Label()) label.setText("out of") label.addClass("WSpaced") self.numberOfResults = positionLayout.addChildElement(Display.Label()) self.numberOfResults.makeStrong() self.numberOfResults.setText("100") self.numberOfResults.addClass("WSpaced") self.showAllButton = positionLayout.addChildElement(Buttons.ToggleButton("showAllButton")) self.showAllButton.setText("Show All") buttonLayout = self.addChildElement(Layout.Horizontal()) self.startButton = buttonLayout.addChildElement(Buttons.Link()) self.startButton.setText("<<") self.startButton.setDestination("#Link") self.backButton = buttonLayout.addChildElement(Buttons.Link()) self.backButton.setText("< Back") self.backButton.setDestination("#Link") self.backButton.addClass("WSpaced") self.pageLinks = buttonLayout.addChildElement(Layout.Flow()) self.nextButton = buttonLayout.addChildElement(Buttons.Link()) self.nextButton.setText("Next >") self.nextButton.setDestination("#Link") self.lastButton = buttonLayout.addChildElement(Buttons.Link()) self.lastButton.setText(">>") self.lastButton.setDestination("#Link") self.lastButton.addClass("WSpaced") self.pagesShownAtOnce = 15 self.itemsPerPage = 25 self._index_ = self.addChildElement(HiddenInputs.HiddenIntValue(id + "Index")) self._pages_ = None self.connect("rendering", None, self, "_updateUI_") self.showAllButton.addJavascriptEvent("onclick", "WebElements.replace(this, WebElements.buildThrobber());") self.showAllButton.connect("jsToggled", None, self, "jsSetNavigationIndex", 0) self.showAllButton.connect("toggled", True, self.showAllButton, "setValue", "Show in Pages") self.showAllButton.connect("toggled", False, self.showAllButton, "setValue", "Show All") def setItems(self, items=None): """ Set a list of items for the item pager to page-through """ itemsPerPage = int(self.itemsPerPage) if iterableLength(items) <= itemsPerPage: self.showAllButton.remove() elif self.showAllButton.toggled(): itemsPerPage = iterableLength(items) self._pages_ = PositionController( items=items or [], startIndex=self._index_.value(), itemsPerPage=itemsPerPage, pagesShownAtOnce=int(self.pagesShownAtOnce), ) self._index_.setValue(self._pages_.startIndex) def currentPageItems(self): """ The items contained in the currently highlighted page """ return self._pages_.currentPageItems def jsSetNavigationIndex(self, index): """ Creates the javascript to switch to a different position within the items: index - the first item you want to appear in your pages results """ return "WebElements.get('%(id)sIndex').value = '%(index)d';%(handlers)s;" % { "id": self.fullId(), "index": index, "handlers": "\n".join([ClientSide.var(result) for result in self.emit("jsIndexChanged")]), } def _updateUI_(self): """ Updates the ui to reflect the currently selected page and provide links to other pages """ if not self._pages_: return elif not self.currentPageItems(): self.hide() return self.resultsStartAt.setText(self._pages_.startPosition) self.resultsEndAt.setText(self._pages_.nextPageIndex) self.numberOfResults.setText(self._pages_.length) if self._pages_.areMore: self.nextButton.show() self.lastButton.show() self.nextButton.addJavascriptEvent("onclick", self.jsSetNavigationIndex(self._pages_.nextPageIndex)) self.lastButton.addJavascriptEvent("onclick", self.jsSetNavigationIndex(self._pages_.lastPageIndex)) else: self.nextButton.hide() self.lastButton.hide() if self._pages_.arePrev: self.backButton.show() self.startButton.show() self.backButton.addJavascriptEvent("onclick", self.jsSetNavigationIndex(self._pages_.prevPageIndex)) self.startButton.addJavascriptEvent("onclick", self.jsSetNavigationIndex(0)) else: self.backButton.hide() self.startButton.hide() pageList = self._pages_.pageList() if len(pageList) > 1: for page in self._pages_.pageList(): link = self.pageLinks.addChildElement(Buttons.Link()) link.setText(unicode(page / self._pages_.itemsPerPage + 1)) link.addClass("WSpaced") if page != self._index_.value(): link.setDestination("#Link") link.addJavascriptEvent("onclick", self.jsSetNavigationIndex(page))
class ItemPager(Layout.Vertical): """ Paged Results: Encapsulates the UI logic for paging multiple item from a database or other source. """ signals = Base.TemplateElement.signals + ['jsIndexChanged'] properties = Base.TemplateElement.properties.copy() properties['itemsPerPage'] = {'action': 'classAttribute', 'type': 'int'} properties['pagesShownAtOnce'] = { 'action': 'classAttribute', 'type': 'int' } def __init__(self, id, name=None, parent=None): Layout.Vertical.__init__(self, id, name, parent) positionLayout = self.addChildElement(Layout.Horizontal()) label = positionLayout.addChildElement(Display.Label()) label.setText('Showing Results') label.addClass('Spaced Word') self.resultsStartAt = positionLayout.addChildElement(Display.Label()) self.resultsStartAt.strong = True self.resultsStartAt.setText('1') self.resultsStartAt.addClass('SpacedWord') label = positionLayout.addChildElement(Display.Label()) label.setText('-') label.addClass('Spaced Word') self.resultsEndAt = positionLayout.addChildElement(Display.Label()) self.resultsEndAt.strong = True self.resultsEndAt.setText('25') self.resultsEndAt.addClass('SpacedWord') label = positionLayout.addChildElement(Display.Label()) label.setText('out of') label.addClass('Spaced Word') self.numberOfResults = positionLayout.addChildElement(Display.Label()) self.numberOfResults.strong = True self.numberOfResults.setText('100') self.numberOfResults.addClass('SpacedWord') self.showAllButton = positionLayout.addChildElement( Buttons.ToggleButton('showAllButton')) self.showAllButton.setText("Show All") buttonLayout = self.addChildElement(Layout.Horizontal()) self.startButton = buttonLayout.addChildElement(Buttons.Link()) self.startButton.setText("<<") self.startButton.setDestination("#Link") self.backButton = buttonLayout.addChildElement(Buttons.Link()) self.backButton.setText("< Back") self.backButton.setDestination("#Link") self.backButton.addClass("SpacedWord") self.pageLinks = buttonLayout.addChildElement(Layout.Flow()) self.nextButton = buttonLayout.addChildElement(Buttons.Link()) self.nextButton.setText("Next >") self.nextButton.setDestination("#Link") self.lastButton = buttonLayout.addChildElement(Buttons.Link()) self.lastButton.setText(">>") self.lastButton.setDestination("#Link") self.lastButton.addClass("SpacedWord") self.pagesShownAtOnce = 15 self.itemsPerPage = 25 self._index_ = self.addChildElement( HiddenInputs.HiddenIntValue(id + 'Index')) self._pages_ = None self.connect('beforeToHtml', None, self, '_updateUI_') self.showAllButton.addJavascriptEvent( 'onclick', "JUReplaceElement(this, JUBuildThrobber());") self.showAllButton.connect('jsToggled', None, self, 'jsSetNavigationIndex', 0) self.showAllButton.connect('toggled', True, self.showAllButton, 'setValue', 'Show in Pages') self.showAllButton.connect('toggled', False, self.showAllButton, 'setValue', 'Show All') def setItems(self, items=None): """ Set a list of items for the item pager to page-through """ itemsPerPage = int(self.itemsPerPage) if iterableLength(items) <= itemsPerPage: self.showAllButton.remove() elif self.showAllButton.toggled(): itemsPerPage = iterableLength(items) self._pages_ = PositionController(items=items or [], startIndex=self._index_.value(), itemsPerPage=itemsPerPage, pagesShownAtOnce=int( self.pagesShownAtOnce)) self._index_.setValue(self._pages_.startIndex) def currentPageItems(self): """ The items contained in the currently highlighted page """ return self._pages_.currentPageItems def jsSetNavigationIndex(self, index): """ Creates the javascript to switch to a different position within the items: index - the first item you want to appear in your pages results """ return ( "JUGetElement('%(id)sIndex').value = '%(index)d';%(handlers)s;" % { 'id': self.jsId(), 'index': index, 'handlers': "\n".join(self.emit('jsIndexChanged')) }) def _updateUI_(self): """ Updates the ui to reflect the currently selected page and provide links to other pages """ if not self._pages_: return elif not self.currentPageItems(): self.hide() return self.resultsStartAt.setText(self._pages_.startPosition) self.resultsEndAt.setText(self._pages_.nextPageIndex) self.numberOfResults.setText(self._pages_.length) if self._pages_.areMore: self.nextButton.show() self.lastButton.show() self.nextButton.addJavascriptEvent( 'onclick', self.jsSetNavigationIndex(self._pages_.nextPageIndex)) self.lastButton.addJavascriptEvent( 'onclick', self.jsSetNavigationIndex(self._pages_.lastPageIndex)) else: self.nextButton.hide() self.lastButton.hide() if self._pages_.arePrev: self.backButton.show() self.startButton.show() self.backButton.addJavascriptEvent( 'onclick', self.jsSetNavigationIndex(self._pages_.prevPageIndex)) self.startButton.addJavascriptEvent('onclick', self.jsSetNavigationIndex(0)) else: self.backButton.hide() self.startButton.hide() pageList = self._pages_.pageList() if len(pageList) > 1: for page in self._pages_.pageList(): link = self.pageLinks.addChildElement(Buttons.Link()) link.setText(unicode(page / self._pages_.itemsPerPage + 1)) link.addClass('SpacedWord') if page != self._index_.value(): link.setDestination('#Link') link.addJavascriptEvent('onclick', self.jsSetNavigationIndex(page))