Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RPS-1086): add option to close the nova object #27

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions examples/01_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@


async def main():
nova = Nova()
cell = nova.cell()
controllers = await cell.controllers()
controller = controllers[0]
async with Nova() as nova:
cell = nova.cell()
controllers = await cell.controllers()
controller = controllers[0]

async with controller:
activated_motion_group_ids = controller.activated_motion_group_ids()
print(activated_motion_group_ids)
async with controller:
activated_motion_group_ids = await controller.activated_motion_group_ids()
print(activated_motion_group_ids)

motion_group = controller[0]
motion_group = controller[0]

tcp_names = await motion_group.tcp_names()
print(tcp_names)
tcp_names = await motion_group.tcp_names()
print(tcp_names)

tcp = tcp_names[0]
tcp = tcp_names[0]

# Current motion group state
state = await motion_group.get_state(tcp)
print(state)
# Current motion group state
state = await motion_group.get_state(tcp)
print(state)

# Current joints positions
joints = await motion_group.joints()
print(joints)
# Current joints positions
joints = await motion_group.joints()
print(joints)

# Current TCP pose
tcp_pose = await motion_group.tcp_pose(tcp)
print(tcp_pose)
# Current TCP pose
tcp_pose = await motion_group.tcp_pose(tcp)
print(tcp_pose)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/02_plan_and_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async def main():
joint_trajectory = await motion_group.plan(actions, tcp)
await motion_group.execute(joint_trajectory, tcp, actions=actions)

await nova.close()


if __name__ == "__main__":
asyncio.run(main())
2 changes: 2 additions & 0 deletions examples/03_move_and_set_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ async def main():
# io_value = await controller.read_io("digital_out[0]")
await motion_group.plan_and_execute(actions, tcp)

await nova.close()


if __name__ == "__main__":
asyncio.run(main())
2 changes: 1 addition & 1 deletion examples/04_move_multiple_robots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async def main():
cell = nova.cell()
ur = await cell.controller("ur")
kuka = await cell.controller("kuka")

await asyncio.gather(move_robot(ur), move_robot(kuka))
await nova.close()


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/05_selection_motion_group_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ async def main():
async with mg_0, mg_1:
await asyncio.gather(move_robot(mg_0, tcp), move_robot(mg_1, tcp))

await nova.close()


if __name__ == "__main__":
asyncio.run(main())
9 changes: 9 additions & 0 deletions nova/core/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def __init__(
def cell(self, cell_id: str = config("CELL_NAME", default="cell")) -> "Cell":
return Cell(self._api_client, cell_id)

async def close(self):
return await self._api_client.close()

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.close()


class Cell:
def __init__(self, api_gateway: ApiGateway, cell_id: str):
Expand Down
2 changes: 1 addition & 1 deletion nova/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ def __init__(
)

async def close(self):
await self._api_client.close()
return await self._api_client.close()
90 changes: 45 additions & 45 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading