def get_and_save_data():
    for scene, angle in zip(["0", "l90", "r90"], [(90, 180), (0, 90),
                                                  (180, 270)]):
        environment = VrepEnvironment(settings.SCENES + '/room_calib_' +
                                      scene + '.ttt')
        # environment.start_vrep()
        environment.connect()
        environment.load_scene(settings.SCENES + '/room_calib_' + scene +
                               '.ttt')
        environment.start_simulation()
        agent = Pioneer(environment)
        time.sleep(1)

        sample = agent.read_lidars()
        ranges = np.array(sample)[angle[0]:angle[1]]
        for _ in range(0, 29):
            sample = agent.read_lidars()
            ranges += np.array(sample)[angle[0]:angle[1]]
        ranges = ranges / 10
        np.savetxt("ranges_" + scene + ".txt", ranges)

        environment.stop_simulation()
        environment.disconnect()
        del environment
Example #2
0
##########
##########

if __name__ == "__main__":
    plt.ion()
    # Initialize and start the environment
    environment = VrepEnvironment(settings.SCENES + '/room_static.ttt')  # Open the file containing our scene (robot and its environment)
    environment.connect()        # Connect python to the simulator's remote API
    agent   = Pioneer(environment)
    display = Display(agent, False) 

    print('\nDemonstration of Simultaneous Localization and Mapping using CoppeliaSim robot simulation software. \nPress "CTRL+C" to exit.\n')
    start = time.time()
    step  = 0
    done  = False
    environment.start_simulation()
    time.sleep(1)

    try:    
        while step < settings.simulation_steps and not done:
            display.update()                      # Update the SLAM display
            loop(agent)                           # Control loop
            step += 1
    except KeyboardInterrupt:
        print('\n\nInterrupted! Time: {}s'.format(time.time()-start))
        
    display.close()
    environment.stop_simulation()
    environment.disconnect()