<jupyter_start><jupyter_text>Simulate an EPICS motorUsing two float PVs and a userCalc from the docker container, simulate an EPICS motor with tools from ophyd and apstools.userCalc field | value | meaning---  | ---          | ---A PV | gp:gp:float1 | motor VALB PV | gp:gp:float2 | motor RBVC    | 0.1          | maximum step sizeCALC | `MIN(ABS(A-B),C)*(A>B?1:-1)+B` | simulated position (readback)SCAN | 1 second     | update rate (motor speed)OUTN | gp:gp:float2 | output PV name<jupyter_code>from apstools.devices import PVPositionerSoftDone
from apstools.devices import SwaitRecord

import bluesky
from bluesky import plans as bp
from bluesky import plan_stubs as bps

from ophyd import Component
from ophyd import EpicsSignal
from ophyd import PVPositionerPC

import time
class SoftMotor(PVPositionerPC):
    readback = Component(EpicsSignal, "gp:float2")
    setpoint = Component(EpicsSignal, "gp:float1")
motor = SoftMotor("gp:", name="motor")
motor.wait_for_connection()
sim_calc = SwaitRecord("gp:userCalc5", name="sim_calc")
sim_calc.wait_for_connection()
sim_calc.reset()
sim_calc
sim_calc.channels.A.input_pv.put(motor.setpoint.pvname)
sim_calc.channels.B.input_pv.put(motor.readback.pvname)
sim_calc.channels.C.input_value.put(0.1)
sim_calc.scanning_rate.put(".1 second")
sim_calc.calculation.put("MIN(ABS(A-B),C)*(A>B?1:-1)+B")
sim_calc.output_link_pv.put(motor.readback.pvname)
sim_calc.description.put(f"{motor.name} (simulated)")
sim_calcs_enable = EpicsSignal("gp:userCalcEnable", name="sim_calcs_enable")
sim_calcs_enable.wait_for_connection()
sim_calcs_enable.put("Enable")
motor.setpoint.put(1.5+motor.position)
RE = bluesky.RunEngine({})
t0 = time.time()
RE(bps.mvr(motor, 2))
print(f"{time.time()-t0:.3f}s elapsed")
motor = PVPositionerSoftDone("gp:", readback_pv="gp:float2", setpoint_pv="gp:float1", tolerance=0.001, name="motor")
motor.wait_for_connection()
motor.move(1.234)
t0 = time.time()
RE(bps.mv(motor, -motor.position))
print(f"{time.time()-t0:.3f}s elapsed")<jupyter_output>2.454s elapsed
{'fraction_non_alphanumeric': 0.14074074074074075, 'fraction_numerical': 0.01925925925925926, 'mean_word_length': 6.209964412811388, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '473419', 'license': 'MIT', 'n_tokens_mistral': 801, 'n_tokens_neox': 745, 'n_words': 145, 'path': 'notebooks/simulate_motor.ipynb', 'repo_name': 'kellyjelly0904/macros_29id', 'size': '2025'}