|
|
@ -1,11 +1,11 @@ |
|
|
|
package a8k.base_hardware; |
|
|
|
package a8k.canbus; |
|
|
|
|
|
|
|
import a8k.a8k_can_protocol.*; |
|
|
|
import a8k.a8k_can_protocol.MId; |
|
|
|
import a8k.canbus.protocol.*; |
|
|
|
import a8k.canbus.protocol.MId; |
|
|
|
import a8k.appbean.HardwareException; |
|
|
|
import a8k.appbean.cfg.Pos2d; |
|
|
|
import a8k.appbean.appevent.A8kHardwareReport; |
|
|
|
import a8k.service.AppEventBusService; |
|
|
|
import a8k.app_eventbus.appevent.A8kHardwareReport; |
|
|
|
import a8k.app_eventbus.AppEventBusService; |
|
|
|
import a8k.utils.ByteArray; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import org.java_websocket.client.WebSocketClient; |
|
|
@ -300,14 +300,29 @@ public class A8kCanBusService { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_move_by.toInt(), dpos); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveByBlock(MId id, int dpos, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
stepMotorEasyMoveBy(id, dpos); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveTo(MId id, int pos) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_move_to.toInt(), pos); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveToBlock(MId id, int pos, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
stepMotorEasyMoveTo(id, pos); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveToZero(MId id) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_move_to_zero.toInt()); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveToZeroBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
stepMotorEasyMoveToZero(id); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasySetCurrentPos(MId id, int pos) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_set_current_pos.toInt(), pos); |
|
|
|
} |
|
|
@ -316,6 +331,17 @@ public class A8kCanBusService { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_move_to_io.toInt(), io); |
|
|
|
} |
|
|
|
|
|
|
|
// step_motor_easy_move_to_zero_point_quick |
|
|
|
|
|
|
|
public void stepMotorEasyMoveToZeroPointQuick(MId id) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_move_to_zero_point_quick.toInt()); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveToZeroPointQuickBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
stepMotorEasyMoveToZeroPointQuick(id); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorStop(MId id) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_stop.toInt()); |
|
|
|
} |
|
|
@ -333,10 +359,19 @@ public class A8kCanBusService { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_move_to_end_point.toInt()); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyMoveToEndPointBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
stepMotorEasyMoveToEndPoint(id); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyReciprocatingMotion(MId id, int startpos, int endpos, int times) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.step_motor_easy_reciprocating_motion.toInt(), startpos, endpos, times); |
|
|
|
} |
|
|
|
|
|
|
|
public void stepMotorEasyReciprocatingMotionBlock(MId id, int startpos, int endpos, int times, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
stepMotorEasyReciprocatingMotion(id, startpos, endpos, times); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
// |
|
|
|
// MINI_SERVO |
|
|
|
// |
|
|
@ -350,6 +385,7 @@ public class A8kCanBusService { |
|
|
|
return packet.getContentI32(0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoActiveCfg(MId id) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.mini_servo_active_cfg.toInt()); |
|
|
|
} |
|
|
@ -371,14 +407,29 @@ public class A8kCanBusService { |
|
|
|
callcmd(id.toInt(), CmdId.mini_servo_move_to.toInt(), pos); |
|
|
|
} |
|
|
|
|
|
|
|
public void miniServoMoveToBlock(MId id, int pos, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
miniServoMoveTo(id, pos); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void miniServoRotate(MId id, int direction) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.mini_servo_rotate.toInt(), direction); |
|
|
|
} |
|
|
|
|
|
|
|
public void miniServoRotateBlock(MId id, int direction, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
miniServoRotate(id, direction); |
|
|
|
waitForMod(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void miniServoRotateWithTorque(MId id, int torque) throws HardwareException { |
|
|
|
callcmd(id.toInt(), CmdId.mini_servo_rotate_with_torque.toInt(), torque); |
|
|
|
} |
|
|
|
|
|
|
|
public void miniServoRotateWithTorqueBlock(MId id, int torque, Integer actionOvertime) throws HardwareException, InterruptedException { |
|
|
|
miniServoRotateWithTorque(id, torque); |
|
|
|
miniServoWaitIsNotMove(id, actionOvertime); |
|
|
|
} |
|
|
|
|
|
|
|
public void miniServoWaitIsNotMove(MId id, int acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
long startedAt = System.currentTimeMillis(); |
|
|
|
do { |
|
|
@ -414,27 +465,6 @@ public class A8kCanBusService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void waitForAction(MId mid, int cmdId, Integer acitionOvertime) throws InterruptedException, HardwareException { |
|
|
|
long startedAt = System.currentTimeMillis(); |
|
|
|
do { |
|
|
|
try { |
|
|
|
var status = getModuleStatus(mid); |
|
|
|
if (status == ModuleStatus.IDLE) { |
|
|
|
break; |
|
|
|
} else if (status == ModuleStatus.ERROR) { |
|
|
|
throw new HardwareException(mid, moduleGetError(mid)); |
|
|
|
} |
|
|
|
} catch (HardwareException ignored) { |
|
|
|
} |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
if (now - startedAt > acitionOvertime) { |
|
|
|
throw new HardwareException(mid, A8kEcode.Overtime); |
|
|
|
} |
|
|
|
|
|
|
|
Thread.sleep(100); |
|
|
|
} while (true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void waitForMods(MId[] mids, Integer acitionOvertime) throws InterruptedException, HardwareException { |
|
|
|
for (MId mid : mids) { |
|
|
@ -444,7 +474,7 @@ public class A8kCanBusService { |
|
|
|
|
|
|
|
public void waitForMod(MId mid, Integer acitionOvertime) throws InterruptedException, HardwareException { |
|
|
|
long startedAt = System.currentTimeMillis(); |
|
|
|
// Thread.sleep(300); |
|
|
|
// Thread.sleep(300); |
|
|
|
// CmdId action = lastCmdMap.get(mid); |
|
|
|
CmdId action = lastCmdMapGet(mid); |
|
|
|
do { |