Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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()