第一版速度可配置

This commit is contained in:
modehua 2024-02-06 01:28:31 -08:00
parent b99cd8a633
commit df0805234f
7 changed files with 80 additions and 57 deletions

View File

@ -8,7 +8,7 @@ CuoZhiMotor::CuoZhiMotor()
m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, 4, 1, 1);
speedConfig();
mspCuozhiFeeding = {.finalPeriod = 1427500, .Fmin = 2027500, .stepnum = 30, .a = 100, .offset = 4, .finalDelay = 3000};
if (smbtype == SMBType::MB_DRV_TMC216)
//if (smbtype == SMBType::MB_DRV_TMC216)
{
mspCuozhiFeeding.finalPeriod /= 4;
mspCuozhiFeeding.Fmin /= 4;
@ -59,7 +59,7 @@ void CuoZhiMotor::reset()
mspCuozhiBackward.a,
mspCuozhiBackward.offset,
mspCuozhiBackward.finalDelay);
//printf("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
@ -96,10 +96,9 @@ void CuoZhiMotor::feeding()
Motor::start(delays_feeding, mspCuozhiFeeding);
}
void CuoZhiMotor::speedChange(int speed, int dpi, int colormode) // speed should be in range [0,5] (by ply,at 2019.5.23)
void CuoZhiMotor::speedChange(MotorSpeedParamEx paramex)
{
auto t_smbtype = MotorConfig::MTBDType::MT_TMC;//SMBType::MB_DRV_TMC216;//smbtype == SMBType::MB_DRV_8825 ? MotorConfig::MTBDType::MT_DRV : MotorConfig::MTBDType::MT_TMC;
m_cuoparamex = m_mtconfig->GetMotorSpeedParam(false, t_smbtype, speed, colormode, dpi);
m_cuoparamex = paramex;
speedConfig();
}
@ -110,17 +109,6 @@ void CuoZhiMotor::speedRecover()
void CuoZhiMotor::speedConfig()
{
LOG("CuoZhiMotor 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_cuoparamex.speed,
m_cuoparamex.dpi,
m_cuoparamex.colormode,
m_cuoparamex.mt_param.finalPeriod,
m_cuoparamex.mt_param.Fmin,
m_cuoparamex.mt_param.a,
m_cuoparamex.mt_param.offset,
m_cuoparamex.mt_param.stepnum,
m_cuoparamex.mt_param.finalDelay);
delays_forward.clear();
delays_forward = speedup_cfg(m_cuoparamex.mt_param.finalPeriod, m_cuoparamex.mt_param.Fmin, m_cuoparamex.mt_param.stepnum, m_cuoparamex.mt_param.a,
m_cuoparamex.mt_param.offset, m_cuoparamex.mt_param.finalDelay);

View File

@ -24,7 +24,7 @@ public:
void feeding();
void speedChange(int speed, int dpi = 1,int colormode = 1);
void speedChange(MotorSpeedParamEx paramex);
void speedRecover();

View File

@ -11,23 +11,17 @@
#define BTN_NORMAL_POWER 3 //按键正常模式 (退出低功耗)
Scanner::Scanner(ScannerGlue glue)
: motorZouzhi(),
motorCuozhi(),
m_glue(glue),
m_isPulling(false),
m_isDoublePaper(false),
isPaperInit(false),
m_jamPaper(false),
m_jamIn(false),
m_correctting(false),
waitpapertime(200),
m_scansysinfo(nullptr)
: motorZouzhi(),motorCuozhi(),motor_cfg_(),
m_glue(glue),m_isPulling(false),
m_isDoublePaper(false),isPaperInit(false),
m_jamPaper(false),m_jamIn(false),
m_correctting(false),waitpapertime(200),
m_scansysinfo(nullptr),auto_size_(false)
{
frame_time_ = 3000;
m_scaninfo = GetScanInfoFromJson();
capturer.reset(new MultiFrameCapture(m_glue));
capturer->SetParent(this);
capturer->set_image_callback(&have_img_callback);
@ -78,6 +72,7 @@ Scanner::Scanner(ScannerGlue glue)
FsmState::setScanner(this);
threadRunMessageLoop = std::thread(&Scanner::runMessageLoop, this);
Motor::enablePower(true);
UpdateScanInfo();
}
Scanner::~Scanner()
@ -93,25 +88,63 @@ Scanner::~Scanner()
threadRunScan.join();
}
void Scanner::updateSpeedMode()
{
m_scaninfo = GetScanInfoFromJson();
int sp = m_scaninfo.SpeedMode;
if(sp == 0)
sp = 3;
int speed = m_scaninfo.SpeedMode;
printf("JSON文件获取当前速度%d\r\n",speed);
if(speed == 0)
speed = 3;
unsigned int t_dpi = m_config.params.dpi;
if(m_config.params.pageSize == (unsigned int)PaperSize::G400_MAXSIZE || m_config.params.pageSize == (unsigned int)PaperSize::G400_MAXAUTO ) //长文稿采用600dpi模式扫描
t_dpi = 3;
if (m_config.params.slow_moire) //摩尔纹特殊处理
t_dpi = sp = 16;
t_dpi = speed = 16;
motorCuozhi.speedChange(sp, t_dpi,m_config.params.isColor);
motorZouzhi.speedChange(sp, t_dpi,m_config.params.isColor);
Zouzhi_ParamEx_ = motor_cfg_.GetMotorSpeedParam(true,MotorConfig::MTBDType::MT_TMC,speed,m_config.params.isColor,t_dpi);
Cuozhi_ParamEx_ = motor_cfg_.GetMotorSpeedParam(false,MotorConfig::MTBDType::MT_TMC,speed,m_config.params.isColor,t_dpi);
motorCuozhi.speedChange(Cuozhi_ParamEx_);
motorZouzhi.speedChange(Zouzhi_ParamEx_);
}
void Scanner::ConfigScanParam(HG_ScanConfiguration config)
{
m_config = config;
auto_size_ = m_config.params.pageSize==(int)PaperSize::G400_AUTO ||
m_config.params.pageSize==(int)PaperSize::G400_MAXAUTO ||
m_config.params.pageSize==(int)PaperSize::G400_MAXSIZE;
updateSpeedMode();
capturer->UpdateScanParam(m_config);
}
void Scanner::UpdateScanInfo()
{
m_scaninfo = GetScanInfoFromJson();
auto params = motor_cfg_.GetMotorSpeedParams(true,MotorConfig::MTBDType::MT_TMC);
for (int i = 0; i < params.size(); i++)
{
if (params[i].speed == m_scaninfo.SpeedMode)
{
auto fpgaparam = GetFpgaparam(params[i].dpi, params[i].colormode);
fpgaparam.Sp = params[i].sp;
SaveFpgaparam(fpgaparam);
if (params[i].dpi == 3 && params[i].colormode)
{
printf("sp sp sp sp sp sp sp sp sp:%d :%d\r\n",params[i].sp,fpgaparam.Sp);
}
}
// if(params[i].speed == 0x10)
// {
// auto fpgaparam = GetFpgaparam(params[i].dpi, params[i].colormode);
// fpgaparam.Sp = params[i].sp;
// SaveFpgaparam(fpgaparam);
// }
}
updateSpeedMode();
}
void Scanner::have_img_callback(int val)
{
if (val < 0)
@ -126,7 +159,7 @@ void Scanner::startScan()
if (threadRunScan.joinable())
threadRunScan.join();
stop_countdown();
this_thread::sleep_for(std::chrono::milliseconds(200));
updateSpeedMode();
// //开始进行扫描
threadRunScan = std::thread(&Scanner::runScan, this);
@ -452,7 +485,7 @@ void Scanner::reset()
motorCuozhi.reset();
isRested = true;
isPaperInit = false;
LOG("Scanner->motorCuozhi is reseted \n");
printf("Scanner->motorCuozhi is reseted \n");
}
}
void Scanner::paper_pullout()
@ -461,7 +494,8 @@ void Scanner::paper_pullout()
m_isPulling = true;
motorCuozhi.stop();
motorZouzhi.speedChange(1);
MotorSpeedParamEx ParamEx = motor_cfg_.GetMotorSpeedParam(true,MotorConfig::MTBDType::MT_TMC,1,1,1);
motorZouzhi.speedChange(ParamEx);
motorZouzhi.setDirection(1);
motorZouzhi.start();
if (sensor->waitPaperOut(5000))
@ -471,8 +505,3 @@ void Scanner::paper_pullout()
m_isPulling = false;
}
void Scanner::UpdateScanInfo()
{
m_scaninfo = GetScanInfoFromJson();
updateSpeedMode();
}

