diff --git a/zynq_7010_code/CameraParams.h b/zynq_7010_code/CameraParams.h index 7480e6e..68691d0 100644 --- a/zynq_7010_code/CameraParams.h +++ b/zynq_7010_code/CameraParams.h @@ -81,6 +81,16 @@ union CamZ_Reg_A_New unsigned int dpi_200: 1; //dpi=1的时候 dpi_200=1 200dpi dpi=1的时候 dpi_200=0 300dpi dpi=0的时候 dpi_200=0 600dpi }; }; +union CamZ_Reg_11 +{ + int value; + struct + { + unsigned int div_reg:5; + unsigned int samp_reg:10; + unsigned int low_reg:10; + }; +}; union SCAN_PWM diff --git a/zynq_7010_code/CuoZhiMotor.cpp b/zynq_7010_code/CuoZhiMotor.cpp index c0d6226..f699565 100644 --- a/zynq_7010_code/CuoZhiMotor.cpp +++ b/zynq_7010_code/CuoZhiMotor.cpp @@ -59,7 +59,7 @@ void CuoZhiMotor::reset() mspCuozhiBackward.a, mspCuozhiBackward.offset, mspCuozhiBackward.finalDelay); - LOG("finalPeriod=%d Fmin=%d \n", mspCuozhiBackward.finalPeriod, mspCuozhiBackward.Fmin); + //printf("finalPeriod=%d Fmin=%d \n", mspCuozhiBackward.finalPeriod, mspCuozhiBackward.Fmin); Motor::start(delays_forward, mspCuozhiBackward); std::random_device rd; // obtain a random number from hardware std::mt19937 gen(rd()); // seed the generator diff --git a/zynq_7010_code/HCamDevice.cpp b/zynq_7010_code/HCamDevice.cpp index 4bd35b6..570aa10 100644 --- a/zynq_7010_code/HCamDevice.cpp +++ b/zynq_7010_code/HCamDevice.cpp @@ -155,6 +155,7 @@ HCamDevice::HCamDevice() //devmem 0x40010040 32 0x00000B00 //灰度模式 VSNP值 0x10 //this->event_thread.reset(new std::thread(&HCamDevice::HtCamEventWorkThread, this)); + //this->event_thread.reset(new std::thread(&HCamDevice::auto_duty_cycle,this)); for (int i = 0; i < 20; i++) { //HtCamReadADCReg(i, &val); @@ -323,6 +324,32 @@ void HCamDevice::HtCamSetPeriod(double reg_value) printf("PWM占空比:%d\r\n",rgb.NShort[1]); HtCamWriteFpgaRegs(0x09,rgb.value); } +// void HCamDevice::HtCamGetPeriod(double ®_value) +// { +// int reg = HtCamReadFpgaRegs(0x11); +// } +// void HCamDevice::HtCamSetLowLevelTimer(double reg_value) +// { +// reg_value /= 100; +// CamZ_Reg_11 reg; +// reg.value = HtCamReadFpgaRegs(0x11); +// int crossover_period = reg.div_reg * 10;//单位是ns +// int cycle = 1 / 1.6119 * 100000000;//单位是s 转换为ns +// reg.low_reg = cycle * (1 - reg_value) / crossover_period; +// } +// void HCamDevice::auto_duty_cycle() +// { +// std::unique_lock lock(auto_duty_wait); + +// while (true) +// { +// wait_auto_duty_.wait(lock); + + +// } + + +// } int HCamDevice::HtCamEventWorkThread(void) { struct pollfd pfd; diff --git a/zynq_7010_code/HCamDevice.h b/zynq_7010_code/HCamDevice.h index de764b1..e7d7718 100644 --- a/zynq_7010_code/HCamDevice.h +++ b/zynq_7010_code/HCamDevice.h @@ -52,6 +52,7 @@ public: void HtCamGetPeriod(uint8_t ®_value);//获取扫描仪传感器占空比 void HtCamSetPeriod(double reg_value); //设置扫描仪传感器占空比 + //void HtCamGetPeriod(double ®_value); //获取扫描仪传感器占空比 void HtCamGetFrameCnt(uint32_t &val);//获取设置采集的帧数 需要采集的帧数,设置为0x05表示采集六帧后停止 void HtCamSetFrameCnt(uint32_t val);//需要采集的帧数,设置为0x05表示采集六帧后停止 @@ -180,6 +181,10 @@ private: std::shared_ptr event_thread = nullptr; + + std::shared_ptr thread_auto_duty= nullptr; + //std::condition_variable auto_duty_wait; + //std::mutex auto_duty_lock_; Camconfig* config = nullptr; std::string _CAM_TYPE = "PYTHONZ_1200"; diff --git a/zynq_7010_code/MultiFrameCapture.cpp b/zynq_7010_code/MultiFrameCapture.cpp index 556cfe8..af20029 100644 --- a/zynq_7010_code/MultiFrameCapture.cpp +++ b/zynq_7010_code/MultiFrameCapture.cpp @@ -215,7 +215,7 @@ void MultiFrameCapture::UpdateScanParam(HG_ScanConfiguration config) uint32_t cnt = compute_frame(paper_size_ , val) ; if (resolution_ == 2) { - cnt -=1 ; + //cnt -=1 ; } video->HtCamSetFrameCnt(cnt); @@ -274,7 +274,7 @@ void MultiFrameCapture::waitsnapdone(int state) m_glue.m_imageready(ip); //发一次空包 b_end_snap = true; - printf("!!!!!!!!!!!!!!!! m_cv_snapdone wait done :%f \n",sw.elapsed_ms()); + printf("走纸结束,等待采集完成耗时:%f \n",sw.elapsed_ms()); } bool MultiFrameCapture::IsImageQueueEmpty() { @@ -331,23 +331,24 @@ void MultiFrameCapture::snaprun() if (data) { - if (i == 1) + if (i == 2) { - uint32_t cnt = 25; - if (paper_size_ != (unsigned int)PaperSize::G400_MAXSIZE && !is_remove_morr_) - { - int val = resolution_ == 3 ? 600 :(resolution_ == 2?300:200); - cnt = compute_frame((unsigned int)PaperSize::G400_AUTO , val) ; - cnt *=sw.elapsed_ms(); - } - else - cnt = (info_ex.frame_index + 1) * sw.elapsed_ms(); - - image_cb_(cnt); - img_wait_.notify_all(); + uint32_t cnt = 25; + if (paper_size_ != (unsigned int)PaperSize::G400_MAXSIZE && !is_remove_morr_) + { + int val = resolution_ == 3 ? 600 :(resolution_ == 2?300:200); + cnt = compute_frame((unsigned int)PaperSize::G400_AUTO , val) ; + cnt *=(sw.elapsed_ms() +3); + } + else + cnt = (info_ex.frame_index + 3) * sw.elapsed_ms(); + image_cb_(cnt); + img_wait_.notify_all(); // cv::imwrite("/home/root/test.bmp", mat); //cv::imwrite("/home/root/test.bmp", mat); //savebitmap(data,15552,512,"1.bmp"); + + printf("第二帧图像采集耗时:%f\r\n",sw.elapsed_ms()); } HG_JpegCompressInfo info ; @@ -363,8 +364,8 @@ void MultiFrameCapture::snaprun() //printf("获取数据 width:%d height:%d is_first:%d is_last:%d DataLength:%d\r\n",info_ex.width,info_ex.height,info.first_frame,info.last_frame,info.DataLength); + //printf("index_frame:%d\r\n",info.index_frame); m_glue.m_imageready(info); - printf("采集图像耗时:%f\r\n",sw.elapsed_ms()); } return ret; }; @@ -387,24 +388,32 @@ void MultiFrameCapture::snaprun() int channels = color_mode_ == 1 ? 3 : 1; int color_mode = video->HtCamGetColorMode(); int func_sig = 0; - int time_out = resolution_ == DPI_600 ? 2000 : 900; ///这个时间是根据每帧的数据量来进行调测的 + int time_out = resolution_ == DPI_600 ? 2000 : 500; ///这个时间是根据每帧的数据量来进行调测的 if (is_remove_morr_) { time_out = 2000; } - if (color_mode_) - { - time_out += 400; - } + // if (color_mode_) + // { + // time_out += 400; + // } uint32_t frame_num = 0; uint32_t frame_cnt = 0; video->HtCamGetFrameCnt(frame_cnt); - printf("获取设置的帧数:%d\r\n",frame_cnt); - frame_info_.frame_index = frame_cnt + 1; + printf("获取设置的帧数:%d\r\n",frame_cnt); + frame_info_.frame_index = frame_cnt; //这个值别乱改 获取出来8 是指 0 - 8 ,实际采集图像是9 + + // if(resolution_ == 1 && color_mode_ == 0) + { + //frame_info_.frame_index = frame_cnt; //这个地方很可能是FPGA 的bug 所以暂时先这么处理一下 + //printf("特殊处理200dpi 灰度模式 采集流程\r\n"); + } + + // video->HtCamSetVsnpTime(ti); // printf("设置 vsnp:%d\r\n",ti); //ti++; @@ -413,6 +422,8 @@ void MultiFrameCapture::snaprun() // ti++; StopWatch sw; + + sw.reset(); for (size_t i = 1; i <= frame_info_.frame_index ; i++) { @@ -426,11 +437,17 @@ void MultiFrameCapture::snaprun() { video->HtCamGetFrameNum(frame_num); int ind = i; //已采集了的帧数 - int val = frame_num - ind; //剩余还未采集的帧数 + int val = frame_num - 1 - ind; //剩余还未采集的帧数 + printf("val :%d frame_num:%d i:%d\r\n",val,frame_num,i); - while (val > 0) + int j = 0; + //if(resolution_ == 1 && color_mode_ == 0) + { + //j = 1; //这个地方很可能是FPGA 的bug 所以暂时先这么处理一下 + //printf("特殊处理200dpi 灰度模式 采集流程 jjj r\n"); + } + while (val > j) { - //frame_info_.last_frame = val == 1 ? true : false; frame_info_.frame_index = frame_num; ind++; diff --git a/zynq_7010_code/Scanner.cpp b/zynq_7010_code/Scanner.cpp index 5f06176..82605cc 100644 --- a/zynq_7010_code/Scanner.cpp +++ b/zynq_7010_code/Scanner.cpp @@ -286,7 +286,7 @@ void Scanner::runScan() break; } - printf("frame_time_:%d\r\n",frame_time_); + printf("一张纸所需要的采集时间:%dms\r\n",frame_time_); if (sensor->waitPaperOut(frame_time_)) { if (!m_isDoublePaper) @@ -297,6 +297,9 @@ void Scanner::runScan() m_scaninfo.JamOutNum++; printf("paper 卡纸了。。。。。\n"); } + else + error_code = (int)HG_ScannerStatus::DETECT_DOUBLE_FEED; + printf("error_code:%d\r\n",error_code); capturer->waitsnapdone(error_code);//等待采集完成 isScaning = false; break; @@ -306,13 +309,13 @@ void Scanner::runScan() capturer->stopsnap(b_autosize); error_code = m_isDoublePaper ? (int)HG_ScannerStatus::DETECT_DOUBLE_FEED : m_jamPaper ? (int)HG_ScannerStatus::PAPER_JAM :0; - capturer->waitsnapdone(error_code);//等待采集完成 - - m_DstScannum--; - m_scaninfo.RollerNum++; - m_scaninfo.TotalScanned++; + { + m_DstScannum--; + m_scaninfo.RollerNum++; + m_scaninfo.TotalScanned++; + } if (m_DstScannum == 0) { put(S_EVT_STOP_SCAN); @@ -321,8 +324,24 @@ void Scanner::runScan() } sw.reset(); - while (meminfo->GetMemoryUsed() > 90.0f||(m_config.params.dpi ==0x03 && capturer->getimageremain()>1)) //内存占用高于75% 其实我觉得开发人员应该自己控制好这个内存大小,让他绝对不可能超过这个内存大小 + ////必须控制队列帧数。 + while ( m_config.params.dpi == 0x01 && image_num_>=15) { + printf("200DPI 图像队列过多,正在等待图像取走:%d\r\n",image_num_); + this_thread::sleep_for(std::chrono::milliseconds(300)); + } + while ( m_config.params.dpi == 0x02 && image_num_ >= 8) + { + printf("300DPI 图像队列过多,正在等待图像取走:%d\r\n",image_num_); + this_thread::sleep_for(std::chrono::milliseconds(300)); + } + while ( m_config.params.dpi == 0x03 && image_num_ >= 2) + { + printf("600DPI 图像队列过多,正在等待图像取走:%d\r\n",image_num_); + this_thread::sleep_for(std::chrono::milliseconds(300)); + } + while (meminfo->GetMemoryUsed() > 90.0f) //内存占用高于75% 其实我觉得开发人员应该自己控制好这个内存大小,让他绝对不可能超过这个内存大小 + { if (sw.elapsed_s() < 50.0) std::this_thread::yield(); else @@ -331,12 +350,7 @@ void Scanner::runScan() isScaning = false; break; } - } - - printf("一张纸完成时间:%f\r\n",sw1.elapsed_ms()); - if( m_config.params.dpi == 3) - this_thread::sleep_for(std::chrono::milliseconds(3000)); - + } } isScaning = false; m_DstScannum = 0; @@ -345,13 +359,10 @@ void Scanner::runScan() capturer->setScanFlag(false); capturer->stopsnap(b_autosize); - int t_delay = 500;//b_autosize ?350 : 200; - //int t_delay = m_config.params.dpi == 0x02 ? 150 : (m_config.params.dpi == 0x03 ? 350 : 100); - + int t_delay = 500; this_thread::sleep_for(std::chrono::milliseconds(t_delay)); //走纸多转一会儿 确保扫描传感器过了之后 纸能出完 LOG("\n--------------------------scan done --------------------------------\n"); - } void Scanner::CreatCorrectData(int correctmode) diff --git a/zynq_7010_code/Scanner.h b/zynq_7010_code/Scanner.h index 5ceb771..29bd0f0 100644 --- a/zynq_7010_code/Scanner.h +++ b/zynq_7010_code/Scanner.h @@ -61,7 +61,8 @@ public: inline void ResetJamIn() { m_jamIn = false; } inline bool IsScanning() { return isScaning; } inline void close_v4l2() { capturer->close(); } - + inline void list_image_num(int num) {image_num_ = num;} + int image_num_ = 0; CaptureParams GetCaptureParams() { CaptureParams param; diff --git a/zynq_7010_code/UsbScanner.cpp b/zynq_7010_code/UsbScanner.cpp index 11aae0d..abf26e1 100644 --- a/zynq_7010_code/UsbScanner.cpp +++ b/zynq_7010_code/UsbScanner.cpp @@ -261,9 +261,9 @@ HG_JpegCompressInfo UsbScanner::GetImage() HG_JpegCompressInfo ret = {0}; if (m_images.Size() > 0 && !m_images.IsShutDown()) { + m_hgScanner->list_image_num(m_images.Size()); ret = m_images.Take(); imageremain--; - // LOG("aquired image index %d \n",++aquiredimgindex); } return ret; } @@ -299,8 +299,7 @@ bool UsbScanner::GetImagequeueEmpty() if (m_images.Size() != 0) { printf("队列剩余图像帧数:%d\r\n",m_images.Size()); - } - + } return m_images.Size() == 0; } diff --git a/zynq_7010_code/UsbScanner.h b/zynq_7010_code/UsbScanner.h index a76313a..2486613 100644 --- a/zynq_7010_code/UsbScanner.h +++ b/zynq_7010_code/UsbScanner.h @@ -43,6 +43,7 @@ public: virtual void close_v4l2()override; + std::string GetSysInfo(); int read_bulk(void *pdata, int length,int time = 1000); int write_bulk(void *pdata, int length); diff --git a/zynq_7010_code/ZouZhiMotor.cpp b/zynq_7010_code/ZouZhiMotor.cpp index d5e4948..495f19d 100644 --- a/zynq_7010_code/ZouZhiMotor.cpp +++ b/zynq_7010_code/ZouZhiMotor.cpp @@ -32,16 +32,16 @@ void ZouZhiMotor::speedRecover() void ZouZhiMotor::speedConfig() { - LOG("ZouZhiMotor speed=%d \n dpi=%d \n colormode=%d \n finalPeriod=%d \n Fmin=%d \n a=%.2f \n offset=%.2f \n stepnum=%.2f \n finalDelay=%.2f \n ", - m_zouparamex.speed, - m_zouparamex.dpi, - m_zouparamex.colormode, - m_zouparamex.mt_param.finalPeriod, - m_zouparamex.mt_param.Fmin, - m_zouparamex.mt_param.a, - m_zouparamex.mt_param.offset, - m_zouparamex.mt_param.stepnum, - m_zouparamex.mt_param.finalDelay); + // printf("ZouZhiMotor speed=%d \n dpi=%d \n colormode=%d \n finalPeriod=%d \n Fmin=%d \n a=%.2f \n offset=%.2f \n stepnum=%.2f \n finalDelay=%.2f \n ", + // m_zouparamex.speed, + // m_zouparamex.dpi, + // m_zouparamex.colormode, + // m_zouparamex.mt_param.finalPeriod, + // m_zouparamex.mt_param.Fmin, + // m_zouparamex.mt_param.a, + // m_zouparamex.mt_param.offset, + // m_zouparamex.mt_param.stepnum, + // m_zouparamex.mt_param.finalDelay); delays.clear(); diff --git a/zynq_7010_code/main.cpp b/zynq_7010_code/main.cpp index 93bfdd4..a9ecdd9 100644 --- a/zynq_7010_code/main.cpp +++ b/zynq_7010_code/main.cpp @@ -315,10 +315,8 @@ int main(int argc, char *argv[]) case USBCommand::GET_IMAGE: { HG_JpegCompressInfo info = m_scanner->GetImage(); - //printf("USB error_code:%d\r\n",info.error_code); if (info.pJpegData != nullptr && info.DataLength != 0 || info.error_code) { - int tt = m_scanner->write_bulk((void *)&info, sizeof(int) * 8); int index = 0; int total = info.DataLength;