9 changed files with 164 additions and 46 deletions
-
32src/main/java/a8k/app_eventbus/AppEventBusService.java
-
6src/main/java/a8k/app_eventbus/appevent/A8kCanBusOnConnectEvent.java
-
26src/main/java/a8k/canbus/A8kCanBusService.java
-
76src/main/java/a8k/canbus/A8kModParamInitializer.java
-
7src/main/java/a8k/canbus/custom_param_mgr/A8kModCustomParam.java
-
32src/main/java/a8k/canbus/custom_param_mgr/A8kModCustomParamMgr.java
-
4src/main/java/a8k/canbus/custom_param_mgr/ModCustomParamId.java
-
3src/main/java/a8k/canbus/protocol/RegIndex.java
@ -0,0 +1,6 @@ |
|||
package a8k.app_eventbus.appevent; |
|||
|
|||
public class A8kCanBusOnConnectEvent extends AppEvent { |
|||
public A8kCanBusOnConnectEvent() { |
|||
} |
|||
} |
@ -1,16 +1,90 @@ |
|||
package a8k.canbus; |
|||
|
|||
import a8k.app_eventbus.AppEventBusService; |
|||
import a8k.app_eventbus.appevent.A8kCanBusOnConnectEvent; |
|||
import a8k.app_eventbus.appevent.AppEvent; |
|||
import a8k.appbean.AppEventListener; |
|||
import a8k.appbean.HardwareException; |
|||
import a8k.canbus.custom_param_mgr.ModCustomParamId; |
|||
import a8k.canbus.custom_param_mgr.A8kModCustomParamMgr; |
|||
import a8k.canbus.protocol.MId; |
|||
import a8k.canbus.protocol.RegIndex; |
|||
import jakarta.annotation.PostConstruct; |
|||
import jakarta.annotation.Resource; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Component |
|||
public class A8kModParamInitializer { |
|||
public class A8kModParamInitializer implements AppEventListener { |
|||
static Logger logger = LoggerFactory.getLogger(A8kModParamInitializer.class); |
|||
|
|||
@Resource |
|||
AppEventBusService eventBus; |
|||
|
|||
@Resource |
|||
A8kCanBusService canBus; |
|||
|
|||
@Resource |
|||
A8kModCustomParamMgr customParamMgr; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
logger.info("A8kModInitializer init"); |
|||
eventBus.regListener(this); |
|||
} |
|||
|
|||
public void initA8kCustcomParams() { |
|||
customParamMgr.setCustomParam(MId.FeedingModXM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); |
|||
customParamMgr.setCustomParam(MId.ShakeModGripperZM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); |
|||
customParamMgr.setCustomParam(MId.ShakeModClampingM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); |
|||
} |
|||
|
|||
public void initA8kModParams() throws HardwareException { |
|||
/* |
|||
* 设置位置偏差容忍度 |
|||
* 1.如果电机配置有编码器器,则每次调用moveBy,moveTo都会进行位置检查 |
|||
* 2.如果电机没有配备编码,则每次调用moveQuickToZeroPoint,都会进行一次位置检查 |
|||
*/ |
|||
canBus.moduleSetReg(MId.FeedingModXM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.ShakeModClampingM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.ShakeModGripperZM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.ShakeModShakeM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.OptModPullM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.OptModScannerM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
canBus.moduleSetReg(MId.IncubatorRotateCtrlM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); |
|||
|
|||
canBus.moduleSetReg(MId.FeedingModXM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.ShakeModClampingM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.ShakeModGripperZM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.ShakeModShakeM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.OptModPullM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.OptModScannerM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
canBus.moduleSetReg(MId.IncubatorRotateCtrlM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); |
|||
} |
|||
|
|||
public void forceInitA8kModParams() { |
|||
try { |
|||
logger.info("forceInitA8kModParams"); |
|||
initA8kModParams(); |
|||
} catch (HardwareException e) { |
|||
logger.error("init hardware param fail......", e); |
|||
//TODO:校验这里的逻辑 |
|||
canBus.forceShutdown(); |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void onAppEvent(AppEvent event) { |
|||
if (event instanceof A8kCanBusOnConnectEvent) { |
|||
forceInitA8kModParams(); |
|||
} |
|||
} |
|||
} |
@ -1,7 +1,10 @@ |
|||
package a8k.canbus.custom_param_mgr; |
|||
|
|||
import a8k.canbus.protocol.MId; |
|||
|
|||
public class A8kModCustomParam { |
|||
public A8kModCustomParamId id; |
|||
public Integer value; |
|||
MId mid; |
|||
public ModCustomParamId id; |
|||
public Integer value; |
|||
|
|||
} |
@ -1,25 +1,35 @@ |
|||
package a8k.canbus.custom_param_mgr; |
|||
|
|||
import a8k.canbus.protocol.MId; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
|
|||
@Component |
|||
public class A8kModCustomParamMgr { |
|||
|
|||
Map<A8kModCustomParamId, A8kModCustomParam> customParamMap; |
|||
Set<A8kModCustomParam> customParamSet; |
|||
|
|||
public Integer getCustomParam(A8kModCustomParamId id) { |
|||
var vaule = customParamMap.get(id); |
|||
if (vaule != null) { |
|||
return vaule.value; |
|||
} else { |
|||
return id.defaultVal; |
|||
public Integer getCustomParam(MId mid, ModCustomParamId id) { |
|||
for (A8kModCustomParam param : customParamSet) { |
|||
if (param.mid == mid && param.id == id) { |
|||
return param.value; |
|||
} |
|||
} |
|||
|
|||
return id.defaultVal; |
|||
} |
|||
|
|||
public void setCustomParam(A8kModCustomParam param) { |
|||
customParamMap.put(param.id, param); |
|||
public void setCustomParam(MId mid, ModCustomParamId id, Integer val) { |
|||
for (A8kModCustomParam param : customParamSet) { |
|||
if (param.mid == mid && param.id == id) { |
|||
param.value = val; |
|||
return; |
|||
} |
|||
} |
|||
A8kModCustomParam param = new A8kModCustomParam(); |
|||
param.mid = mid; |
|||
param.id = id; |
|||
param.value = val; |
|||
customParamSet.add(param); |
|||
} |
|||
} |
@ -1,13 +1,13 @@ |
|||
package a8k.canbus.custom_param_mgr; |
|||
|
|||
public enum A8kModCustomParamId { |
|||
public enum ModCustomParamId { |
|||
|
|||
MOTOR_STANDY_POS_COMPENSATE("电机待机位置零点补偿"),//待机位置 = 零点- 零点补偿 |
|||
; |
|||
public final String desc; |
|||
public final Integer defaultVal; |
|||
|
|||
A8kModCustomParamId(String desc) { |
|||
ModCustomParamId(String desc) { |
|||
this.desc = desc; |
|||
this.defaultVal = 0; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue