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

Tidy apple2 undulator #1002

Merged
merged 11 commits into from
Feb 6, 2025
Merged

Tidy apple2 undulator #1002

merged 11 commits into from
Feb 6, 2025

Conversation

DominicOram
Copy link
Contributor

@DominicOram DominicOram commented Jan 23, 2025

Fixes #999

This didn't end up removing as much code as I expected but I do think it's more maintainable as it contains less repetition.

Instructions to reviewer on how to test:

  1. Confirm tests still pass and behaviour unchanged

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

@DominicOram DominicOram requested a review from a team as a code owner January 23, 2025 17:18
with self.add_children_as_readables(StandardReadableFormat.HINTED_SIGNAL):
self.user_setpoint_readback = epics_signal_r(float, fullPV + ".RBV")
self.user_setpoint_readback = epics_signal_r(float, motor_PV + ".RBV")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Relm-Arrowny I could instead make everything use user_readback but this changes the name of the signal when it is read() I wasn't sure if the name was important so left it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be safe to change it to user_readback in fact it is better if we inherit from motor but I think super need to goes before the signal definition otherwise when we call the super class constructor it will override the user_setpoint we define.

Now that I am typing away I remember why I did not use motor, The main reason is I do not want them to be stoppable as we are not meant to try to stop the id once they are moving. I was also worry that leaving movable/locatable in there where they would not function as intended, as we have this strange relationship of user_setpoint return done immediately and nothing happen until we say go.
May be we should call this UndulatorPhaseIO/signals instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if the motor bit is the controversial one I'll revert that and make a follow up issue

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.66%. Comparing base (f370749) to head (5812239).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1002      +/-   ##
==========================================
- Coverage   97.67%   97.66%   -0.02%     
==========================================
  Files         159      159              
  Lines        6590     6560      -30     
==========================================
- Hits         6437     6407      -30     
  Misses        153      153              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Relm-Arrowny Relm-Arrowny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, it looks good, there are only one part I am not sure about.

with self.add_children_as_readables(StandardReadableFormat.HINTED_SIGNAL):
self.user_setpoint_readback = epics_signal_r(float, fullPV + ".RBV")
self.user_setpoint_readback = epics_signal_r(float, motor_PV + ".RBV")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be safe to change it to user_readback in fact it is better if we inherit from motor but I think super need to goes before the signal definition otherwise when we call the super class constructor it will override the user_setpoint we define.

Now that I am typing away I remember why I did not use motor, The main reason is I do not want them to be stoppable as we are not meant to try to stop the id once they are moving. I was also worry that leaving movable/locatable in there where they would not function as intended, as we have this strange relationship of user_setpoint return done immediately and nothing happen until we say go.
May be we should call this UndulatorPhaseIO/signals instead?



class UndulatorPhaseMotor(StandardReadable):
class UndulatorPhaseMotor(Motor):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Inherit from motor here mean we will have stopable which is something we are told not to do with our id. Furthermore, movable/locatable will not function correctly, So it probably better if we not make this motor but instead change the name and call it UndulatorPhaseIO(Device)?

Comment on lines 217 to 222
self.user_setpoint = epics_signal_w(str, fullPV + "SET")
self.user_setpoint_demand_readback = epics_signal_r(float, fullPV + "DMD")

fullPV = fullPV + "MTR"
motor_PV = fullPV + "MTR"
with self.add_children_as_readables(StandardReadableFormat.HINTED_SIGNAL):
self.user_setpoint_readback = epics_signal_r(float, fullPV + ".RBV")
self.user_setpoint_readback = epics_signal_r(float, motor_PV + ".RBV")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must: If we were to use motor, I think this

super().__init__(motor_PV, name)

need to goes before:

 self.user_setpoint = epics_signal_w(str, fullPV + "SET")
 self.user_setpoint_demand_readback = epics_signal_r(float, fullPV + "DMD")

Otherwise it get override by Motor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't super().init() what automatically names the children after connecting: would the children still get named in this order?

Copy link
Contributor

@Relm-Arrowny Relm-Arrowny Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't super().init() what automatically names the children after connecting: would the children still get named in this order?

I am not sure now that you question this...... but last time I try inherit motor and change the signal inside Motor something like this would happens, I definite

self.user_setpoint = epics_signal_w(str, fullPV + "SET")

and call super().init() and user_setpoint get replace by:

Motor.user_setpoint = epics_signal_rw(float, prefix + ".VAL")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would make sense that the call to super replaces it. I will work out the exact behaviour and may make a ophyd-async issue about it.

Copy link
Contributor

@Relm-Arrowny Relm-Arrowny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good thanks.

@DominicOram
Copy link
Contributor Author

Sorry @DiamondJoseph, need a Bluesky Reviewer and you already commented on here...

Copy link
Contributor

@DiamondJoseph DiamondJoseph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits around typing, I need to know about how the jaw_phase set signal works before I'll approve, and I'm not completely happy about passing both strings and signals around.

Basically looks there though.

src/dodal/devices/apple2_undulator.py Outdated Show resolved Hide resolved
Comment on lines +93 to +99
async def estimate_motor_timeout(
setpoint: SignalR, curr_pos: SignalR, velocity: SignalR
):
vel = await velocity.get_value()
cur_pos = await curr_pos.get_value()
target_pos = float(await setpoint.get_value())
return abs((target_pos - cur_pos) * 2.0 / vel) + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume this is duplicated for motor- can we have a ticket for the behaviour that we want out of Motor to be isolated in ophyd-async, to at least document why this has ended up here for the future, with the ticket linked as a comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comes back to the discussion of whether we inherit from Motor etc. I will make a new issue

src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Outdated Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
src/dodal/devices/apple2_undulator.py Show resolved Hide resolved
Co-authored-by: Joseph Ware <53935796+DiamondJoseph@users.noreply.github.com>
@DominicOram DominicOram merged commit 3f6af7a into main Feb 6, 2025
19 checks passed
@DominicOram DominicOram deleted the 999_tidy_apple2_undulator branch February 6, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce repeated code in apple2_undulator
4 participants