Skip to content

Commit

Permalink
Put the lid on when plate is on B15
Browse files Browse the repository at this point in the history
  • Loading branch information
danr committed Feb 20, 2024
1 parent ff4353d commit c866a8a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 33 deletions.
35 changes: 25 additions & 10 deletions cellpainter/cellpainter/moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def tags(self) -> list[str]:
out += [tag]
return out

def expand_hotels(self, name: str) -> dict[str, MoveList]:
def expand_hotels(self, name: str, *, expand_base: bool) -> dict[str, MoveList]:
'''
If there is a tag like 19/21 then expand to all heights 1/21, 3/21, .., 21/21
The first occurence of 19 in the name is replaced with 1, 3, .., 21, so
Expand All @@ -233,14 +233,22 @@ def expand_hotels(self, name: str) -> dict[str, MoveList]:
else:
raise ValueError(f'Unknown hotel in: {name}')
for tag in set(self.tags()):
if m := re.match(r'(\d+)/(11|21)$', tag):
ref_h = int(m.group(1))
assert str(ref_h) in name
assert ref_h in hotel_locs
for h in hotel_locs:
dz = (h - ref_h) * hotel_dist
name_h = name.replace(str(ref_h), str(h), 1)
out[name_h] = self.adjust_tagged(tag, dname=str(h), dz=dz)
if expand_base:
if tag == 'base 21':
ref_h = 21
for h in [15]:
dz = (h - ref_h) * hotel_dist
name_h = f'{name} [base B{h}]'
out[name_h] = self.adjust_tagged(tag, dname=f'[base B{h}]', dz=dz)
if not expand_base:
if m := re.match(r'(\d+)/(11|21)$', tag):
ref_h = int(m.group(1))
assert str(ref_h) in name
assert ref_h in hotel_locs
for h in hotel_locs:
dz = (h - ref_h) * hotel_dist
name_h = name.replace(str(ref_h), str(h), 1)
out[name_h] = self.adjust_tagged(tag, dname=str(h), dz=dz)
return out

def with_sections(self, include_Section: bool=False) -> list[tuple[str, Move]]:
Expand Down Expand Up @@ -467,7 +475,9 @@ def read_and_expand(filename: Path) -> dict[str, MoveList]:
ml = MoveList.read_jsonl(filename)
expanded = ml.expand_sections()
for k, v in list(expanded.items()):
expanded |= v.expand_hotels(k)
expanded |= v.expand_hotels(k, expand_base=False)
for k, v in list(expanded.items()):
expanded |= v.expand_hotels(k, expand_base=True)
return expanded

def read_movelists() -> dict[str, MoveList]:
Expand Down Expand Up @@ -589,6 +599,7 @@ def effect(self, world: World) -> dict[str, str | None]:
movelists = read_movelists()

B21 = 'B21'
B15 = 'B15'
effects: dict[str, Effect] = {}

for k, v in movelists.items():
Expand All @@ -613,6 +624,10 @@ def effect(self, world: World) -> dict[str, str | None]:
effects[lid_Bi + ' get'] = PutLidOn(source=Bi, target=B21)
effects[lid_Bi + ' put'] = TakeLidOff(source=B21, target=Bi)

lid_Bi = f'lid-B{i} [base B15]'
effects[lid_Bi + ' get'] = PutLidOn(source=Bi, target=B15)
effects[lid_Bi + ' put'] = TakeLidOff(source=B15, target=Bi)

for k in list(effects.keys()):
effects[k + ' transfer'] = effects[k]

Expand Down
55 changes: 42 additions & 13 deletions cellpainter/cellpainter/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OptPrio:
wash_to_disp = Min(priority=6, weight=1)
incu_slack = Min(priority=6, weight=1)
without_lid = Min(priority=4, weight=1)
batch_time = Min(priority=3, weight=1)
total_time = Min(priority=3, weight=1)
squeeze_steps = Min(priority=2, weight=1)
inside_incu = Max(priority=1, weight=0)

Expand All @@ -62,6 +62,10 @@ def lid_put(self):
def lid_get(self):
return f'lid-{self.lid_loc} get'

@property
def lid_get_base_B15(self):
return f'lid-{self.lid_loc} get [base B15]'

@property
def rt_put(self):
return f'{self.rt_loc} put'
Expand Down Expand Up @@ -333,6 +337,21 @@ class ProtocolConfig:
blue_prime: list[str]
use_blue: bool

'''
def any_disp(self):
return any([
*[step.disp for step in self.steps],
*[step.disp_prime for step in self.steps],
*[step.disp_prep for step in self.steps],
])
def any_wash(self):
return self.wash_prime or any([step.wash for step in self.steps])
def any_blue(self):
return self.use_blue or self.blue_prime or any([step.blue for step in self.steps])
'''

from .protocol_paths import ProtocolPaths, paths_v5

@dataclass(frozen=True)
Expand Down Expand Up @@ -462,15 +481,15 @@ def program_test_comm(with_incu: bool=True, with_blue: bool=True) -> Command:
Test communication with robotarm, washer, dispenser and incubator.
'''
return Seq(
# BlueCmd(action='TestCommunications', protocol_path=None).fork() if with_blue else Idle(),
BlueCmd(action='TestCommunications', protocol_path=None).fork() if with_blue else Idle(),
DispCmd(cmd='TestCommunications', protocol_path=None).fork(),
IncuCmd(action='get_status', incu_loc=None).fork() if with_incu else Idle(),
RobotarmCmd('ur gripper init and check'),
WaitForResource('disp'),
WashCmd(cmd='TestCommunications', protocol_path=None).fork(),
WaitForResource('incu') if with_incu else Idle(),
WaitForResource('wash'),
# WaitForResource('blue') if with_blue else Idle(),
WaitForResource('blue') if with_blue else Idle(),
).add(Metadata(step_desc='test comm'))

