Skip to content

Add HWP Sequencer app - #234

Open
mileslucas wants to merge 19 commits into
devfrom
ml/hwpSequencer
Open

Add HWP Sequencer app#234
mileslucas wants to merge 19 commits into
devfrom
ml/hwpSequencer

Conversation

@mileslucas

Copy link
Copy Markdown
Contributor

HWP sequencer manages the state machine for the polarimeter, which moves the HWP stage and toggles data acquistion on and off.

To be tested.

@mileslucas

Copy link
Copy Markdown
Contributor Author

Testing works fine using a non-threaded blocking appLogic method with a magic sleep timer. Need to move to a threaded call to moveHwp which should wait until the HWP is in the desired position.

@mileslucas

Copy link
Copy Markdown
Contributor Author

This is tested working on exao1

  • acquisition time is greater than or equal to the timePerPos property
  • the hwp moves to correct position and blocks until that position is reached
  • the hwp positions work regardless of hwp adi tracking being turned on
  • setting numCyles to -1 correctly loops forever
  • setting numCycles to >0 correctly ends after the number of loops
  • the lastCycle toggle appropriately stops sequencing at the final hwp position
  • toggle the sequence switch immediately ends the acquistion
  • if the hwpsequence app crashes/stops it will stop saving data
  • No blocking code is inside appLogic, it's inside a separate thread

@mileslucas
mileslucas requested a review from jaredmales December 3, 2025 19:15
@mileslucas

Copy link
Copy Markdown
Contributor Author

Actually, one question to resolve is whether we should be triggering obs_on or triggering the fxngensync output.

Triggering obs_on is noisy on maggieo_x and leads to an explosion of folders, so it might be better to turn the trigger off instead, but this conflicts with the lab rules I just wrote for #228

@mileslucas

Copy link
Copy Markdown
Contributor Author

New behavior using fxngensync output to pause acquisition during HWP movement is tested and working

@mileslucas

Copy link
Copy Markdown
Contributor Author

Final piece of logic to implement is some kind of block to wait for the current frame to readout before moving HWP--I think I can just wait for a semaphore from the SHM for one of the camscis.

@mileslucas

Copy link
Copy Markdown
Contributor Author

I've moved the app to run on ICC so the SHMs are as fresh as possible. The semaphore waits are tested to work with both fast exposure times (5 Hz) and slow exposure times (10s). Long exposures have little to no observing efficiency loss because we turn the external trigger off and then wait for the semaphore, which means there are no intermediate exposures that lock us up for a full exposure time before continuing saving.

I think this is ready to go now!

@mileslucas

Copy link
Copy Markdown
Contributor Author

depends on #244 now but otherwise should be ready to go

@mileslucas mileslucas mentioned this pull request Dec 7, 2025
@mileslucas
mileslucas force-pushed the ml/hwpSequencer branch 3 times, most recently from 669406a to 6e99490 Compare December 9, 2025 23:40
@mileslucas

Copy link
Copy Markdown
Contributor Author

new features as of 2025/12/09

  • If data is already being saved, turn it off via obs_on
  • Make sure the fxngensync output is turned on when appShutdown is called to keep cameras running even if this app breaks
  • Move HWP back to 0 deg after sequence is finished
  • Update to using shmimMonitor which means the semaphore wait still works even when camera ROI changes or any other case where the shmim changes

@mileslucas

Copy link
Copy Markdown
Contributor Author

@jaredmales this is the block of code that is screwed up--the sympton is that regardlesss of camera readout time, on the first iteration of the sequence the sem_wait call is instantaneous. only on the first iteration. This is obvious when using long exposures, if you set EXPTIME to 10 seconds and start a sequence, the obs_on toggle will turn on way before the current frame is read out. Subsequent sem_waits do exactly what's expected--blocks until a frame is received and the processImage method is called.

It is crazy bizarre that the same exact code has different behavior. The startSequencing method does not touch the semaphore, nor does appLogic. One of the only things that's different is the m_startSaving flag (true on first iteration, false otherwise), and the indices for the current cycle status.

// DEBUG
int semval;
sem_getvalue( &m_smSemaphore, &semval);
std::cerr << "SEMVALUE before flush: " << semval << std::endl;
XWC_SEM_FLUSH(m_smSemaphore);
// DEBUG
sem_getvalue( &m_smSemaphore, &semval);
std::cerr << "SEMVALUE after flush: " << semval << std::endl;
// Stop triggering
m_indiP_fxngenOutput["value"] = "Off";
sendNewProperty(m_indiP_fxngenOutput);
sem_getvalue( &m_smSemaphore, &semval);
std::cerr << "SEMVALUE after fxngenoutput changed: " << semval << std::endl;
while (m_fxngenOutp)
mx::sys::milliSleep(m_hwpWait);
sem_getvalue( &m_smSemaphore, &semval);
std::cerr << "SEMVALUE after fxngenoutput confirmed: " << semval << std::endl;
sem_getvalue( &m_smSemaphore, &semval);
std::cerr << "SEMVALUE before wait: " << semval << std::endl;
// Wait for current frame to arrive
if (sem_wait(&m_smSemaphore) < 0)
{
log<software_error>({ __FILE__, __LINE__, "failed waiting for semaphore" });
return -1;
}
sem_getvalue( &m_smSemaphore, &semval);
std::cerr << "SEMVALUE after wait: " << semval << std::endl;

Comment thread apps/hwpSequencer/hwpSequencer.hpp
Comment thread apps/hwpSequencer/hwpSequencer.hpp
Comment thread apps/hwpSequencer/hwpSequencer.hpp Outdated
return -1;
}

mx::sys::sleep(m_timePerPos);

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 sleep function takes an unsigned as argument, so it's integer seconds. You probably want to use mx::sys::microSleep(m_timePerPos*1e6);

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.

see dfd2f8

Comment thread apps/hwpSequencer/hwpSequencer.hpp Outdated
m_doMoveHwp = false;
}

mx::sys::sleep(0.1);

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.

same as above. In this case it's not sleeping at all.

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.

see dfd2f8

@mileslucas
mileslucas requested a review from a team April 10, 2026 21:33
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.

2 participants