diff --git a/examples/01_basic.py b/examples/01_basic.py index fdc511e..562c10b 100644 --- a/examples/01_basic.py +++ b/examples/01_basic.py @@ -22,6 +22,5 @@ async def main(): print(tcp_pose) - if __name__ == "__main__": asyncio.run(main()) diff --git a/wandelbots/core/motion_group.py b/wandelbots/core/motion_group.py index 453e82d..2c0ce35 100644 --- a/wandelbots/core/motion_group.py +++ b/wandelbots/core/motion_group.py @@ -107,8 +107,6 @@ async def plan(self, path: MotionTrajectory, tcp: str) -> wb.models.PlanTrajecto current_joints = await self.joints(tcp=tcp) robot_setup = await self._get_optimizer_setup(tcp=tcp) - - # TODO: paths = [wb.models.MotionCommandPath(**path.model_dump()) for path in path.motions] paths = [wb.models.MotionCommandPath.from_json(path.model_dump_json()) for path in path.motions] motion_commands = [wb.models.MotionCommand(path=path) for path in paths] @@ -170,7 +168,6 @@ async def move_along_path( if joint_velocities is not None: limit_override.joint_velocity_limits = wb.models.Joints(joints=joint_velocities) - # Iterator that moves the robot to start of motion move_to_trajectory_stream = motion_api.stream_move_to_trajectory_via_joint_ptp( cell=self._cell, motion=load_plan_response.motion, location_on_trajectory=0 @@ -181,14 +178,11 @@ async def move_along_path( playback_speed_in_percent = 100 responses = [] + async def movement_controller( - response_stream: AsyncGenerator, + response_stream: AsyncGenerator, ) -> (AsyncGenerator)[wb.models.ExecuteTrajectoryRequest, wb.models.ExecuteTrajectoryResponse]: - yield wb.models.InitializeMovementRequest( - trajectory=load_plan_response.motion, - initial_location=0, - ) - + yield wb.models.InitializeMovementRequest(trajectory=load_plan_response.motion, initial_location=0) initialize_movement_response = await anext(response_stream) print(f"initial move response {initialize_movement_response}") @@ -200,9 +194,7 @@ async def movement_controller( for action in path.actions ] - yield wb.models.StartMovementRequest( - set_ios=set_io_list, - ) + yield wb.models.StartMovementRequest(set_ios=set_io_list) async for execute_trajectory_response in response_stream: response = execute_trajectory_response.actual_instance @@ -216,7 +208,6 @@ async def movement_controller( await motion_api.execute_trajectory(self._cell, movement_controller) - """ if any(isinstance(motion, dts.UnresolvedMotion) for motion in path.motions) or collision_scene is not None: current_joints = await self._get_current_joints() diff --git a/wandelbots/core/nova.py b/wandelbots/core/nova.py index 0d9985d..763b5cd 100644 --- a/wandelbots/core/nova.py +++ b/wandelbots/core/nova.py @@ -53,8 +53,8 @@ def __init__( ): self._api_client = self._init_api_client(host, username, password, access_token, version) - - def _init_api_client(self, + def _init_api_client( + self, host: str | None = None, username: str | None = None, password: str | None = None, @@ -82,11 +82,11 @@ def _init_api_client(self, ) return wb.ApiClient(api_client_config) - def cell(self, cell_id: str = "cell") -> "Cell": # TODO check if the cell exists return Cell(self._api_client, cell_id) + class Cell: def __init__(self, api_client: wb.ApiClient, cell_id: str): self._api_client = api_client @@ -100,4 +100,4 @@ async def controller(self, controller_host: str = None) -> "Controller": if found_controller is None: raise ControllerNotFoundException(controller=controller_host) - return Controller(api_client=self._api_client, cell=self._cell_id, controller_host=found_controller.host) \ No newline at end of file + return Controller(api_client=self._api_client, cell=self._cell_id, controller_host=found_controller.host) diff --git a/wandelbots/core/planner.py b/wandelbots/core/planner.py deleted file mode 100644 index 71e7207..0000000 --- a/wandelbots/core/planner.py +++ /dev/null @@ -1,11 +0,0 @@ -from abc import ABC, abstractmethod - - -class Planner(ABC): - @abstractmethod - def plan(self): - pass - - -class DefaultPlanner(Planner): - pass diff --git a/wandelbots/types/motion.py b/wandelbots/types/motion.py index 192b34b..9c9c1f0 100644 --- a/wandelbots/types/motion.py +++ b/wandelbots/types/motion.py @@ -204,10 +204,7 @@ class JointPTP(Motion): @pydantic.model_serializer def custom_serialize(self): - return { - "target_joint_position": list(self.target), - "path_definition_name": "PathJointPTP", - } + return {"target_joint_position": list(self.target), "path_definition_name": "PathJointPTP"} def jnt(target: tuple[float, ...], settings: MotionSettings = MotionSettings()) -> JointPTP: diff --git a/wandelbots/types/pose.py b/wandelbots/types/pose.py index cb02d0e..4f712ac 100644 --- a/wandelbots/types/pose.py +++ b/wandelbots/types/pose.py @@ -5,6 +5,7 @@ from scipy.spatial.transform import Rotation as R + class Position(Vector3d): """A position @@ -69,7 +70,6 @@ def __round__(self, n=None): tuple([round(a, 1) for a in pos_and_rot_vector[:3]] + [round(a, 3) for a in pos_and_rot_vector[3:]]) ) - def to_tuple(self) -> tuple[float, float, float, float, float, float]: """Return the pose as a tuple @@ -100,7 +100,6 @@ def from_tuple(cls, value: tuple[float, float, float, float, float, float]): def __getitem__(self, item): return self.to_tuple()[item] - def __matmul__(self, other): if isinstance(other, Pose): transformed_matrix = np.dot(self.matrix, other.matrix) @@ -112,7 +111,6 @@ def __matmul__(self, other): else: raise ValueError(f"Cannot multiply Pose with {type(other)}") - def _to_homogenous_transformation_matrix(self): """Converts the pose (position and rotation vector) to a 4x4 homogeneous transformation matrix.""" rotation_vec = [self.orientation.x, self.orientation.y, self.orientation.z] @@ -122,8 +120,6 @@ def _to_homogenous_transformation_matrix(self): mat[:3, 3] = [self.position.x, self.position.y, self.position.z] return mat - - def _matrix_to_pose(self, matrix: np.ndarray) -> "Pose": """Converts a homogeneous transformation matrix to a Pose.""" rotation_matrix = matrix[:3, :3] @@ -133,8 +129,7 @@ def _matrix_to_pose(self, matrix: np.ndarray) -> "Pose": (position[0], position[1], position[2], rotation_vec[0], rotation_vec[1], rotation_vec[2]) ) - @property def matrix(self) -> np.ndarray: """Returns the homogeneous transformation matrix.""" - return self._to_homogenous_transformation_matrix() \ No newline at end of file + return self._to_homogenous_transformation_matrix()