Commit 4f5a823f authored by ahoms's avatar ahoms
Browse files

* changed Frelon::Camera Roi protocol: setRoi accepts any Roi, getRoi

  returns the effective one, and checkRoi does both withouth hw changes
* finished implementation of Frelon::Camera trigger mode, expusure
  and latency times, nb of frames and start/stop
* added user FrameCallback to Espia::Acq; renamed AcqStatus -> Status
* implemented Espia::BufferMgr wich concat frames and callbacks
* added concat frames in buffer mgrs allocBuffers and getBufferPtr
* changed [un]registerCallback in HwFrameCallbackGen (and derived)
  to recieve a reference to the callback object instead of its pointer
* extended and moved GetDefMaxNbBuffers and ClearBuffer to MemUtils;
  buffer managers now have them as default implementation
* print HwFrameInfoType::frame_timestamp with microsecond resolution;
  added ostream << X/YBorder and Corner operators



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@81 45c4679d-1946-429d-baad-37912b19538b
parent 10cddb0b
......@@ -83,6 +83,14 @@ enum RoiMode {
None, Slow, Fast, Kinetic,
};
enum TimeUnitFactor {
Milliseconds, Microseconds,
};
typedef std::map<TimeUnitFactor, double> TimeUnitFactorMapType;
extern TimeUnitFactorMapType TimeUnitFactorMap;
extern const FrameDim MaxFrameDim;
......
......@@ -44,9 +44,9 @@ class Camera
void setRoiMode(RoiMode roi_mode);
void getRoiMode(RoiMode& roi_mode);
void checkRoi(Roi& roi);
void setRoi(const Roi& roi);
void getRoi(Roi& roi);
void checkRoi(const Roi& set_roi, Roi& hw_roi);
void setRoi(const Roi& set_roi);
void getRoi(Roi& hw_roi);
void setTriggerMode(TrigMode trig_mode);
void getTriggerMode(TrigMode& trig_mode);
......@@ -60,6 +60,9 @@ class Camera
void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames);
void start();
void stop();
private:
static const double HorzBinSleepTime;
......@@ -89,10 +92,16 @@ class Camera
void getImageRoiOffset(const Roi& req_roi, const Roi& image_roi,
Point& roi_offset);
void checkRoiMode(const Roi& roi);
void processRoiReq(Roi& roi, Roi& chan_roi, Point& roi_offset);
void processSetRoi(const Roi& req_roi, Roi& hw_roi, Roi& chan_roi,
Point& roi_offset);
void setTimeUnitFactor(TimeUnitFactor time_unit_factor);
void getTimeUnitFactor(TimeUnitFactor& time_unit_factor);
SerialLine m_ser_line;
Point m_roi_offset;
TrigMode m_trig_mode;
int m_nb_frames;
};
inline bool Camera::isChanActive(InputChan chan)
......
......@@ -102,4 +102,15 @@ FTMInputChanListMapType
lima::Frelon::FTMInputChanListMap(C_LIST_ITERS(FTMInputChanListCList));
typedef pair<TimeUnitFactor, double> FactorPair;
static const FactorPair TimeUnitFactorCList[] = {
FactorPair(Milliseconds, 1e-3),
FactorPair(Microseconds, 1e-6),
};
TimeUnitFactorMapType
lima::Frelon::TimeUnitFactorMap(C_LIST_ITERS(TimeUnitFactorCList));
const FrameDim lima::Frelon::MaxFrameDim(2048, 2048, Bpp16);
#include "FrelonCamera.h"
#include "RegEx.h"
#include "MiscUtils.h"
#include <sstream>
using namespace lima::Frelon;
......@@ -10,7 +11,8 @@ const double Camera::HorzBinSleepTime = 2;
Camera::Camera(Espia::SerialLine& espia_ser_line)
: m_ser_line(espia_ser_line)
{
m_trig_mode = IntTrig;
readRegister(NbFrames, m_nb_frames);
}
SerialLine& Camera::getSerialLine()
......@@ -181,6 +183,9 @@ void Camera::setBin(const Bin& bin)
if (bin == curr_bin)
return;
Roi roi;
setRoi(roi);
writeRegister(BinHorz, bin.getX());
Sleep(HorzBinSleepTime);
writeRegister(BinVert, bin.getY());
......@@ -360,37 +365,39 @@ void Camera::checkRoiMode(const Roi& roi)
setRoiMode(roi_mode);
}
void Camera::checkRoi(Roi& roi)
void Camera::checkRoi(const Roi& set_roi, Roi& hw_roi)
{
if (!roi.isActive())
if (!set_roi.isActive()) {
hw_roi = set_roi;
return;
}
Roi chan_roi;
Point roi_offset;
processRoiReq(roi, chan_roi, roi_offset);
processSetRoi(set_roi, hw_roi, chan_roi, roi_offset);
}
void Camera::processRoiReq(Roi& roi, Roi& chan_roi, Point& roi_offset)
void Camera::processSetRoi(const Roi& set_roi, Roi& hw_roi,
Roi& chan_roi, Point& roi_offset)
{
roi.alignCornersTo(Point(32, 1), Ceil);
getChanRoi(roi, chan_roi);
Roi aligned_roi = set_roi;
aligned_roi.alignCornersTo(Point(32, 1), Ceil);
getChanRoi(aligned_roi, chan_roi);
Roi image_roi;
getImageRoi(chan_roi, image_roi);
getImageRoiOffset(roi, image_roi, roi_offset);
getFinalRoi(image_roi, roi_offset, roi);
getImageRoiOffset(set_roi, image_roi, roi_offset);
getFinalRoi(image_roi, roi_offset, hw_roi);
}
void Camera::setRoi(const Roi& roi)
void Camera::setRoi(const Roi& set_roi)
{
checkRoiMode(roi);
if (!roi.isActive())
checkRoiMode(set_roi);
if (!set_roi.isActive())
return;
Roi chan_roi, proc_roi = roi;
Roi hw_roi, chan_roi;
Point roi_offset;
processRoiReq(proc_roi, chan_roi, roi_offset);
if (proc_roi != roi)
throw LIMA_HW_EXC(InvalidValue, "Requested roi not valid");
processSetRoi(set_roi, hw_roi, chan_roi, roi_offset);
Point tl = chan_roi.getTopLeft();
Size size = chan_roi.getSize();
......@@ -403,8 +410,15 @@ void Camera::setRoi(const Roi& roi)
m_roi_offset = roi_offset;
}
void Camera::getRoi(Roi& roi)
void Camera::getRoi(Roi& hw_roi)
{
hw_roi.reset();
RoiMode roi_mode;
getRoiMode(roi_mode);
if (roi_mode == None)
return;
int rpb, rpw, rlb, rlw;
readRegister(RoiPixelBegin, rpb);
readRegister(RoiPixelWidth, rpw);
......@@ -414,6 +428,104 @@ void Camera::getRoi(Roi& roi)
Roi chan_roi(Point(rpb, rlb), Size(rpw, rlw));
Roi image_roi;
getImageRoi(chan_roi, image_roi);
getFinalRoi(image_roi, m_roi_offset, roi);
getFinalRoi(image_roi, m_roi_offset, hw_roi);
}
void Camera::setTriggerMode(TrigMode trig_mode)
{
m_trig_mode = trig_mode;
}
void Camera::getTriggerMode(TrigMode& trig_mode)
{
trig_mode = m_trig_mode;
}
void Camera::setTimeUnitFactor(TimeUnitFactor time_unit_factor)
{
int time_unit = int(time_unit_factor);
writeRegister(TimeUnit, time_unit);
}
void Camera::getTimeUnitFactor(TimeUnitFactor& time_unit_factor)
{
int time_unit;
readRegister(TimeUnit, time_unit);
time_unit_factor = TimeUnitFactor(time_unit);
}
void Camera::setExpTime(double exp_time)
{
const int MaxVal = (1 << 16) - 1;
bool ok = false;
int exp_val;
TimeUnitFactor seq_clist[] = { Microseconds, Milliseconds };
TimeUnitFactor *it, *end = C_LIST_END(seq_clist);
for (it = seq_clist; it != end; ++it) {
double factor = TimeUnitFactorMap[*it];
exp_val = int(exp_time / factor + 0.1);
ok = (exp_val <= MaxVal);
if (ok)
break;
}
if (!ok)
throw LIMA_HW_EXC(InvalidValue, "Exposure time too high");
TimeUnitFactor time_unit_factor = (exp_val == 0) ? Milliseconds : *it;
setTimeUnitFactor(time_unit_factor);
writeRegister(ExpTime, exp_val);
}
void Camera::getExpTime(double& exp_time)
{
TimeUnitFactor time_unit_factor;
getTimeUnitFactor(time_unit_factor);
int exp_val;
readRegister(ExpTime, exp_val);
exp_time = exp_val * TimeUnitFactorMap[time_unit_factor];
}
void Camera::setLatTime(double lat_time)
{
int lat_val = int(lat_time / TimeUnitFactorMap[Milliseconds] + 0.1);
writeRegister(LatencyTime, lat_val);
}
void Camera::getLatTime(double& lat_time)
{
int lat_val;
readRegister(LatencyTime, lat_val);
lat_time = lat_val * TimeUnitFactorMap[Milliseconds];
}
void Camera::setNbFrames(int nb_frames)
{
TrigMode trig_mode;
getTriggerMode(trig_mode);
int cam_nb_frames = (trig_mode == ExtTrigMult) ? 1 : nb_frames;
writeRegister(NbFrames, cam_nb_frames);
m_nb_frames = nb_frames;
}
void Camera::getNbFrames(int& nb_frames)
{
nb_frames = m_nb_frames;
}
void Camera::start()
{
TrigMode trig_mode;
getTriggerMode(trig_mode);
if (trig_mode == IntTrig)
sendCmd(Start);
}
void Camera::stop()
{
TrigMode trig_mode;
getTriggerMode(trig_mode);
if (trig_mode != ExtGate)
sendCmd(Stop);
}
#include "FrelonCamera.h"
#include "EspiaBufferMgr.h"
#include <iostream>
......@@ -53,15 +54,62 @@ void frelon_read_reg(Frelon::Camera& frelon_cam, Frelon::Reg reg)
cout << "Val" << " " << val << endl;
}
void test_sleep(double sleep_time)
void frelon_set_roi(Frelon::Camera& frelon_cam, const Roi& set_roi)
{
Roi hw_roi;
frelon_cam.getRoi(hw_roi);
cout << "HwRoi " << hw_roi << endl;
cout << "SetRoi " << set_roi << endl;
frelon_cam.checkRoi(set_roi, hw_roi);
cout << "HwRoi " << hw_roi << endl;
frelon_cam.setRoi(set_roi);
frelon_cam.getRoi(hw_roi);
cout << "HwRoi " << hw_roi << endl;
}
void print_sleep(double sleep_time)
{
cout << "Sleep(" << sleep_time << "): " << Sleep(sleep_time) << endl;
}
void test_sleep()
{
print_sleep(0.1);
print_sleep(1.5);
print_sleep(0.1);
print_sleep(0.01);
print_sleep(0.001);
}
class FrelonFrameCb : public HwFrameCallback
{
public:
FrelonFrameCb(int nb_frames, Cond& acq_finished)
: m_nb_frames(nb_frames), m_acq_finished(acq_finished) {}
protected:
virtual bool newFrameReady(const HwFrameInfoType& frame_info)
{
cout << frame_info << " \r" << flush;
if (frame_info.acq_frame_nb == m_nb_frames - 1) {
cout << endl;
m_acq_finished.signal();
}
return true;
}
private:
int m_nb_frames;
Cond& m_acq_finished;
};
void test_frelon(bool do_reset)
{
Espia::Dev espia(0);
Espia::SerialLine espia_ser_line(espia);
Espia::Dev espia_dev(0);
Espia::Acq espia_acq(espia_dev);
Espia::BufferMgr espia_buffer_mgr(espia_acq);
Espia::SerialLine espia_ser_line(espia_dev);
Frelon::SerialLine frelon_ser_line(espia_ser_line);
Frelon::Camera frelon_cam(espia_ser_line);
......@@ -106,13 +154,99 @@ void test_frelon(bool do_reset)
}
cout << endl;
test_sleep(0.1);
test_sleep(3.5);
test_sleep(0.1);
test_sleep(0.01);
test_sleep(0.001);
test_sleep();
cout << "TopLeft: " << TopLeft << endl;
cout << "TopRight: " << TopRight << endl;
cout << "BottomLeft: " << BottomLeft << endl;
cout << "BottomRight: " << BottomRight << endl;
Bin bin;
Roi roi;
frelon_cam.getBin(bin);
cout << "Bin " << bin << endl;
bin = 1;
cout << "Bin " << bin << endl;
frelon_cam.setBin(bin);
frelon_cam.getBin(bin);
cout << "Bin " << bin << endl;
roi = Roi(Point(515, 517), Size(1021, 521));
frelon_set_roi(frelon_cam, roi);
frelon_cam.getBin(bin);
cout << "Bin " << bin << endl;
bin = 2;
cout << "Bin " << bin << endl;
frelon_cam.setBin(bin);
frelon_cam.getBin(bin);
cout << "Bin " << bin << endl;
roi = Roi(Point(257, 259), Size(509, 265));
frelon_set_roi(frelon_cam, roi);
roi = Roi(Point(57, 59), Size(71, 72));
frelon_set_roi(frelon_cam, roi);
bin = 1;
cout << "Bin " << bin << endl;
frelon_cam.setBin(bin);
frelon_cam.getBin(bin);
cout << "Bin " << bin << endl;
roi.reset();
frelon_set_roi(frelon_cam, roi);
FrameDim frame_dim;
frelon_cam.getFrameDim(frame_dim);
frame_dim /= bin;
int max_nb_buffers = espia_buffer_mgr.getMaxNbBuffers(frame_dim);
cout << "MaxNbBuffers " << max_nb_buffers << endl;
int nb_buffers = max_nb_buffers;
int nb_concat_frames = 1;
espia_buffer_mgr.allocBuffers(nb_buffers, nb_concat_frames, frame_dim);
espia_buffer_mgr.getNbBuffers(nb_buffers);
espia_buffer_mgr.getNbConcatFrames(nb_concat_frames);
cout << "NbBuffers " << nb_buffers << ", "
<< "NbConcatFrames " << nb_concat_frames << endl;
TrigMode trig_mode;
frelon_cam.getTriggerMode(trig_mode);
cout << "TrigMode " << trig_mode << endl;
trig_mode = IntTrig;
frelon_cam.setTriggerMode(trig_mode);
frelon_cam.getTriggerMode(trig_mode);
cout << "TrigMode " << trig_mode << endl;
int nb_frames;
frelon_cam.getNbFrames(nb_frames);
cout << "NbFrames " << nb_frames << endl;
nb_frames = nb_buffers;
frelon_cam.setNbFrames(nb_frames);
frelon_cam.getNbFrames(nb_frames);
cout << "NbFrames " << nb_frames << endl;
Espia::Acq::StatusType acq_status;
espia_acq.getStatus(acq_status);
cout << "running " << acq_status.running << ", "
<< "last_frame_nb " << acq_status.last_frame_nb << endl;
espia_acq.setNbFrames(nb_frames);
Cond acq_finished;
FrelonFrameCb frame_cb(nb_frames, acq_finished);
espia_buffer_mgr.registerFrameCallback(frame_cb);
espia_acq.start();
frelon_cam.start();
acq_finished.wait();
cout << "Acq. finished!" << endl;
}
int main(int argc, char *argv[])
{
......
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