Added Gui (unfinished)
config into dataclass and enums new Gui that includes settings deleted GlobalVariables small fixes (import, names...)
This commit is contained in:
+29
-17
@@ -5,21 +5,31 @@ import time
|
||||
import math
|
||||
import numpy as np
|
||||
import pybullet as p
|
||||
import pybullet_data # Added missing import
|
||||
|
||||
import config as cfg
|
||||
from config import cfg
|
||||
import DataTypes as dt
|
||||
|
||||
|
||||
class Simulation:
|
||||
def __init__(self):
|
||||
self.physics_client = p.connect(p.GUI)
|
||||
self.robot = p.loadURDF(cfg.urdf_path, useFixedBase=True)
|
||||
def __init__(self, urdf_path: str = cfg.urdf_path):
|
||||
self.urdf_path = urdf_path
|
||||
|
||||
# Connect to PyBullet GUI
|
||||
self.physicsClient = p.connect(p.GUI)
|
||||
p.setAdditionalSearchPath(pybullet_data.getDataPath())
|
||||
p.setGravity(0, 0, -9.81)
|
||||
|
||||
# Load plane and robot URDF
|
||||
self.planeId = p.loadURDF("plane.urdf")
|
||||
self.robot = p.loadURDF(self.urdf_path, [0, 0, 0.2])
|
||||
|
||||
self.revolute_joints = [
|
||||
i
|
||||
for i in range(p.getNumJoints(self.robot))
|
||||
if p.getJointInfo(self.robot, i)[2] == p.JOINT_REVOLUTE
|
||||
]
|
||||
# Discover revolute joint indices dynamically
|
||||
self.revolute_joints = []
|
||||
for j in range(p.getNumJoints(self.robot)):
|
||||
joint_info = p.getJointInfo(self.robot, j)
|
||||
if joint_info[2] == p.JOINT_REVOLUTE:
|
||||
self.revolute_joints.append(j)
|
||||
|
||||
self.set_all_joints_to_90()
|
||||
p.resetDebugVisualizerCamera(
|
||||
@@ -30,11 +40,8 @@ class Simulation:
|
||||
)
|
||||
|
||||
def set_all_joints_to_90(self):
|
||||
for joint_index in range(p.getNumJoints(self.robot)):
|
||||
joint_info = p.getJointInfo(self.robot, joint_index)
|
||||
joint_type = joint_info[2]
|
||||
if joint_type == p.JOINT_REVOLUTE:
|
||||
p.resetJointState(self.robot, joint_index, math.radians(90))
|
||||
for joint_index in self.revolute_joints:
|
||||
p.resetJointState(self.robot, joint_index, math.radians(90))
|
||||
|
||||
def updatePos(self, current_rad: dt.RadArray):
|
||||
radflat = current_rad.data.flatten()
|
||||
@@ -51,7 +58,12 @@ class Simulation:
|
||||
p.stepSimulation()
|
||||
|
||||
def disconnect(self):
|
||||
p.disconnect(self.physics_client)
|
||||
if p.isConnected(self.physicsClient):
|
||||
p.disconnect(self.physicsClient)
|
||||
|
||||
def close(self):
|
||||
"""Cleanup wrapper for Robot backend compatibility."""
|
||||
self.disconnect()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -62,7 +74,7 @@ if __name__ == "__main__":
|
||||
backend = PyBulletBackend(sim_instance)
|
||||
|
||||
# 2. Instantiate Robot with simulation backend
|
||||
robot = Robot(backend=backend)
|
||||
robot = Robot(backend_type=backend)
|
||||
robot.reset_to_init()
|
||||
|
||||
# 3. Command forward movement [vx, vy, omega]
|
||||
@@ -71,7 +83,7 @@ if __name__ == "__main__":
|
||||
# 4. Main test execution loop
|
||||
try:
|
||||
while True:
|
||||
# Executes state machine logic (Idle -> Walking -> Target Step -> Physics Step)
|
||||
# Executes state machine logic
|
||||
robot.tick()
|
||||
time.sleep(1.0 / 60.0)
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in New Issue
Block a user