Commit b5a3a8b6 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

roi: managed hardware roi from 1M to 6M

parent 6556abb7
......@@ -49,6 +49,7 @@ public:
SETTING_EXPOSURE_PERIOD,
SETTING_HARDWARE_TRIGGER_DELAY,
SETTING_EXPOSURE_PER_FRAME,
SETTING_ROI,
KILL_ACQUISITION,
RUNNING,
ANYCMD
......@@ -128,6 +129,9 @@ public:
int nbAcquiredImages() const;
void version(int& major,int& minor,int& patch) const;
bool hasRoiCapability() const;
void setRoi(const std::string&);
private:
static const double TIME_OUT = 10.;
......@@ -177,6 +181,7 @@ private:
int m_nb_acquired_images;
bool m_has_cmd_setenergy;
bool m_pilatus3_threshold_mode;
bool m_has_cmd_roi;
int m_major_version;
int m_minor_version;
int m_patch_version;
......
......@@ -22,6 +22,8 @@
#ifndef PILATUSINTERFACE_H
#define PILATUSINTERFACE_H
#include <vector>
#include "lima/HwInterface.h"
#include "lima/HwFileEventMgr.h"
#include "lima/Debug.h"
......@@ -118,7 +120,32 @@ private:
double m_exposure_requested;
double m_latency;
};
/*******************************************************************
* \class RoiCtrlOb
* \brief Control object providing Pilatus hardware roi
*******************************************************************/
class RoiCtrlObj : public HwRoiCtrlObj
{
DEB_CLASS_NAMESPC(DebModCamera, "RoiCtrlObj", "Pilatus");
public:
RoiCtrlObj(Camera& cam,DetInfoCtrlObj&);
virtual void checkRoi(const Roi& set_roi, Roi& hw_roi);
virtual void setRoi(const Roi& set_roi);
virtual void getRoi(Roi& hw_roi);
private:
typedef std::pair<const char*,Roi> PATTERN2ROI;
typedef std::vector<PATTERN2ROI> ROIS;
inline ROIS::const_iterator _getRoi(const Roi& roi) const;
Camera& m_cam;
DetInfoCtrlObj& m_det;
bool m_has_hardware_roi;
ROIS m_possible_rois;
Roi m_current_roi;
};
/*******************************************************************
* \class Interface
* \brief Pilatus hardware interface
......@@ -163,6 +190,7 @@ private:
HwTmpfsBufferMgr m_buffer;
SyncCtrlObj m_sync;
SavingCtrlObj m_saving;
RoiCtrlObj m_roi;
};
} // namespace Pilatus
......
......@@ -19,6 +19,7 @@ namespace Pilatus
SETTING_EXPOSURE_PERIOD,
SETTING_HARDWARE_TRIGGER_DELAY,
SETTING_EXPOSURE_PER_FRAME,
SETTING_ROI,
KILL_ACQUISITION,
RUNNING
};
......@@ -97,5 +98,8 @@ namespace Pilatus
int nbAcquiredImages() const;
void version(int& major /Out/,int& minor /Out/,int& patch /Out/) const;
bool hasRoiCapability() const;
void setRoi(const std::string&);
};
};
......@@ -112,6 +112,7 @@ Camera::Camera(const char *host,int port)
m_nb_acquired_images(0),
m_has_cmd_setenergy(true),
m_pilatus3_threshold_mode(false),
m_has_cmd_roi(true),
m_major_version(-1),
m_minor_version(-1),
m_patch_version(-1)
......@@ -279,6 +280,8 @@ void Camera::_resync()
send("setenergy");
else
send("setthreshold");
if(m_has_cmd_roi)
send("setroi 0");
send("exptime");
send("expperiod");
send("nimages 1");
......@@ -582,6 +585,12 @@ void Camera::_run()
{
DEB_TRACE() << "Can't retrieved camserver version";
}
else if(msg.find("Unrecognized command: setroi") !=
std::string::npos)
{
m_has_cmd_roi = false;
_resync();
}
else
{
DEB_TRACE() << "-- ERROR";
......@@ -1140,5 +1149,36 @@ void Camera::version(int& major,int& minor,int& patch) const
minor = m_minor_version;
patch = m_patch_version;
}
//-----------------------------------------------------
// ROI(S)
//-----------------------------------------------------
bool Camera::hasRoiCapability() const
{
AutoMutex lock(m_cond.mutex());
return m_pilatus3_threshold_mode && m_has_cmd_roi;
}
void Camera::setRoi(const std::string& roi_pattern)
{
DEB_MEMBER_FUNCT();
if(!hasRoiCapability())
THROW_HW_ERROR(Error) << "This detector doesn't manage hardware roi";
AutoMutex aLock(m_cond.mutex());
RECONNECT_WAIT_UNTIL(Camera::STANDBY,
"Could not set exposure period, server not idle");
m_state = Camera::SETTING_ROI;
std::stringstream msg;
msg << "setroi " << roi_pattern;
send(msg.str());
// ROI can failed if it's not manage in this detector
while(m_state == Camera::SETTING_ROI)
m_cond.wait(TIME_OUT);
if(m_state == Camera::ERROR)
{
m_state = Camera::STANDBY;
THROW_HW_ERROR(Error) << "Could not set roi to:"
<< DEB_VAR2(roi_pattern,m_error_message);
}
}
//-----------------------------------------------------
......@@ -374,6 +374,152 @@ void SyncCtrlObj::prepareAcq()
m_cam.setNbImagesInSequence(nb_frames);
}
/*****************************************************************************
ROI
*****************************************************************************/
static const int MODULE_WIDTH = 487;
static const int MODULE_HEIGHT = 195;
static const int MODULE_WIDTH_SPACE = 7;
static const int MODULE_HEIGHT_SPACE = 17;
RoiCtrlObj::RoiCtrlObj(Camera& cam,DetInfoCtrlObj& det) :
m_cam(cam),
m_det(det),
m_has_hardware_roi(det.isPilatus3())
{
DEB_CONSTRUCTOR();
Size detImageSize;
det.getDetectorImageSize(detImageSize);
if(m_has_hardware_roi)
{
if(detImageSize == Size(2463,2527)) // Pilatus 6M
{
Roi c2(2 * MODULE_WIDTH + 2 * MODULE_WIDTH_SPACE,
5 * MODULE_HEIGHT + 5 * MODULE_HEIGHT_SPACE,
MODULE_WIDTH,
2 * MODULE_HEIGHT + MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("C2",c2));
Roi c18(MODULE_WIDTH + MODULE_WIDTH_SPACE,
3 * (MODULE_HEIGHT + MODULE_HEIGHT_SPACE),
3 * MODULE_WIDTH + 2 * MODULE_WIDTH_SPACE,
6 * MODULE_HEIGHT + 5 * MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("C18",c18));
}
else if(detImageSize == Size(1475,1679)) // Pilatus 2M
{
Roi c2(MODULE_WIDTH + MODULE_WIDTH_SPACE,
3 * MODULE_HEIGHT + 3 * MODULE_HEIGHT_SPACE,
MODULE_WIDTH,
2 * MODULE_HEIGHT + MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("C2",c2));
Roi r8(MODULE_WIDTH + MODULE_WIDTH_SPACE,
2 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE,
2 * MODULE_WIDTH + MODULE_WIDTH_SPACE,
4 * MODULE_HEIGHT + 3 * MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("R8",r8));
Roi l8(0,
2 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE,
2 * MODULE_WIDTH + MODULE_WIDTH_SPACE,
4 * MODULE_HEIGHT + 3 * MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("L8",l8));
Roi c12(0,
2 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE,
3 * MODULE_WIDTH + 2 * MODULE_WIDTH_SPACE,
4 * MODULE_HEIGHT + 3 * MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("C12",c12));
}
else if(detImageSize == Size(981,1043)) // Pilatus 1M
{
Roi r1(MODULE_WIDTH + MODULE_WIDTH_SPACE,
2 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE,
MODULE_WIDTH,
MODULE_HEIGHT);
m_possible_rois.push_back(PATTERN2ROI("R1",r1));
Roi l1(0,
2 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE,
MODULE_WIDTH,
MODULE_HEIGHT);
m_possible_rois.push_back(PATTERN2ROI("L1",l1));
Roi r3(MODULE_WIDTH + MODULE_WIDTH_SPACE,
MODULE_HEIGHT + MODULE_HEIGHT_SPACE,
MODULE_WIDTH,
3 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("R3",r3));
Roi l3(0,
MODULE_HEIGHT + MODULE_HEIGHT_SPACE,
MODULE_WIDTH,
3 * MODULE_HEIGHT + 2 * MODULE_HEIGHT_SPACE);
m_possible_rois.push_back(PATTERN2ROI("L3",l3));
}
else
m_has_hardware_roi = false;
}
if(!m_has_hardware_roi)
DEB_WARNING() << "Hardware Roi not managed for this detector";
Roi full(Point(0,0),detImageSize);
m_possible_rois.push_back(PATTERN2ROI("0",full));
m_current_roi = full;
}
void RoiCtrlObj::checkRoi(const Roi& set_roi, Roi& hw_roi)
{
DEB_MEMBER_FUNCT();
ROIS::const_iterator i = _getRoi(set_roi);
if(i == m_possible_rois.end())
THROW_HW_ERROR(Error) << "Something weird happen";
hw_roi = i->second;
}
void RoiCtrlObj::setRoi(const Roi& set_roi)
{
DEB_MEMBER_FUNCT();
ROIS::const_iterator i;
if(set_roi.isActive())
{
i = _getRoi(set_roi);
if(i == m_possible_rois.end())
THROW_HW_ERROR(Error) << "Something weird happen";
}
else
i = --m_possible_rois.end(); // full_frame
if(m_has_hardware_roi)
m_cam.setRoi(i->first);
m_current_roi = i->second;
}
void RoiCtrlObj::getRoi(Roi& hw_roi)
{
hw_roi = m_current_roi;
}
inline RoiCtrlObj::ROIS::const_iterator
RoiCtrlObj::_getRoi(const Roi& roi) const
{
for(ROIS::const_iterator i = m_possible_rois.begin();
i != m_possible_rois.end();++i)
{
if(i->second.containsRoi(roi))
return i;
}
return m_possible_rois.end();
}
/*****************************************************************************
Memory map manager
*****************************************************************************/
......@@ -504,8 +650,9 @@ public:
{
DEB_MEMBER_FUNCT();
Size current_size;
m_interface.m_det_info.getDetectorImageSize(current_size);
Roi hw_roi;
m_interface.m_roi.getRoi(hw_roi);
const Size &current_size = hw_roi.getSize();
ImageType current_image_type;
m_interface.m_det_info.getCurrImageType(current_image_type);
......@@ -532,7 +679,8 @@ Interface::Interface(Camera& cam,const DetInfoCtrlObj::Info* info)
m_buffer(WATCH_PATH,FILE_PATTERN,
*m_buffer_cbk),
m_sync(cam,m_det_info),
m_saving(cam)
m_saving(cam),
m_roi(cam,m_det_info)
{
DEB_CONSTRUCTOR();
......@@ -548,6 +696,9 @@ Interface::Interface(Camera& cam,const DetInfoCtrlObj::Info* info)
HwSavingCtrlObj *saving = &m_saving;
m_cap_list.push_back(HwCap(saving));
HwRoiCtrlObj *roi = &m_roi;
m_cap_list.push_back(HwCap(roi));
m_buffer.getDirectoryEvent().watch_moved_to();
//Activate new pilatus3 threshold method
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment