Ejemplo n.º 1
0
def main():
    print("============================================================")
    print(sys.argv[0] + ": Simulates a robot file and Python controller")
    if len(sys.argv) <= 1:
        print("USAGE: simtest.py [world_file] [controller files (.py)]")
    print("============================================================")
    if len(sys.argv) <= 1:
        exit()

    world = WorldModel()
    #load up any world items, control modules, or paths
    control_modules = []
    for fn in sys.argv[1:]:
        path, base = os.path.split(fn)
        mod_name, file_ext = os.path.splitext(base)
        if file_ext == '.py' or file_ext == '.pyc':
            sys.path.append(os.path.abspath(path))
            mod = importlib.import_module(mod_name, base)
            control_modules.append(mod)
        elif file_ext == '.path':
            control_modules.append(fn)
        else:
            res = world.readFile(fn)
            if not res:
                print("Unable to load model " + fn)
                print("Quitting...")
                sys.exit(1)
    viewer = MyGLViewer(world)

    for i, c in enumerate(control_modules):
        if isinstance(c, str):
            sys.path.append(os.path.abspath("../control"))
            import trajectory_controller
            #it's a path file, try to load it
            controller = trajectory_controller.make(world.robot(i), c)
        else:
            try:
                maker = c.make
            except AttributeError:
                print("Module", c.__name__, "must have a make() method")
                print("Quitting...")
                sys.exit(1)
            controller = maker(world.robot(i))
        viewer.sim.setController(world.robot(i), controller)

    vis.setWindowTitle("Klamp't Simulation Tester")
    if SPLIT_SCREEN_TEST:
        viewer2 = MyGLViewer(world)
        vis.setPlugin(viewer)
        vis.addPlugin(viewer2)
        viewer2.window.broadcast = True
        vis.show()
        while vis.shown():
            time.sleep(0.01)
        vis.kill()
    else:
        vis.run(viewer)
Ejemplo n.º 2
0
        path, base = os.path.split(fn)
        mod_name, file_ext = os.path.splitext(base)
        if file_ext == '.py' or file_ext == '.pyc':
            sys.path.append(os.path.abspath(path))
            mod = importlib.import_module(mod_name, base)
            control_modules.append(mod)
        elif file_ext == '.path':
            control_modules.append(fn)
        else:
            res = world.readFile(fn)
            if not res:
                raise RuntimeError("Unable to load model " + fn)
    viewer = MyGLViewer(world)

    for i, c in enumerate(control_modules):
        if isinstance(c, str):
            sys.path.append(os.path.abspath("../control"))
            import trajectory_controller
            #it's a path file, try to load it
            controller = trajectory_controller.make(world.robot(i), c)
        else:
            try:
                maker = c.make
            except AttributeError:
                print "Module", c.__name__, "must have a make() method"
                raise
            controller = maker(world.robot(i))
        viewer.controllers.append(controller)

    viewer.run()
Ejemplo n.º 3
0
        path,base = os.path.split(fn)
        mod_name,file_ext = os.path.splitext(base)
        if file_ext=='.py' or file_ext=='.pyc':
            sys.path.append(os.path.abspath(path))
            mod = importlib.import_module(mod_name,base)
            control_modules.append(mod)
        elif file_ext=='.path':
            control_modules.append(fn)
        else:
            res = world.readFile(fn)
            if not res:
                raise RuntimeError("Unable to load model "+fn)
    viewer = MyGLViewer(world)

    for i,c in enumerate(control_modules):
        if isinstance(c,str):
            sys.path.append(os.path.abspath("../control"))
            import trajectory_controller
            #it's a path file, try to load it
            controller = trajectory_controller.make(world.robot(i),c)
        else:
            try:
                maker = c.make
            except AttributeError:
                print "Module",c.__name__,"must have a make() method"
                raise
            controller = maker(world.robot(i))
        viewer.controllers.append(controller)
    
    viewer.run()
Ejemplo n.º 4
0
        try:
            output = json.loads(msg)
            return output
        except ValueError:
            #didn't parse properly
            print "Couldn't read Python object from JSON message '" + msg + "'"
            return None


if __name__ == "__main__":
    import sys
    import trajectory_controller

    host = 'localhost'
    port = 3456

    if len(sys.argv) == 1:
        print "Usage: %s [linear_path_file]\n" % (sys.argv[0], )
        print "By default connects to localhost:3456"
        exit()

    #by default, runs a trajectory controller
    pathfn = sys.argv[1]
    pycontroller = trajectory_controller.make(None, pathfn)
    s = ControllerClient((host, port), pycontroller)
    asyncore.loop()


def make(robot):
    return SerialController()
Ejemplo n.º 5
0
            return None
        try:
            output = json.loads(msg)
            return output
        except ValueError:
            #didn't parse properly
            print "Couldn't read Python object from JSON message '"+msg+"'"
            return None


if __name__ == "__main__":
    import sys
    import trajectory_controller

    host = 'localhost'
    port = 3456

    if len(sys.argv)==1:
        print "Usage: %s [linear_path_file]\n"%(sys.argv[0],)
        print "By default connects to localhost:3456"
        exit()
        
    #by default, runs a trajectory controller
    pathfn = sys.argv[1]
    pycontroller = trajectory_controller.make(None,pathfn)
    s = ControllerClient((host,port),pycontroller)
    asyncore.loop()

def make(robot):
    return SerialController()