Skip to content

Commit

Permalink
Updates from first test on the beamline
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Dec 3, 2024
1 parent f6cd690 commit 4b09daa
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_PVWS_SOCKET="pvws.diamond.ac.uk"
VITE_PVWS_SSL="true"
VITE_BLUEAPI_SOCKET="http://localhost:8000"
VITE_BLUEAPI_SOCKET="http://localhost:25565"
Binary file modified diamondlightsource-cs-web-lib-0.5.0.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion package-lock.json

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

11 changes: 9 additions & 2 deletions src/blueapi/blueapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ export function getWorkerStatus(): Promise<BlueApiWorkerState> {
return blueApiCall("/worker/state").then((res) => res.json());
}

export function submitPlan(planName: string, planParams: object): Promise<string> {
export function submitPlan(
planName: string,
planParams: object
): Promise<string> {
return blueApiCall("/tasks", "POST", {
name: planName,
params: planParams,
}).then((res) => res.json().then((res) => res["task_id"]));
}

export function submitAndRunPlanImmediately(planName: string, planParams: object): Promise<string> {
export function submitAndRunPlanImmediately(
planName: string,
planParams: object
): Promise<string> {
return submitPlan(planName, planParams).then((res) =>
// TODO make sure submitPlan was succesful before then putting it to the worker
blueApiCall("/worker/task", "PUT", { task_id: res }).then((res) =>
res.json().then((res) => res["task_id"])
)
Expand Down
8 changes: 7 additions & 1 deletion src/components/SleepButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ export function SleepButton() {
onChange={(e) => setSeconds(Number(e.target.value))}
style={{ width: 100 }}
/>
<Button onClick={() => submitAndRunPlanImmediately("sleep", { sec: seconds })}>Sleep!</Button>
<Button
onClick={() =>
submitAndRunPlanImmediately("gui_sleep", { sec: seconds })
}
>
Sleep!
</Button>
</Stack>
);
}
21 changes: 19 additions & 2 deletions src/screens/DetectorMotion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Button, Stack, TextField, useTheme } from "@mui/material";
import { PvComponent, PvDescription, PvItem } from "../pv/PvComponent";
import { forceString } from "../pv/util";
import { submitAndRunPlanImmediately } from "../blueapi/blueapi";

function RoPvBox(props: PvDescription) {
return PvComponent({
Expand All @@ -25,8 +26,24 @@ export function DetectorMotionTabPanel() {
<RoPvBox label="Selected detector" pv="ca://ME14E-MO-IOC-01:GP101" />
<RoPvBox label="Detector stage position" pv="ca://BL24I-EA-DET-01:Y" />
<Stack direction={"row"}>
<TextField label="New position" />
<Button>Move stage!</Button>
<Button
onClick={() =>
submitAndRunPlanImmediately("gui_move_detector", { det: "eiger" })
}
>
Move to Eiger!
</Button>
<Button
onClick={() =>
submitAndRunPlanImmediately("gui_move_detector", {
det: "pilatus",
})
}
>
Move to Pilatus!
</Button>
{/* <TextField label="New position" />
<Button>Move stage!</Button> */}
</Stack>
</Stack>
</div>
Expand Down
40 changes: 31 additions & 9 deletions src/screens/OavMover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { CoordNumberInput } from "../components/CoordNumberInput";
export function MoveArrows() {
const theme = useTheme();
return (
<Box bgcolor={theme.palette.background.paper} borderRadius={5} paddingTop={1} paddingBottom={1}>
<Box
bgcolor={theme.palette.background.paper}
borderRadius={5}
paddingTop={1}
paddingBottom={1}
>
<Grid2 container spacing={0} columns={3}>
<Grid2 size={3}>
<b>Nudge sample:</b>
Expand Down Expand Up @@ -59,7 +64,12 @@ export function BeamCentre({
}) {
const theme = useTheme();
return (
<Box bgcolor={theme.palette.background.paper} borderRadius={5} paddingTop={1} paddingBottom={1}>
<Box
bgcolor={theme.palette.background.paper}
borderRadius={5}
paddingTop={1}
paddingBottom={1}
>
<Grid2 container spacing={0} columns={3}>
<Grid2 size={3} padding={1}>
<b>Beam center:</b>
Expand Down Expand Up @@ -96,14 +106,21 @@ export function PixelsToMicrons({
}) {
const theme = useTheme();
return (
<Box bgcolor={theme.palette.background.paper} borderRadius={5} paddingTop={1} paddingBottom={1}>
<Box
bgcolor={theme.palette.background.paper}
borderRadius={5}
paddingTop={1}
paddingBottom={1}
>
<Grid2 container spacing={0} columns={3}>
<Grid2 size={3}>
<Stack direction="row" spacing={2} padding={2}>
<TextField
label="Pixels per micron"
onChange={(e) =>
setPixelsPerMicron(Number(e.target.value) ? Number(e.target.value) : 0)
setPixelsPerMicron(
Number(e.target.value) ? Number(e.target.value) : 0
)
}
defaultValue={1.25}
aria-label="Pixels per micron"
Expand Down Expand Up @@ -136,12 +153,14 @@ export function OavMover() {
console.log(
`Clicked on position (${x}, ${y}) (px relative to beam centre) in original stream. Relative position in um (${x_um}, ${y_um}). Submitting to BlueAPI...`
);
const [x_int, y_int] = [Math.round(x), Math.round(y)];
if (Number.isNaN(x_um) || Number.isNaN(y_um)) {
console.log("Not submitting plan while disconnected from PVs!");
console.log(
"Not submitting plan while disconnected from PVs!"
);
} else {
submitAndRunPlanImmediately("virtual_relative_move_um", {
x_um: x_um,
y_um: y_um,
submitAndRunPlanImmediately("gui_gonio_move_on_click", {
position_px: [x_int, y_int],
});
}
}}
Expand All @@ -151,7 +170,10 @@ export function OavMover() {
<Grid2 size={3} height={3}>
<MoveArrows />
<Grid2 size={3} padding={1} />
<BeamCentre setCrosshairX={setCrosshairX} setCrosshairY={setCrosshairY} />
<BeamCentre
setCrosshairX={setCrosshairX}
setCrosshairY={setCrosshairY}
/>
<PixelsToMicrons setPixelsPerMicron={setPixelsPerMicron} />
</Grid2>
</Grid2>
Expand Down

0 comments on commit 4b09daa

Please sign in to comment.