class SIMULATION: def __init__(self,GUI,solutionID): self.solutionID = solutionID self.GUI = GUI self.physicsClient = p.connect(p.GUI if self.GUI else p.DIRECT) p.setAdditionalSearchPath(pybullet_data.getDataPath()) p.setGravity(0,0,-9.8) self.world = WORLD() self.robot = ROBOT(self.solutionID) def Get_Fitness(self): self.robot.Get_Fitness() def Run(self): for t in range(c.NUMBER_STEP): if self.GUI : time.sleep(1/240) p.stepSimulation() self.robot.Sense(t) self.robot.Think(t) self.robot.Act(t) def __del__(self): p.disconnect() '''
class SIMULATION: def __init__(self, directOrGui, solutionID): self.directOrGui = directOrGui if self.directOrGui == "DIRECT": self.physicsClient = p.connect(p.DIRECT) elif self.directOrGui == "GUI": self.physicsClient = p.connect(p.GUI) p.setAdditionalSearchPath(pybullet_data.getDataPath()) p.setGravity(0, 0, -9.8) self.world = WORLD() self.robot = ROBOT(solutionID) def Run(self): for i in range(350): p.stepSimulation() self.robot.Sense(i) self.robot.Think() self.robot.Act(i) if self.directOrGui == "GUI": t.sleep(1 / 60) def Get_Fitness(self, solutionID): self.robot.Get_Fitness(solutionID) def __del__(self): p.disconnect()