Desc = tuple[str, str, str]
Expand Down Expand Up @@ -509,8 +528,12 @@ def paint_batch(batch: list[Plate], protocol_config: ProtocolConfig) -> Command:
Checkpoint(f'batch {batch_index}'),
]

prep_cmds += [
program_test_comm(with_blue=p.use_blue),
BlueCmd('get_working_plate').fork() if p.use_blue else Idle(),
]

post_cmds = [
Duration(f'batch {batch_index}', OptPrio.batch_time),
]

chunks: dict[Desc, Iterable[Command]] = {}
Expand Down Expand Up @@ -580,6 +603,13 @@ def paint_batch(batch: list[Plate], protocol_config: ProtocolConfig) -> Command:
),
]

lid_on_base_B15 = [
*RobotarmCmds(
plate_with_corrected_lid_pos.lid_get_base_B15,
after_drop=[Duration(f'{plate_desc} lid off {ix}', OptPrio.without_lid)]
),
]

if step.name == 'Mito' or step.name == 'PFA':
incu_get = [
# Idle() + 'sep {plate_desc} {step.name}',
Expand Down Expand Up @@ -676,7 +706,8 @@ def paint_batch(batch: list[Plate], protocol_config: ProtocolConfig) -> Command:
cmd.add(Metadata(plate_id=None))
for cmd in blue_prime
if plate is first_plate
if not prev_step or not prev_step.blue
# if not prev_step or not prev_step.blue
if step.blue # let's just always prime blue for simplicity
],
BlueCmd('Validate', step.blue),
),
Expand Down Expand Up @@ -809,11 +840,11 @@ def blue_to_B(z: int):
chunks[plate.id, step.name, 'blue -> B21' ] = [*blue_to_B(21), *lid_on]
chunks[plate.id, step.name, 'blue -> B15' ] = [*blue_to_B(15)]

