Browse Source

v1016 | 光学模块 增加扫描时,电机参数配置

master
zhaohe 4 months ago
parent
commit
de5b147a81
  1. 2
      a8000_protocol
  2. 113
      usrc/subboards/subboard90_optical_module/optical_module_v2.cpp
  3. 24
      usrc/subboards/subboard90_optical_module/optical_module_v2.hpp
  4. 2
      usrc/version.h

2
a8000_protocol

@ -1 +1 @@
Subproject commit 8f879b4d76b81dc8bb3c7179a9aa3b126d70164b
Subproject commit 07fcb845c2a81ec202179261c33502a04f0d9549

113
usrc/subboards/subboard90_optical_module/optical_module_v2.cpp

@ -69,7 +69,18 @@ void OpticalModuleV2::initialize(int32_t moduleid, hardware_config_t* hardwarecf
m_reg.scan_step_interval = 1;
m_reg.scan_pointnum = 1200;
m_default_reg = m_reg;
m_reg.scan_vstart = 400;
m_reg.scan_vstop = 400;
m_reg.scan_v1 = 550;
m_reg.scan_a1 = 300;
m_reg.scan_d1 = 300;
m_reg.scan_amax = 1000;
m_reg.scan_dmax = 1000;
m_reg.scan_vdefault = 1200;
m_reg.scan_tzerowait = 0;
m_default_reg = m_reg;
ZLOGI(TAG, "-----------------module info--------------");
ZLOGI(TAG, "f_detector max gain : %f", f_detector_raw_gain_to_gain(255));
@ -145,6 +156,16 @@ int32_t OpticalModuleV2::module_xxx_reg(int32_t param_id, bool read, int32_t& va
PROCESS_REG(kreg_a8k_opt_t_reverse_scan_pos_offset, REG_GET(m_reg.t_reverse_scan_pos_offset), REG_SET(m_reg.t_reverse_scan_pos_offset));
PROCESS_REG(kreg_a8k_opt_f_reverse_scan_pos_offset, REG_GET(m_reg.f_reverse_scan_pos_offset), REG_SET(m_reg.f_reverse_scan_pos_offset));
PROCESS_REG(kreg_a8k_opt_scan_vdefault, REG_GET(m_reg.scan_vdefault), REG_SET(m_reg.scan_vdefault));
PROCESS_REG(kreg_a8k_opt_scan_vstart, REG_GET(m_reg.scan_vstart), REG_SET(m_reg.scan_vstart));
PROCESS_REG(kreg_a8k_opt_scan_a1, REG_GET(m_reg.scan_a1), REG_SET(m_reg.scan_a1));
PROCESS_REG(kreg_a8k_opt_scan_amax, REG_GET(m_reg.scan_amax), REG_SET(m_reg.scan_amax));
PROCESS_REG(kreg_a8k_opt_scan_v1, REG_GET(m_reg.scan_v1), REG_SET(m_reg.scan_v1));
PROCESS_REG(kreg_a8k_opt_scan_dmax, REG_GET(m_reg.scan_dmax), REG_SET(m_reg.scan_dmax));
PROCESS_REG(kreg_a8k_opt_scan_d1, REG_GET(m_reg.scan_d1), REG_SET(m_reg.scan_d1));
PROCESS_REG(kreg_a8k_opt_scan_vstop, REG_GET(m_reg.scan_vstop), REG_SET(m_reg.scan_vstop));
PROCESS_REG(kreg_a8k_opt_scan_tzerowait, REG_GET(m_reg.scan_tzerowait), REG_SET(m_reg.scan_tzerowait));
PROCESS_REG(kreg_a8k_opt_scan_step_interval, REG_GET(m_reg.scan_step_interval), REG_SET(m_reg.scan_step_interval));
PROCESS_REG(kreg_a8k_opt_scan_pointnum, REG_GET(m_reg.scan_pointnum), REG_SET(m_reg.scan_pointnum));
default:
@ -159,28 +180,16 @@ int32_t OpticalModuleV2::module_stop() {
return 0;
}
// virtual int32_t a8000_optical_start_capture();
// virtual int32_t a8000_optical_read_raw(int32_t index, uint8_t* data, int32_t* len);
#define MAX_SCAN_POINT_NUM 1200
// bittly.variableSet("scan_start_pos","2860"); //F
// bittly.variableSet("scan_step_interval","1");
// bittly.variableSet("scan_pointnum","1200");
// bittly.variableSet("scan_direction","-1");
// bittly.variableSet("scan_start_pos","4005"); //T
// bittly.variableSet("scan_step_interval","1");
// bittly.variableSet("scan_pointnum","1200");
// bittly.variableSet("scan_direction","-1");
int32_t OpticalModuleV2::start_t_optical_scan(int32_t scanDirection, int32_t lasterGain, int32_t scanGain) {
m_thread.stop();
m_thread.start([this, scanDirection, lasterGain, scanGain]() {
ZLOGI(TAG, "--------------start_t_optical_scan-----------");
int32_t intervalStep = 0;
int32_t scanStartPos = 0;
osDelay(50);
osDelay(10);
if (scanDirection >= 0) {
intervalStep = -m_reg.scan_step_interval;
@ -189,7 +198,7 @@ int32_t OpticalModuleV2::start_t_optical_scan(int32_t scanDirection, int32_t las
intervalStep = m_reg.scan_step_interval;
scanStartPos = m_reg.t_reverse_scan_pos_offset;
}
active_motor_default_cfg();
move_to_block(scanStartPos);
// 设置激光亮度增益
@ -206,7 +215,8 @@ int32_t OpticalModuleV2::start_t_optical_scan(int32_t scanDirection, int32_t las
int32_t adcval = 0;
adc_capture_point_num = 0;
motor_prepare();
int32_t startTicket = HAL_GetTick();
active_motor_opt_cfg();
while (true) {
// 移动到第一个点
move_to_block(scanStartPos + step);
@ -226,13 +236,18 @@ int32_t OpticalModuleV2::start_t_optical_scan(int32_t scanDirection, int32_t las
break;
}
}
// end of scan
m_t_laster_enable_io.setState(false);
motor_release();
_close_t_amp_n5v();
recover_motor_default_cfg();
if (scanDirection < 0) {
reverse_capture_data();
}
ZLOGI(TAG, "use time: %f s", (HAL_GetTick() - startTicket) / 1000.0);
ZLOGI(TAG, "--------------end_t_optical_scan-----------");
});
return 0;
@ -242,7 +257,7 @@ int32_t OpticalModuleV2::start_f_optical_scan(int32_t scanDirection, int32_t las
m_thread.stop();
m_thread.start([this, scanDirection, lasterGain, scanGain]() {
ZLOGI(TAG, "--------------start_f_optical_scan-----------");
osDelay(50);
osDelay(10);
int32_t intervalStep = 0;
int32_t scanStartPos = 0;
@ -254,7 +269,7 @@ int32_t OpticalModuleV2::start_f_optical_scan(int32_t scanDirection, int32_t las
intervalStep = m_reg.scan_step_interval;
scanStartPos = m_reg.f_reverse_scan_pos_offset;
}
active_motor_default_cfg();
move_to_block(scanStartPos);
// 设置激光亮度增益
@ -274,8 +289,8 @@ int32_t OpticalModuleV2::start_f_optical_scan(int32_t scanDirection, int32_t las
int pointnum = 0;
int32_t adcval = 0;
adc_capture_point_num = 0;
motor_prepare();
active_motor_opt_cfg();
int32_t startTicket = HAL_GetTick();
while (true) {
// 移动到第一个点
move_to_block(scanStartPos + step);
@ -293,13 +308,19 @@ int32_t OpticalModuleV2::start_f_optical_scan(int32_t scanDirection, int32_t las
if (m_thread.getExitFlag()) {
break;
}
osDelay(1);
// osDelay(1);
}
motor_release();
// end of scan
select_f_channel(0);
a8000_optical_close_laser(kf_optical);
recover_motor_default_cfg();
if (scanDirection < 0) {
reverse_capture_data();
}
ZLOGI(TAG, "use time: %f s", (HAL_GetTick() - startTicket) / 1000.0);
ZLOGI(TAG, "--------------end_f_optical_scan-----------");
});
// adc_capture_buf[0]
@ -321,8 +342,8 @@ int32_t OpticalModuleV2::start_barcode_scan(int32_t lasterGain, int32_t scanGain
ZLOGI(TAG, "intervalstep : %d", intervalstep);
ZLOGI(TAG, "scanNum : %d", scanNum);
osDelay(50);
osDelay(10);
active_motor_default_cfg();
move_to_block(startpos);
// 设置激光亮度增益
@ -344,7 +365,8 @@ int32_t OpticalModuleV2::start_barcode_scan(int32_t lasterGain, int32_t scanGain
adc_capture_point_num = 0;
int32_t scanDirection = intervalstep < 0 ? 1 : 0; // 与电机运行相反的方向为正
motor_prepare();
active_motor_opt_cfg();
int32_t startTicket = HAL_GetTick();
while (true) {
// 移动到第一个点
move_to_block(startpos + step);
@ -362,13 +384,19 @@ int32_t OpticalModuleV2::start_barcode_scan(int32_t lasterGain, int32_t scanGain
if (m_thread.getExitFlag()) {
break;
}
osDelay(1);
// osDelay(1);
}
motor_release();
// end of scan
select_f_channel(0);
a8000_optical_close_laser(kf_optical);
recover_motor_default_cfg();
if (scanDirection < 0) {
reverse_capture_data();
}
ZLOGI(TAG, "use time: %f s", (HAL_GetTick() - startTicket) / 1000.0);
ZLOGI(TAG, "--------------end_barcode_scan-----------");
});
// adc_capture_buf[0]
@ -579,27 +607,26 @@ int32_t OpticalModuleV2::_close_t_amp_n5v() {
return 0;
}
int32_t OpticalModuleV2::motor_prepare() {
auto _motor = motor->getMotor();
// _motor->setNoAccLimit(true);
return 0;
}
int32_t OpticalModuleV2::motor_release() {
void OpticalModuleV2::active_motor_default_cfg() { motor->step_motor_active_cfg(); }
void OpticalModuleV2::recover_motor_default_cfg() { active_motor_default_cfg(); }
void OpticalModuleV2::active_motor_opt_cfg() {
auto _motor = motor->getMotor();
// _motor->setNoAccLimit(false);
return 0;
_motor->set_vstart(m_reg.scan_vstart);
_motor->set_vstop(m_reg.scan_vstop);
_motor->set_a1(m_reg.scan_a1);
_motor->set_d1(m_reg.scan_d1);
_motor->set_v1(m_reg.scan_v1);
_motor->set_amax(m_reg.scan_amax);
_motor->set_dmax(m_reg.scan_dmax);
_motor->set_tzerowait(m_reg.scan_tzerowait);
}
int32_t OpticalModuleV2::move_to_block(int32_t pos) {
auto _motor = motor->getMotor();
_motor->setAcceleration(3600);
_motor->setDeceleration(3600);
_motor->moveTo(pos, motor->getCfg()->motor_default_velocity);
while (!_motor->isReachTarget() && !m_thread.getExitFlag()) {
// zos_early_delayus(100);
// osDelay(1);
_motor->moveTo(pos, m_reg.scan_vdefault);
while (!_motor->isReachTarget()) {
}
_motor->stop();
return 0;
}

24
usrc/subboards/subboard90_optical_module/optical_module_v2.hpp

@ -11,7 +11,7 @@
namespace iflytop {
using namespace std;
#define OPTICAL_MODULE_MAX_SCAN_POINT_NUM 2000
#define OPTICAL_MODULE_MAX_SCAN_POINT_NUM 2000
class OpticalModuleV2 : public ZIModule {
ENABLE_MODULE(OpticalModuleV2, ka8000_optical_module, PC_VERSION);
@ -54,6 +54,17 @@ class OpticalModuleV2 : public ZIModule {
int32_t f_reverse_scan_pos_offset;
int32_t scan_step_interval;
int32_t scan_pointnum;
int32_t scan_vdefault;
int32_t scan_vstart;
int32_t scan_a1;
int32_t scan_amax;
int32_t scan_v1;
int32_t scan_dmax;
int32_t scan_d1;
int32_t scan_vstop;
int32_t scan_tzerowait;
} reg_table_t;
private:
@ -127,7 +138,6 @@ class OpticalModuleV2 : public ZIModule {
virtual int32_t a8k_opt_v2_f_start_scan(int32_t scanDirection, int32_t lasterGain, int32_t scanGain);
virtual int32_t a8k_opt_v2_barcode_start_scan(int32_t lasterGain, int32_t scanGain, int32_t startpos, int32_t intervalstep, int32_t scanNum);
virtual int32_t a8000_optical_read_raw(int32_t index, uint8_t* data, int32_t* len);
virtual int32_t a8k_opt_v2_t_open_laster(int32_t lasterGain, int32_t scanGain);
@ -150,7 +160,6 @@ class OpticalModuleV2 : public ZIModule {
int32_t dumpresult();
int32_t move_to_block(int32_t pos);
virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t& val) override;
void opt_module_power_ctrl(bool on);
@ -159,9 +168,6 @@ class OpticalModuleV2 : public ZIModule {
int32_t _open_t_amp_n5v();
int32_t _close_t_amp_n5v();
int32_t motor_prepare();
int32_t motor_release();
int32_t f_detector_gain_to_raw_gain(float gain);
int32_t t_detector_gain_to_raw_gain(float gain);
@ -172,6 +178,12 @@ class OpticalModuleV2 : public ZIModule {
int32_t raw_get_sector_num(int32_t* val);
private:
void active_motor_default_cfg();
void recover_motor_default_cfg();
void active_motor_opt_cfg();
int32_t move_to_block(int32_t pos);
private:
int32_t a8000_optical_open_laser(int32_t type);
int32_t a8000_optical_close_laser(int32_t type);
int32_t a8000_optical_set_laster_gain(int32_t type, int32_t gain);

2
usrc/version.h

@ -1,2 +1,2 @@
#pragma once
#define PC_VERSION 1015
#define PC_VERSION 1016
Loading…
Cancel
Save