Skip to content

Commit

Permalink
Create simulation_environment.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 11, 2024
1 parent f200d13 commit cfd29d3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions models/simulation/simulation_environment.py
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)

0 comments on commit cfd29d3

Please sign in to comment.