-
Notifications
You must be signed in to change notification settings - Fork 25
EpicsMotorIOC #62
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
Open
malitsky
wants to merge
13
commits into
NSLS-II:master
Choose a base branch
from
malitsky:add_motor_ioc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
EpicsMotorIOC #62
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
034c302
initial version of iocs/eps_motor_ioc_sim.py
54fd5be
added timeout tests and Tom's suggestion
a02614e
added time delay
6a9feb2
updated user_setpoint()
7cb6875
moved temperature_controllers_test.py into iocs/tests
155ebfd
added caproto.tests.example_runner
68890d0
removed caproto.tests.example_runner
6abcac0
disable temperature_controllers_test by renaming
a4f8898
removed commented code
a802103
moved tests into nslsii/tests and enable temperature_controllers_test
27bdb2e
removed synchronous sleeps, splitted tests
1670509
added pytest.raises
b35b936
added putter_lock
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| #!/usr/bin/env python3 | ||
| from caproto.server import pvproperty, PVGroup | ||
| from caproto.server import ioc_arg_parser, run | ||
| from caproto import ChannelType | ||
| import time | ||
|
|
||
|
|
||
| class EpicsMotorIOC(PVGroup): | ||
| """ | ||
| Simulates ophyd.EpicsMotor. | ||
| """ | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) | ||
|
|
||
| _dir_states = ['neg', 'pos'] | ||
| _false_true_states = ['False', 'True'] | ||
|
|
||
| _step_size = 0.1 | ||
|
|
||
| # position | ||
|
|
||
| _upper_alarm_limit = 10.0 | ||
| _lower_alarm_limit = -10.0 | ||
|
|
||
| _upper_warning_limit = 9.0 | ||
| _lower_warning_limit = -9.0 | ||
|
|
||
| _upper_ctrl_limit = 11.0 | ||
| _lower_ctrl_limit = -11.0 | ||
|
|
||
| _egu = 'mm' | ||
|
|
||
| _precision = 3 | ||
|
|
||
| user_readback = pvproperty(value=0.0, read_only=True, | ||
| dtype=ChannelType.DOUBLE, | ||
| upper_alarm_limit=_upper_alarm_limit, | ||
| lower_alarm_limit=_lower_alarm_limit, | ||
| upper_warning_limit=_upper_warning_limit, | ||
| lower_warning_limit=_lower_warning_limit, | ||
| upper_ctrl_limit=_upper_ctrl_limit, | ||
| lower_ctrl_limit=_lower_ctrl_limit, | ||
| units=_egu, | ||
| precision=_precision, | ||
| name='.RBV') | ||
| user_setpoint = pvproperty(value=0.0, | ||
| dtype=ChannelType.DOUBLE, | ||
| upper_alarm_limit=_upper_alarm_limit, | ||
| lower_alarm_limit=_lower_alarm_limit, | ||
| upper_warning_limit=_upper_warning_limit, | ||
| lower_warning_limit=_lower_warning_limit, | ||
| upper_ctrl_limit=_upper_ctrl_limit, | ||
| lower_ctrl_limit=_lower_ctrl_limit, | ||
| units=_egu, | ||
| precision=_precision, | ||
| name='.VAL') | ||
|
|
||
| # calibration dial <--> user | ||
|
|
||
| user_offset = pvproperty(value=0.0, read_only=True, | ||
| dtype=ChannelType.DOUBLE, | ||
| name='.OFF') | ||
|
|
||
| user_offset_dir = pvproperty(value=_dir_states[1], | ||
| enum_strings=_dir_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.DIR') | ||
|
|
||
| offset_freeze_switch = pvproperty(value=_false_true_states[0], | ||
| enum_strings=_false_true_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.FOFF') | ||
| set_use_switch = pvproperty(value=_false_true_states[0], | ||
| enum_strings=_false_true_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.SET') | ||
|
|
||
| # configuration | ||
|
|
||
| _velocity = 1. | ||
| _acceleration = 3. | ||
|
|
||
| velocity = pvproperty(value=_velocity, read_only=True, | ||
| dtype=ChannelType.DOUBLE, | ||
| name='.VELO') | ||
| acceleration = pvproperty(value=_acceleration, read_only=True, | ||
| dtype=ChannelType.DOUBLE, | ||
| name='.ACCL') | ||
| motor_egu = pvproperty(value=_egu, read_only=True, | ||
| dtype=ChannelType.STRING, | ||
| name='.EGU') | ||
|
|
||
| # motor status | ||
|
|
||
| motor_is_moving = pvproperty(value='False', read_only=True, | ||
| enum_strings=_false_true_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.MOVN') | ||
| motor_done_move = pvproperty(value='False', read_only=False, | ||
| enum_strings=_false_true_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.DMOV') | ||
|
|
||
| high_limit_switch = pvproperty(value=0, read_only=True, | ||
| dtype=ChannelType.INT, | ||
| name='.HLS') | ||
| low_limit_switch = pvproperty(value=0, read_only=True, | ||
| dtype=ChannelType.INT, | ||
| name='.LLS') | ||
|
|
||
| direction_of_travel = pvproperty(value=_dir_states[1], | ||
| enum_strings=_dir_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.TDIR') | ||
|
|
||
| # commands | ||
|
|
||
| _cmd_states = ['False', 'True'] | ||
|
|
||
| motor_stop = pvproperty(value=_cmd_states[0], | ||
| enum_strings=_cmd_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.STOP') | ||
| home_forward = pvproperty(value=_cmd_states[0], | ||
| enum_strings=_cmd_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.HOMF') | ||
| home_reverse = pvproperty(value=_cmd_states[0], | ||
| enum_strings=_cmd_states, | ||
| dtype=ChannelType.ENUM, | ||
| name='.HOMR') | ||
|
|
||
| # Methods | ||
|
|
||
| @user_setpoint.putter | ||
| async def user_setpoint(self, instance, value): | ||
| p0 = instance.value | ||
| dwell = self._step_size/self._velocity | ||
malitsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| N = max(1, int((value - p0) / self._step_size)) | ||
|
|
||
| await self.motor_done_move.write(value='False') | ||
|
|
||
| for j in range(N): | ||
| new_value = p0 + self._step_size*(j+1) | ||
| time.sleep(dwell) | ||
malitsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await self.user_readback.write(value=new_value) | ||
|
|
||
| await self.motor_done_move.write(value='True') | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| ioc_options, run_options = ioc_arg_parser( | ||
| default_prefix='mtr:', | ||
| desc='EpicsMotor IOC.') | ||
|
|
||
| ioc = EpicsMotorIOC(**ioc_options) | ||
| run(ioc.pvdb, **run_options) | ||
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,102 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import time | ||
|
|
||
| from ophyd.epics_motor import EpicsMotor | ||
| from ophyd.status import MoveStatus | ||
|
|
||
|
|
||
| def test_epicsmotor_ioc(): | ||
|
|
||
| stdout = subprocess.PIPE | ||
| stdin = None | ||
|
|
||
| ''' | ||
| ioc_process = subprocess.Popen([sys.executable, '-m', | ||
| 'caproto.tests.example_runner', | ||
| 'nslsii.iocs.epics_motor_ioc_sim'], | ||
| stdout=stdout, stdin=stdin, | ||
| env=os.environ) | ||
| ''' | ||
malitsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ioc_process = subprocess.Popen([sys.executable, '-m', | ||
| 'nslsii.iocs.epics_motor_ioc_sim'], | ||
| stdout=stdout, stdin=stdin, | ||
| env=os.environ) | ||
|
|
||
| print(f'nslsii.iocs.epc_two_state_ioc_sim is now running') | ||
|
|
||
| time.sleep(5) | ||
|
|
||
| # Wrap the rest in a try-except to ensure the ioc is killed before exiting | ||
| try: | ||
|
|
||
| mtr = EpicsMotor(prefix='mtr:', name='mtr') | ||
|
|
||
| time.sleep(5) | ||
|
|
||
| # 1. check the ioc-device connection and initial values | ||
|
|
||
| assert mtr.egu == 'mm' | ||
|
|
||
| velocity_val = mtr.velocity.get() | ||
| assert velocity_val == 1 | ||
|
|
||
| assert mtr.low_limit == -11.0 | ||
| assert mtr.high_limit == 11.0 | ||
|
|
||
| # 2. set_current_position | ||
|
|
||
| target_val = 5 | ||
|
|
||
| readback_val = mtr.user_readback.get() | ||
| mvtime = (target_val - readback_val)/velocity_val | ||
|
|
||
| mtr.set_current_position(target_val) | ||
|
|
||
| time.sleep(mvtime) | ||
|
|
||
| setpoint_val = mtr.user_setpoint.get() | ||
| readback_val = mtr.user_readback.get() | ||
| assert round(setpoint_val, 3) == target_val | ||
| assert round(readback_val, 3) == target_val | ||
|
|
||
| # 3. move (timeout > moving time) | ||
|
|
||
| target_val = 7 | ||
| mvtime = (target_val - readback_val)/velocity_val | ||
|
|
||
| move_status = MoveStatus(mtr, target_val) | ||
|
|
||
| try: | ||
| move_status = mtr.move(target_val, timeout=mvtime+1) | ||
| except RuntimeError: | ||
| pass | ||
|
|
||
| assert move_status.success is True | ||
|
|
||
| time.sleep(mvtime) | ||
|
|
||
| setpoint_val = mtr.user_setpoint.get() | ||
| readback_val = mtr.user_readback.get() | ||
| assert round(setpoint_val, 3) == target_val | ||
| assert round(readback_val, 3) == target_val | ||
|
|
||
| # 4. move (timeout < moving time) | ||
|
|
||
| target_val = 9 | ||
| mvtime = (target_val - readback_val)/velocity_val | ||
|
|
||
| move_status = MoveStatus(mtr, target_val) | ||
|
|
||
| try: | ||
| move_status = mtr.move(target_val, timeout=mvtime-1) | ||
| except RuntimeError: | ||
| pass | ||
|
|
||
| assert move_status.success is False | ||
|
|
||
| finally: | ||
| # Ensure that for any exception the ioc sub-process is terminated | ||
| # before raising. | ||
| ioc_process.terminate() | ||
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
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.