-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Import necessary libraries | ||
import gym | ||
import pybullet as p | ||
import time | ||
import pybullet_data | ||
|
||
# Define a class for simulation environments | ||
class SimulationEnvironment: | ||
def __init__(self, config_path): | ||
# Load configuration from file | ||
with open(config_path) as f: | ||
config = json.load(f) | ||
self.config = config | ||
|
||
# Initialize the simulation environment | ||
self.simulation = gym.make(self.config['simulation']['name']) | ||
|
||
def reset(self): | ||
# Reset the simulation environment | ||
state = self.simulation.reset() | ||
return state | ||
|
||
def step(self, action): | ||
# Step the simulation environment | ||
state, reward, done, info = self.simulation.step(action) | ||
return state, reward, done, info | ||
|
||
def render(self): | ||
# Render the simulation environment | ||
self.simulation.render() | ||
|
||
def close(self): | ||
# Close the simulation environment | ||
self.simulation.close() | ||
|
||
def setup_pybullet(self): | ||
# Set up the PyBullet physics engine | ||
p.connect(p.GUI) | ||
p.setAdditionalSearchPath(pybullet_data.getDataPath()) | ||
p.setGravity(0, 0, -10) | ||
p.setTimeStep(1./240.) | ||
p.setRealTimeSimulation(1) |