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

23 make hardware run in mock mode to test plans #28

Merged
merged 13 commits into from
Jun 18, 2024
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Contribute to the project

Contributions and issues are most welcome! All issues and pull requests are
handled through [GitHub](https://github.com/Relm-Arrowny/p99_bluesky/issues). Also, please check for any existing issues before
handled through [GitHub](https://github.com/DiamondLightSource/p99-bluesky/issues). Also, please check for any existing issues before
filing a new one. If you have a great idea but it involves big changes, please
file a ticket before making a pull request! We want to make sure you don't spend
your time coding something that might not fit the scope of the project.

## Issue or Discussion?

Github also offers [discussions](https://github.com/Relm-Arrowny/p99_bluesky/discussions) as a place to ask questions and share ideas. If
Github also offers [discussions](https://github.com/DiamondLightSource/p99-bluesky/discussions) as a place to ask questions and share ideas. If
your issue is open ended and it is not obvious when it can be "closed", please
raise it as a discussion instead.

Expand Down
4 changes: 2 additions & 2 deletions src/p99_bluesky/beamlines/p99.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dodal.beamlines.beamline_utils import device_instantiation
from dodal.beamlines.beamline_utils import set_beamline as set_utils_beamline
from dodal.common.beamlines.beamline_utils import device_instantiation
from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline
from dodal.log import set_beamline as set_log_beamline
from dodal.utils import get_beamline_name

Expand Down
56 changes: 56 additions & 0 deletions tests/epics/soft_ioc/p99_softioc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import asyncio

from softioc import asyncio_dispatcher, builder, softioc
from softsignal import soft_mbb, soft_motor, soft_signal


async def p99_fake() -> None:
async def _delay_move(signal, v, vel, dmov):
diff = signal.get() - v.get()
if abs(diff) < vel.get() * 0.04:
signal.set(v.get())
dmov.set(True)

elif diff < 0:
dmov.set(False)
signal.set(signal.get() + vel.get() * 0.02)
elif diff > 0:
dmov.set(False)
signal.set(signal.get() - vel.get() * 0.02)

# Sample AngleStage softioc
dispatcher = asyncio_dispatcher.AsyncioDispatcher()
soft_signal("p99-MO-TABLE-01", "WRITETHETA", "WRITETHETA:RBV")
soft_signal("p99-MO-TABLE-01", "WRITEROLL", "WRITEROLL:RBV")
soft_signal("p99-MO-TABLE-01", "WRITEPITCH", "WRITEPITCH:RBV")
# sample selection staged
soft_mbb("p99-MO-STAGE-02", "MP:SELECT")
# xyz stage
x_set, x_vel, x_rbv, x_dmov = await soft_motor(
prefix="p99-MO-STAGE-02", name="X", unit="mm"
)
y_set, y_vel, y_rbv, y_dmov = await soft_motor(
prefix="p99-MO-STAGE-02", name="Y", unit="mm"
)
z_set, z_vel, z_rbv, z_dmov = await soft_motor(
prefix="p99-MO-STAGE-02", name="Z", unit="mm"
)
# build the ioc
builder.LoadDatabase()
softioc.iocInit(dispatcher)

# print(softioc.dbnr(), softioc.dbl()) # type: ignore

async def update(y_rbv, y_set, y_vel, y_dmov):
await _delay_move(y_rbv, y_set, y_vel, y_dmov)

while True:
dispatcher(update, [z_rbv, z_set, z_vel, z_dmov])
dispatcher(update, [y_rbv, y_set, y_vel, y_dmov])
dispatcher(update, [x_rbv, x_set, x_vel, x_dmov])
await asyncio.sleep(0.01)
# softioc.interactive_ioc(globals())


if __name__ == "__main__":
asyncio.run(p99_fake())
94 changes: 94 additions & 0 deletions tests/epics/soft_ioc/softsignal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from softioc import builder


def soft_signal(prefix: str, input_name: str, readback_name: str) -> None:
# Create some records
builder.SetDeviceName(prefix)
rbv = builder.aIn(readback_name, initial_value=0)
# rbv.append(temp)
builder.aOut(
input_name,
initial_value=0.1,
always_update=True,
on_update=lambda v: rbv.set(v),
)


def soft_mbb(prefix: str, name: str, *option):
builder.SetDeviceName(prefix)
# temp = builder.mbbIn(readback_name, initial_value=0)
builder.mbbOut(
name,
"Empty",
"Mn 5um",
"Fe (empty)",
"Co 5um",
"Ni 5um",
"Cu 5um",
"Zn 5um",
"Zr (empty)",
"Mo (empty)",
"Rh (empty)",
"Pd (empty)",
"Ag (empty)",
"Cd 25um",
"W (empty)",
"Pt (empty)",
"User",
)


async def soft_motor(prefix: str, name: str, unit: str = "mm"):
builder.SetDeviceName(prefix)
builder.aOut(
name,
initial_value=1.1,
EGU=unit,
VAL=1.1,
PREC=0,
)
rbv = builder.aOut(
name + "RBV",
initial_value=0.0,
)
vel = builder.aOut(
name + "VELO",
initial_value=1.5,
)
dmov = builder.boolOut(
name + "DMOV",
initial_value=True,
)
ai = builder.aOut(
name + "VAL",
initial_value=0.0,
always_update=True,
on_update=lambda v: dmov.set(False),
)

builder.aOut(
name + "VMAX",
initial_value=2,
)
builder.aOut(
name + "ACCL",
initial_value=1,
)
builder.aOut(
name + "RDBD",
initial_value=0.1,
)

builder.aOut(
name + "LLM",
initial_value=-100,
)
builder.aOut(
name + "HLM",
initial_value=100,
)
builder.aOut(
name + "STOP",
initial_value=0,
)
return ai, vel, rbv, dmov
Empty file added tests/epics/soft_ioc/test.py
Empty file.
Loading
Loading