if 0 and step.name == 'Mito' and not step.blue and not step.wash:
# exception!
chunks[plate.id, step.name, 'disp -> B15' ] = [*disp_to_B(21), *lid_on, *RobotarmCmds('B15 put')]
if step.disp and not step.blue and not step.wash:
# put on the lid now
chunks[plate.id, step.name, 'disp -> B15' ] = [*disp_to_B(15), *lid_on_base_B15]
chunks[plate.id, step.name, 'B15 -> B21' ] = []
chunks[plate.id, step.name, 'B21 -> incu'] = [*B15_to_incu]
chunks[plate.id, step.name, 'B21 -> incu'] = [*RobotarmCmds('B15 get'), *B21_to_incu]
else:
chunks[plate.id, step.name, 'disp -> B15' ] = [*disp_to_B(15)]
chunks[plate.id, step.name, 'B15 -> B21' ] = [*RobotarmCmds('B15 get'), *lid_on]
Expand Down Expand Up @@ -948,11 +979,9 @@ def cell_paint_program(batch_sizes: list[int], protocol_config: ProtocolConfig)
program = Seq(*cmds)
program = Seq(
Checkpoint('run'),
program_test_comm(with_blue=protocol_config.use_blue),
BlueCmd('get_working_plate').fork() if protocol_config.use_blue else Idle(),
WaitForCheckpoint('run') + 'initialization slack',
# we now do test comm at start of each batch
program,
Duration('run', OptPrio.batch_time)
Duration('run', OptPrio.total_time)
)
return Program(
command=program,
Expand Down
2 changes: 1 addition & 1 deletion cellpainter/cellpainter/protocol_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def index() -> Iterator[Tag | dict[str, str]]:
span(f'{delay_secs.value} s'),
),
label(span('zoom: '), zoom_int.range(), span(str(zoom_int.value))),
label(span('pfa duration: '), pfa_duration.range().extend(width=200), span(f'{pfa_duration.value} s')),
# label(span('pfa duration: '), pfa_duration.range().extend(width=200), span(f'{pfa_duration.value} s')),
label(span('vertical: '), vertical.input().extend(style='justify-self: left')),
background='#fff',
border_bottom='1px #0008 solid',
Expand Down
2 changes: 1 addition & 1 deletion cellpainter/cellpainter/small_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_comm(_: SmallProtocolArgs):
'''
Test communication with robotarm, washer, dispenser and incubator.
'''
return Program(protocol.program_test_comm().add(Metadata(gui_force_show=True)))
return Program(protocol.program_test_comm(with_blue=False).add(Metadata(gui_force_show=True)))

@ur_protocols.append
def test_circuit(args: SmallProtocolArgs):
Expand Down
18 changes: 10 additions & 8 deletions cellpainter/movelists/lid-B19.jsonl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{"type":"Section","section":"lid-B19 put"}
{"type":"MoveJoint","joints":[94.88,-110.59,90.31,19.45,95.29,179.84],"name":"B neu"}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-566.9,821.9],"rpy":[0.0,0.7,89.6],"name":"B21 pick","slow":true}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 entrance"}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-566.9,821.9],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 pick","slow":true}
{"type":"GripperMove","pos":255}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.7,89.6],"name":"B21 entrance"}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 entrance"}
{"type":"MoveLin","xyz":[199.7,-421.8,751.1],"rpy":[0.0,0.7,89.6],"tag":"19/21","name":"B19 entrance"}
{"type":"MoveLin","xyz":[199.7,-567.4,751.1],"rpy":[0.0,0.7,89.6],"tag":"19/21","name":"B19 neu"}
{"type":"MoveLin","xyz":[199.7,-567.4,742.6],"rpy":[0.0,0.7,89.6],"tag":"19/21","name":"B19 drop","slow":true}
Expand All @@ -20,9 +21,10 @@
{"type":"GripperMove","pos":255}
{"type":"MoveLin","xyz":[199.7,-567.4,751.1],"rpy":[0.0,0.7,89.6],"tag":"19/21","name":"B19 pick neu"}
{"type":"MoveLin","xyz":[199.7,-421.8,751.1],"rpy":[0.0,0.7,89.6],"tag":"19/21","name":"B19 entrance"}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.7,89.6],"name":"B21 entrance"}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-566.9,822.2],"rpy":[0.0,0.7,89.6],"name":"B21 drop","slow":true}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 entrance"}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-566.9,822.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 drop","slow":true}
{"type":"GripperMove","pos":88}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-566.9,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 neu"}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.7,89.6],"tag":"base 21","name":"B21 entrance"}
{"type":"MoveLin","xyz":[199.7,-421.7,834.2],"rpy":[0.0,0.8,89.6],"name":"B neu"}

0 comments on commit c866a8a

Please sign in to comment.