View File

@ -17,10 +17,11 @@
#include "SysInforTool.h"
#include "MotorConfig.h"
#include "correct_ultis.h"
class ICapturer;
class MemoryInfo;
// class SysInforTool;
static int frame_time_ ;
static int frame_time_ ;
class Scanner
{
std::mutex cb_lock_;
@ -51,7 +52,8 @@ public:
inline bool isFeederLoaded() { return sensor->isPaperStandby(); }
inline void put(ScanEvent evt) { sysEvent.Put(evt); }
inline void ConfigScanParam(HG_ScanConfiguration config) {capturer->UpdateScanParam(m_config = config); }
void ConfigScanParam(HG_ScanConfiguration config) ;
inline void SetDstScanNum(int scannum) { m_DstScannum = scannum; }
inline void SetIsDoublePaper(bool isdoublepaper) { m_isDoublePaper = isdoublepaper; }
@ -91,6 +93,10 @@ private:
private:
ZouZhiMotor motorZouzhi;
CuoZhiMotor motorCuozhi;
MotorConfig motor_cfg_;
MotorSpeedParamEx Zouzhi_ParamEx_;
MotorSpeedParamEx Cuozhi_ParamEx_;
PanelLeds panelLeds;
std::thread threadRunScan;
@ -113,6 +119,7 @@ private:
volatile bool m_correctting;
bool isPaperInit;
bool auto_size_;//匹配原始尺寸类型尺寸
int waitpapertime;
MemoryInfo *meminfo;

View File

@ -4,7 +4,7 @@
ZouZhiMotor::ZouZhiMotor()
: Motor(motorPorts_Zouzhi)
{
auto t_smbtype =MotorConfig::MTBDType::MT_TMC;//SMBType::MB_DRV_TMC216;// smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV;
auto t_smbtype =MotorConfig::MTBDType::MT_TMC;
m_zouparamex = m_mtconfig->GetMotorSpeedParam(true, t_smbtype, 4, 1, 1);
speedConfig();
}
@ -18,10 +18,9 @@ void ZouZhiMotor::start()
Motor::start(delays, m_zouparamex.mt_param);
}
void ZouZhiMotor::speedChange(int speed, int dpi, int colormode) // speed should be in range [0,5] (by ply,at 2019.5.23)
void ZouZhiMotor::speedChange(MotorSpeedParamEx paramex)
{
auto t_smbtype = MotorConfig::MTBDType::MT_TMC;//SMBType::MB_DRV_TMC216;//smbtype == SMBType::MB_DRV_TMC216 ? MotorConfig::MTBDType::MT_TMC : MotorConfig::MTBDType::MT_DRV;
m_zouparamex = m_mtconfig->GetMotorSpeedParam(true, t_smbtype, speed, colormode, dpi);
m_zouparamex = paramex;
speedConfig();
}

