-
Notifications
You must be signed in to change notification settings - Fork 96
[rotations] add ResourceHolderMixin to fix placement in a number of resources #239
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
Merged
rickwierenga
merged 38 commits into
PyLabRobot:main
from
retrobiosciences:jkh/add-rot-test
Sep 18, 2024
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
8380f87
Fix server tests (#209)
rickwierenga 6d81719
Merge branch 'PyLabRobot:main' into main
jkhales 2816879
Merge branch 'PyLabRobot:main' into main
fderop b990f17
Merge branch 'PyLabRobot:main' into main
fderop 71cc945
Merge branch 'PyLabRobot:main' into main
jkhales 41d51df
[rotations] add test for idempotent rotations
jkhales fcc5410
Merge branch 'main' into jkh/add-rot-test
jkhales f459e66
fix lint
jkhales eb90108
fix ResourceStack
jkhales cf88076
Merge branch 'main' into jkh/add-rot-test
jkhales 726ea18
add resource_holder
jkhales c5d03f2
convert to a mixin
jkhales db96840
mixin everywhere
jkhales 3017141
clean
jkhales bacfd5d
move to file
jkhales 08b19ca
add to plate
jkhales 49f8203
fix lint
jkhales 9044ce1
fix typing
jkhales e677a02
Merge branch 'main' into jkh/add-rot-test
jkhales 1c2b51a
update comment
jkhales eeef292
allow location to be overridden
jkhales 87ba3b4
clean up machine
jkhales 3878799
Merge branch 'main' into jkh/add-rot-test
jkhales 1e39fa6
cr
jkhales 522a56f
add todo
jkhales a9f8993
add deprecation warning
jkhales f9a083b
revert
jkhales f95e723
typo
jkhales 9aea429
fix lint
jkhales 828891e
remove _kwargs
rickwierenga 5fdb842
use instances instead of class builder
rickwierenga c4167f8
use get_default_child_location here
rickwierenga 4cc9561
fix type
rickwierenga aaa4429
freeze the ops classes and remove doc strings
rickwierenga 7d00883
Merge branch 'main' into jkh/add-rot-test
rickwierenga ee84c68
freeze the ops classes and remove doc strings
rickwierenga 0af7d77
Merge branch 'main' into jkh/add-rot-test
rickwierenga e7da4ac
Merge branch 'main' into jkh/add-rot-test
rickwierenga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from typing import Optional | ||
from pylabrobot.resources.coordinate import Coordinate | ||
from pylabrobot.resources.resource import Resource | ||
|
||
def get_child_location(resource: Resource) -> Coordinate: | ||
""" | ||
If a resource is rotated, its rotated around its local origin. This does not always | ||
match up with the parent resource's origin. This function calculates the difference | ||
between the two origins and calculates the location of the resource correctly. | ||
""" | ||
if not resource.rotation.y == resource.rotation.x == 0: | ||
raise ValueError("Resource rotation must be 0 around the x and y axes") | ||
if not resource.rotation.z % 90 == 0: | ||
raise ValueError("Resource rotation must be a multiple of 90 degrees on the z axis") | ||
location = { | ||
0.0: Coordinate(x=0, y=0, z=0), | ||
90.0: Coordinate(x=resource.get_size_y(), y=0, z=0), | ||
180.0: Coordinate(x=resource.get_size_y(), y=resource.get_size_x(), z=0), | ||
270.0: Coordinate(x=0, y=resource.get_size_x(), z=0), | ||
}[resource.rotation.z % 360] | ||
return location | ||
|
||
class ResourceHolderMixin: | ||
rickwierenga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
A mixin class for resources that can hold other resources, like a plate or a lid. | ||
|
||
This applies a linear transformation after the rotation to correctly place the child resource. | ||
""" | ||
|
||
def get_default_child_location(self, resource: Resource) -> Coordinate: | ||
return get_child_location(resource) | ||
|
||
def assign_child_resource( | ||
self, | ||
resource: Resource, | ||
location: Optional[Coordinate] = None, | ||
reassign: bool = True | ||
): | ||
location = location or self.get_default_child_location(resource) | ||
# mypy doesn't play well with the Mixin pattern | ||
return super().assign_child_resource(resource, location, reassign) # type: ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.