Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
cbiering committed Dec 3, 2024
1 parent 20af140 commit e64c794
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 40 deletions.
1 change: 0 additions & 1 deletion examples/01_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ async def main():
print(tcp_pose)



if __name__ == "__main__":
asyncio.run(main())
17 changes: 4 additions & 13 deletions wandelbots/core/motion_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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}")
Expand All @@ -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
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions wandelbots/core/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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)
return Controller(api_client=self._api_client, cell=self._cell_id, controller_host=found_controller.host)
11 changes: 0 additions & 11 deletions wandelbots/core/planner.py

This file was deleted.

5 changes: 1 addition & 4 deletions wandelbots/types/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 2 additions & 7 deletions wandelbots/types/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from scipy.spatial.transform import Rotation as R


class Position(Vector3d):
"""A position
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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()
return self._to_homogenous_transformation_matrix()

0 comments on commit e64c794

Please sign in to comment.