Skip to content
Snippets Groups Projects
Select Git revision
  • 49e58574a7afac6db57d158ff56199dc788016a0
  • master default protected
2 results

main_test.py

Blame
  • main_test.py 1.13 KiB
    # -*- coding: utf-8 -*-
    """
    Created on Tue Jan 12 17:17:49 2021
    
    @author: theob
    """
    
    import asyncio
    import Gym_new
    import time
    import nest_asyncio
    import show_image as si
    
        
    
    async def main():
        image_mode = 'L'
        
        
        env = Gym_new.Gym()
        await env.connect_websocket()
        
        # Resets the enviroment
        observation, reward, done, info = await env.reset("",0.01)
        print(observation)
        print(reward)
        print(done)
        
        # Makes 1 step only driving straight
        observation, reward, done, info = await env.step("accelerate,screen_on", 0.17) 
        print(observation) 
        # Obeservation is an array with the following information: 
        # [speed, steering-angle, [length of all sensors (starting straight and then clockwise around the car)]]
        print(reward)
        print(done)
        
        try:
        # Test show Image
            si.show_image(image_mode,info['thumbnail']['width'],info['thumbnail']['height'],info['thumbnail']['image'])
        except Exception as e:
            print("failed showing image: " + str(e))
    
    if __name__ == "__main__":
        nest_asyncio.apply()
        loop = asyncio.get_event_loop()
        loop.run_until_complete(main())