def start(screen): """Fonction s'occupant rapidement de la boucle de jeu""" state = ["read_scene", 'super_choice', ''] in_game = True while in_game: if state[0] == "quit": in_game = False elif state[0] == "main_menu": menu = MainMenu.MainMenu(screen) state = menu.start() elif state[0] == "read_scene": json_scene = utils.load_scene(state[1]) menu = None if json_scene["type"] == "choice": menu = ReadChoice(screen, state[1], state[2]) else: menu = ReadScene(screen, state[1], state[2]) state = menu.start()
max_err = 0.0035 elif 'm4' in args.config: max_err = 0.005 elif 'm3' in args.config: max_err = 0.0035 else: raise ValueError() config = json.load(open(args.config)) rospy.init_node('servo') r_b = Robot.from_ip('192.168.1.129') r_c = Robot.from_ip('192.168.1.131') scene, state = utils.load_scene() # cam safe q r_c.ctrl.moveJ([ 2.2288451194763184, -1.490114526157715, 1.5134428183185022, -0.8572123807719727, -1.3860304991351526, -0.5580604712115687 ]) for q, r in zip(config['robots_q_init'], [r_b, r_c]): r.ctrl.moveJ(q) r_b.zero_ft_sensor() base_t_tcp_b_init = r_b.base_t_tcp() for _ in range(args.n): if rospy.is_shutdown(): break
def my_app(cfg): thread_pool = multiprocessing.pool.ThreadPool() log.info(f'{cfg}') log.info(f'Working directory : {os.getcwd()}') if cfg.unet.ssp == 'tailored': size_stride_pad = [[[4, 4], [4, 4], [3, 4], [3, 4]], [2, 2, 2, 2], [[1, 1], [1, 1], [0, 1], [0, 1]]] else: size_stride_pad = [[4] * 6, [2] * 6, [1] * 6] n_features = [ 1 * cfg.unet.m, 2 * cfg.unet.m, 3 * cfg.unet.m, 4 * cfg.unet.m, 5 * cfg.unet.m ] net = torch.nn.Sequential( utils.conv_4x4_bn(3, cfg.unet.m // 2, 2), utils.conv_4x4_bn(cfg.unet.m // 2, cfg.unet.m, 2), utils.UNet(2, n_features, *size_stride_pad, cfg.unet.depth, join=cfg.unet.join, hs=cfg.unet.hs, t=cfg.unet.t), torch.nn.Conv2d(cfg.unet.m, 1 + cfg.n_multipred, 1, 1, 0), torch.nn.Upsample(scale_factor=8)) net.load_state_dict(torch.load(cfg.unet.name, map_location=cfg.device)[1]) net.eval() net.to(cfg.device) s = utils.load_scene(cfg, net) utils.prematch_scene(cfg, s, thread_pool) s['ransac matches'] = {} def f(k): torch.set_num_threads(1) if k[0] + 1 == k[1]: b = utils.PairwiseRidgeSfM(s, k, reps=64, precision=cfg.precision, min_matches=16, iters=3, gr=0.2, weight_decay=cfg.lmbda).backup else: b = utils.PairwiseRidgeSfM(s, k, reps=32, precision=cfg.precision, min_matches=16, iters=3, gr=0.2, weight_decay=cfg.lmbda).backup return b betas = list( tqdm(thread_pool.imap_unordered(f, s['matches'].keys()), desc='Pairwise-RidgeSfM', total=len(s['matches']))) for b in betas: if len(b) > 3: s['ransac matches'][b['k']] = b scene = utils.GlobalBundleAdjustment(s).to(cfg.device) scene.make_optim() for i in range(scene.bundle_k.size(0) * 6): active_k = min((i // 5 + 1), scene.bundle_k.size(0)) n_cams = scene.bundle_k[active_k - 1][1] scene.bundle_init(active_k, i % 1000 == 0) for i in range(12): scene.flub(i) scene.vid_plot(cfg.outdir + f'/scene{cfg.scene.n}_frameskip{cfg.scene.frameskip}', frame_rate={ 1: 24, 3: 8, 10: 3, 30: 1 }[cfg.scene.frameskip], cam_skip={ 1: 10, 3: 3, 10: 1, 30: 1 }[cfg.scene.frameskip], device=cfg.device) out_file = eval_scannet.get_dumpfile(cfg.outdir, s['file_name']) scene.pose(out_file)
def start(screen): """Fonction s'occupant rapidement de la boucle de jeu""" state = ["main_menu"] in_game = True while in_game: if state[0] == "quit": in_game = False elif state[0] == "main_menu": menu = MainMenu.MainMenu(screen) state = menu.start() elif state[ 0] == "create_scene": # Quand on clique sur "Nouvelle scène", on doit taper un nom # Si la scène existe déjà, on l'édit aussi menu = NewSceneAsk(screen) info = menu.start() if info[0] == "quit": return [ "quit", ] if not os.path.isfile("scenes/scene_" + info[0] + ".json"): empty_json = "" if info[1]: empty_json = '{"type": "choice", "personnages":[], "background": "", "music":"", "choices":[]}' else: empty_json = '{"type":"scene", "personnages": [], "flags": [], "events": [], "background": "", "music":"", "text": "", "next":""}' utils.save_scene(empty_json, info[0]) state = ["edit_scene", info[0]] elif state[ 0] == "choose_scene": # Quand on clique sur "Ouvrir un scène", on doit taper laquelle on veut modif menu = AskInfo.AskInfo(screen, "Entrez le nom de la scène à modifier :") exist = False info = menu.start() if info[0] == "quit": return [ "quit", ] while not exist: # Check si la scène existe ou non if info[0] == "quit": return [ "quit", ] elif not os.path.isfile("scenes/scene_" + info + ".json"): info = menu.start("La scène " + info + " n'existe pas.") else: exist = True state = ["edit_scene", info] elif state[ 0] == "edit_scene": # Une fois que le nom de scène a été choisi # On doit commencer par récupérer le json name_scene = str(state[1]) json_scene = utils.load_scene(name_scene) menu = None if json_scene["type"] == "choice": menu = EditChoice(screen, json_scene) else: menu = EditScene.EditScene(screen, json_scene) state = menu.start() if len(state) > 1: # Ici, on a reçu un json à enregistrer utils.save_scene(state[1], name_scene) # On demande un nom, pour commencer directement la prochaine save menu = AskInfo.AskInfo(screen, "Nom de la prochaine scene :") next_scene_name = menu.start() if next_scene_name[0] != "quit": # On enregistre directement le champs next de l'ancienne scene json_old = json.loads(state[1]) if json_old.get("next", False): json_old["next"] = next_scene_name utils.save_scene(json.dumps(json_old), name_scene) if not os.path.isfile("scenes/scene_" + next_scene_name + ".json"): # Pour gagner du temps, on reprend le même background, et la même musique que pour la scène précédente # Il y a de grandes chances que ces deux attributs ne changent pas d'une scène à l'autre new_json = '{"personnages": [], "flags": [], "events": [], "background": "' + json_old[ "background"] + '", "music":"' + json_old[ "music"] + '", "text": "", "next":""}' utils.save_scene(new_json, next_scene_name) state = ["edit_scene", next_scene_name] else: return [ 'quit', ]