def PreSetup(args, SetupFunction): if agxPython.getContext(): return init = agx.AutoInit() ## Create an application with graphics etc. app = agxOSG.ExampleApplication() dec = app.getSceneDecorator() dec.setBackgroundColor(agx.Vec3(1,1,1)) dec.setLogoFile('textures/TF-loader.png') dec.setLogoLocation(agxOSG.SceneDecorator.FREE) width = 0.25 dec.setLogoPosition(0.5-width/2, 0.3) dec.setMaximumLogoDimension(width, 1.0) ## Create a command line parser. sys.executable will point to python executable ## in this case, because getArgumentName(0) needs to match the C argv[0] which ## is the name of the program running argParser = agxIO.ArgumentParser([sys.executable] + args) app.addScene(argParser.getArgumentName(1), "buildScene", ord('1'), True) ## Call the init method of ExampleApplication ## It will setup the viewer, windows etc. if app.init(argParser): app.run() else: print("An error occurred while initializing ExampleApplication.")
def __init__(self, scene_path, n_substeps, n_actions, observation_type, image_size, camera_pose, no_graphics, args): """Initializes a AgxEnv object :param scene_path: path to binary file containing serialized simulation defined in sim/ folder :param n_substeps: number os simulation steps per call to step() :param n_actions: number of actions (DoF) :param camera_pose: dictionary containing EYE, CENTER, UP information for rendering :param args: arguments for agxViewer """ self.scene_path = scene_path self.n_substeps = n_substeps self.render_to_image = [] self.image_size = image_size self.no_graphics = no_graphics # Initialize AGX simulation self.gravity = None self.time_step = None self.init = agx.AutoInit() self.sim = agxSDK.Simulation() self._build_simulation() # Initialize OSG ExampleApplication self.app = agxOSG.ExampleApplication(self.sim) self.args = args self.root = None self.camera_pose = camera_pose if not no_graphics: self._add_rendering(mode='osg') # TODO: Is this needed? self.fps = int(np.round(1.0 / self.dt)) self.np_random = None self.seed() self.n_actions = n_actions self.observation_type = observation_type if not no_graphics: self._render_callback() obs = self._get_observation() self.observation_space = spaces.Box(low=-1, high=1, shape=(obs.shape), dtype=np.float32) self.action_space = spaces.Box(-1., 1., shape=(self.n_actions,), dtype='float32')
def init_app(**kwargs): """Initialize AGX and ExampleApplication. Template: init = init_app( name = __name__, scenes = [ ( 'buildScene', '1' ) ] ) IMPORTANT: - agx.AutoInit is returned at MUST be captured! Otherwise AGX will crash during exit. - The name has to be __name__ in the script you're calling this function. Examples: from agxPythonModules.utils.environment import init_app init = init_app( name = __name__, scenes = [ ( buildScene, '1' ), ( 'anotherScene', agxSDK.GuiEventListener.KEY_F1 ) ], autoStepping = True, # Default: False onInitialized = lambda app: print( 'App successfully initialized.' ), onShutdown = lambda app: print( 'App successfully shut down.' ) ) Arguments: name: str -- __name__ of the script this function is called from scenes: [] -- List of scene tuples (scene name or function, string key or int), e.g., [ (buildScene1, '1'), 'buildScene2', ord( '2' ) ] onInitialized: callable -- Callback when ExampleApplication has been initialized. This callback is only fired once - i.e., not when reloading the script. autoStepping: bool -- False to start paused. Default False. Returns: agx.AutoInit -- Instance of agx.AutoInit that MUST be captured. """ ## Entry point when this script is loaded with python if kwargs['name'] == "__main__": if agxPython.getContext() is None: init = agx.AutoInit() _applicationMain(**kwargs) return init return None
plt.show() exit() fig = plt.figure(figsize=[6.4, 2.8]) ax = fig.add_subplot(1, 1, 1) # ax.plot(np.array([-8,5]),np.array([0,0]), color = 'black') ax.plot(x_gt_mpc_1[0, :, 0], x_gt_mpc_1[0, :, 1], color = 'lightsteelblue') ax = agx_sim.mpcc.draw_soil(ax,-5, 5) ax = agx_sim.mpcc.draw_path(ax, -10, -5) ax.set_ylabel(r'$\mathit{y}$ $(m)$') ax.set_xlabel(r'$\mathit{x}$ $(m)$') ax.axis('equal') plt.tight_layout() ax.set_xlim(-4.5,0.0) ax.set_ylim(np.amin(x_gt_mpc_1[0, :, 1])-0.5, np.amax(x_gt_mpc_1[0, :, 1]) + 0.5) plt.show() # Entry point when this script is loaded with python if agxPython.getContext() is None: init = agx.AutoInit() main(sys.argv)
def __init__(self, scene_path, n_substeps, n_actions, observation_config, camera_pose, osg_window, agx_only, args): """Initializes a AgxEnv object :param str scene_path: path to binary file containing serialized simulation defined in sim/ folder :param int n_substeps: number os simulation steps per call to step() :param int n_actions: number of actions (DoF) :param gym_agx.rl.observation.ObservationConfig observation_config: observation configuration object :param dict camera_pose: dictionary containing EYE, CENTER, UP information for rendering :param bool osg_window: enables/disables window rendering (useful for training) :param bool agx_only: enables/disables all rendering (useful for training which does not use images) :param list args: arguments for agxViewer """ self.render_mode = 'osg' self.scene_path = scene_path self.n_substeps = n_substeps self.gravity = None self.time_step = None self.init = agx.AutoInit() self.sim = agxSDK.Simulation() self._build_simulation() self.app = None self.root = None self.camera_pose = camera_pose self.osg_window = osg_window self.agx_only = agx_only self.n_actions = n_actions self.observation_config = observation_config self.args = args if not self.agx_only: self.app = agxOSG.ExampleApplication(self.sim) self.args = self.args + [ '--window', 2 * observation_config.image_size[1], 2 * observation_config.image_size[0] ] if self.osg_window: if self.observation_config.depth_in_obs or self.observation_config.rgb_in_obs: warnings.warn(( "OSG window is enabled! \n" "=======> Observations contain image data (OSG rendering cannot be disabled). \n" "=======> Rendering is done inside step(). No need to call render()." )) else: warnings.warn(( "OSG window is enabled! \n" "=======> Observations do not contain image data. \n" "=======> Rendering is done inside render(), do not use 'human' or 'depth' mode." )) else: self.args = self.args + ['--osgWindow', '0'] if self.observation_config.depth_in_obs or self.observation_config.rgb_in_obs: warnings.warn(( "OSG window is disabled! \n" "=======> Observations contain image data (OSG rendering cannot be enabled). \n" "=======> Rendering is done inside step(), " "only 'human' or 'depth' modes available.")) else: warnings.warn( ("OSG window is disabled! \n" "=======> Observations do not contain image data. \n" "=======> Rendering is done inside render(), " "only 'human' or 'depth' modes available.")) self.render_to_image = [] self.img_object = None # TODO: Is this needed? self.fps = int(np.round(1.0 / self.dt)) self.np_random = None self.seed() self.goal = self._sample_goal() obs = self._get_observation() self.obs_space = construct_space(obs['observation']) self.goal_space = construct_space(obs['desired_goal']) self.action_space = spaces.Box(-1., 1., shape=(self.n_actions, ), dtype='float32') self.observation_space = spaces.Dict( dict(desired_goal=self.goal_space, achieved_goal=self.goal_space, observation=self.obs_space))