Skip to content

DemoCamera: Fixed DemoXYStage position reporting bugs and added a polling thread#946

Open
nicost wants to merge 5 commits into
micro-manager:mainfrom
nicost:demoStagePolling
Open

DemoCamera: Fixed DemoXYStage position reporting bugs and added a polling thread#946
nicost wants to merge 5 commits into
micro-manager:mainfrom
nicost:demoStagePolling

Conversation

@nicost
Copy link
Copy Markdown
Member

@nicost nicost commented May 22, 2026

Polling thread fires OnXYStagePositionChanged callbacks during moves. The thread now wakes immediately when a move starts via a condition variable.

…ling thread that fires OnXYStagePositionChanged callbacks during moves. The thread now wakes immediately when a move starts via a condition variable.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the DemoCamera XY stage simulation to improve position reporting during moves by introducing a background polling thread that emits OnXYStagePositionChanged callbacks mid-move, and it fixes related position/relative-move behavior.

Changes:

  • Added a PollingThread to CDemoXYStage that wakes on move start and periodically reports interpolated XY positions during motion.
  • Added locking around move state (timeOutTimer_, positions) and simplified Busy()/Stop() behavior.
  • Minor cleanup: silence unused exposure parameter in bead image generation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
DeviceAdapters/DemoCamera/DemoStages.cpp Adds XY-stage polling thread, locking, updated move interpolation/reporting, and relative-move/stop logic changes.
DeviceAdapters/DemoCamera/DemoCamera.h Declares new relative-move override and polling thread members for CDemoXYStage.
DeviceAdapters/DemoCamera/DemoImageGeneration.cpp Marks exposure parameter unused in GenerateBeadsImage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DeviceAdapters/DemoCamera/DemoCamera.h
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp Outdated
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp Outdated
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp Outdated
@nicost
Copy link
Copy Markdown
Member Author

nicost commented May 22, 2026

@marktsuchida and @tlambert03, let me know if this is OK to merge. This adds a polling thread that will update the core with the current position of the stage even while it is moving. This polling thread can be switched off through a property which will also causes the UsesOnXYStagePositionChanged function to no longer signal true. Should be useful for testing position updates in the UI with and without polling.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread DeviceAdapters/DemoCamera/DemoCamera.h
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp Outdated
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp
Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp
@tlambert03
Copy link
Copy Markdown
Contributor

I'm curious why you felt like it was the responsibility of the device adapter itself (rather than the core, or the application) to create the polling thread?

@nicost
Copy link
Copy Markdown
Member Author

nicost commented May 22, 2026

Some device adapters will report stage positions themselves, others do not. They can declare that through the UsesOnXYStagePositionChanged function. We are planning on creating a single polling loop in the UI that will query all the stages that are not themselves calling OnXYStagePositionChanged. It seems handy to have a demo device with which we can test both approaches.

So, if a device has a built-in mechanism to report changed positions, we should use it, otherwise we should leave it to application (or possibly the core, I am not quite sure where the best place for that polling loop is). Curious if you prefer this to be in the core or in the application.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread DeviceAdapters/DemoCamera/DemoStages.cpp
Comment thread DeviceAdapters/DemoCamera/DemoCamera.h
Copy link
Copy Markdown
Member

@marktsuchida marktsuchida 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 to me — the setting is pre-init so it conforms to the UsesOnXYStagePositionChanged() rules (no dynamic switching).

A few comments below.

Note that NotificationTester already provides the most robust (and uncluttered) way to test all the different stage notification behaviors — although we haven't updated it for the new UsesOnXYStagePositionChanged() function yet. There we probably need to make the NotificationsEnabled property pre-init.

Comment on lines +689 to +695
#ifdef _WIN32
HANDLE moveEvent_;
#else
pthread_mutex_t eventMutex_;
pthread_cond_t eventCond_;
bool eventSignaled_ = false;
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can standard C++ std::mutex and std::condition_variable be used?

Comment on lines +655 to +656
void StartPollingThread();
void StopPollingThread();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The thread doesn't do any polling, so maybe better to name something else. (NotificationThread?)

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.

4 participants