View File

@ -6,7 +6,7 @@ public:
ZouZhiMotor();
~ZouZhiMotor();
virtual void start();
void speedChange(int speed, int dpi = 1,int colormode = 1);
void speedChange(MotorSpeedParamEx paramex);
void speedRecover();
private:

View File

@ -62,11 +62,11 @@ typedef struct
typedef void (*image_callback)(int element);
static std::map<int , sp_COLOR_or_GRAY>mapFradme_SP={
{1,{0x08ED1003,0x1ACC1002,CON(G34D,231027)}},//40 ppm
{2,{0x06DB1003,0x14A01002,CON(G3ZY,240102)}},//50 ppm
{3,{0x05591003,0x100E1002,CON(G36D,231027)}},//60 ppm
{4,{0x04421003,0x0CD11002,CON(G37D,231027)}},//70 ppm
{5,{0x036c1003,0x0A421002,CON(G38D,231027)}},//80 ppm
{1,{0x08ED1003,0x1ACC1002,CON(G33Z,240206)}},//30 ppm
{2,{0x06DB1003,0x14A01002,CON(G34Z,240206)}},//40 ppm
{3,{0x05591003,0x100E1002,CON(G35Z,240206)}},//50 ppm
{4,{0x04421003,0x0CD11002,CON(G36Z,240206)}},//60 ppm
{5,{0x036c1003,0x0A421002,CON(G37Z,240206)}},//70 ppm
};
enum class LedStatus