Skip to content

Commit

Permalink
Fix v4.11.0 1 (#2468)
Browse files Browse the repository at this point in the history
* Fix: Semi auto material thickness mode set wrong work origin coordinate

* Fix: Stopping Print the laser or CNC may not turn off due to asynchronous issues

* Fix: Update tryPause logic and resumeGcode without go home modal
  • Loading branch information
IDKHTS authored Mar 6, 2024
1 parent 85f4dca commit 40298d8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/app/ui/widgets/Connection/modals/GoHomeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { MachineToolHeadOptions } from '@snapmaker/luban-platform';
import { WorkflowStatus, MachineToolHeadOptions } from '@snapmaker/luban-platform';
import React, { useCallback, useEffect, useState } from 'react';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';

import { includes } from 'lodash';
import { RootState } from '../../../../flux/index.def';
import { actions as workspaceActions } from '../../../../flux/workspace';
import i18n from '../../../../lib/i18n';
Expand All @@ -24,7 +25,7 @@ const GoHomeModal: React.FC = () => {

const {
isHomed,

workflowStatus,
activeMachine,
} = useSelector((state: RootState) => state.workspace);

Expand All @@ -41,7 +42,7 @@ const GoHomeModal: React.FC = () => {
return;
}

if (!isHomed) {
if (!isHomed && !includes([WorkflowStatus.Running], workflowStatus)) {
setShowModal(true);
} else {
// already homed, which means machine coordinates are ready
Expand Down
7 changes: 6 additions & 1 deletion src/app/ui/widgets/WorkspaceVisualizer/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Visualizer extends React.PureComponent {
e: Number(workPosition.e)
}
};
if (this.pauseStatus.headStatus) {
if (this.pauseStatus.headStatus || this.props.headType !== HEAD_PRINTING) {
this.props.executeGcode('M5');
}

Expand Down Expand Up @@ -438,6 +438,11 @@ class Visualizer extends React.PureComponent {
if (workflowStatus !== WorkflowStatus.Idle) {
setTimeout(() => {
server.stopServerGcode();

// Stop the laser or CNC machine. While trying to pause, if the 'tryPause' doesn't turn off, then wait for synchronization issues.
if (connectionType === CONNECTION_TYPE_SERIAL && (this.pauseStatus.headStatus || this.props.headType !== HEAD_PRINTING)) {
this.props.executeGcode('M5');
}
}, 60);
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/server/services/machine/ConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,12 @@ class ConnectionManager {
|| (toolHead === LEVEL_ONE_POWER_LASER_FOR_SM2 && isLaserPrintAutoMode))
&& ((materialThickness !== 0 && materialThickness !== -1) || isRotate)) {
await this.channel.laserSetWorkHeight({ toolHead, materialThickness, isRotate });

// Fixme: multi call to set work orign coordinate
// Camera Aid Background mode, force machine to work on machine coordinates (Origin = 0,0)
if (background.enabled && !isRotate) {
await this.channel.setAbsoluteWorkOrigin({ x: 0, y: 0, z: 0, isRotate });
}
}

const { jogSpeed = 1500 } = options;
Expand Down
33 changes: 25 additions & 8 deletions src/server/services/machine/channels/SacpChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1486,20 +1486,39 @@ class SacpChannelBase extends Channel implements
}
}

public async setAbsoluteWorkOrigin({ z, isRotate = false }: {
x: number, y: number, z: number, isRotate: boolean
public async setAbsoluteWorkOrigin({ x, y, z, isRotate = false }: {
x?: number, y?: number, z: number, isRotate: boolean
}) {
try {
const res1 = await this.sacpClient.updateCoordinate(CoordinateType.MACHINE);
log.debug(`updateCoordinate CoordinateType.MACHINE res: ${JSON.stringify(res1)}`);
await this.sacpClient.getCurrentCoordinateInfo().then(async ({ coordinateSystemInfo }) => {
const xNow = coordinateSystemInfo.coordinates.find(item => item.key === Direction.X1).value;
const yNow = coordinateSystemInfo.coordinates.find(item => item.key === Direction.Y1).value;
const zNow = coordinateSystemInfo.coordinates.find(item => item.key === Direction.Z1).value;
log.debug(`current positions, ${zNow}, ${z}`);
log.debug(`current positions, (${xNow}, ${yNow}, ${zNow}), (${x}, ${y}, ${z})`);

// calculate the absolute distance on seperate axis, same reason with coordinate moving func 'coordinateMove'
const newCoord = [];
const setXCoord = () => {
const newX = new CoordinateInfo(Direction.X1, xNow - x);
newCoord.push(newX);
};
const setYCoord = () => {
const newY = new CoordinateInfo(Direction.Y1, yNow - y);
newCoord.push(newY);
};
const setZCoord = () => {
const newZ = new CoordinateInfo(Direction.Z1, isRotate ? 0 : zNow - z);
newCoord.push(newZ);
};

const newZ = new CoordinateInfo(Direction.Z1, isRotate ? 0 : zNow - z);
const newCoord = [newZ];
log.debug(`new positions, ${zNow - z}, ${JSON.stringify(newCoord)}`);
if (!isRotate) {
typeof x !== 'undefined' && setXCoord();
typeof y !== 'undefined' && setYCoord();
}
typeof z !== 'undefined' && setZCoord();
log.debug(`new positions, (${xNow - x}, ${yNow - y}, ${zNow - z}), ${JSON.stringify(newCoord)}`);
await this.sacpClient.updateCoordinate(CoordinateType.WORKSPACE);
const res = await this.sacpClient.setWorkOrigin(newCoord);
log.debug(`setAbsoluteWorkOrigin res:${JSON.stringify(res)}`);
Expand All @@ -1520,8 +1539,6 @@ class SacpChannelBase extends Channel implements
const { laserToolHeadInfo } = await this.sacpClient.getLaserToolHeadInfo(headModule.key);
log.debug(`laserFocalLength:${laserToolHeadInfo.laserFocalLength}, materialThickness: ${materialThickness}, platformHeight:${laserToolHeadInfo.platformHeight}`);
await this.setAbsoluteWorkOrigin({
x: 0,
y: 0,
z: laserToolHeadInfo.laserFocalLength + laserToolHeadInfo.platformHeight + materialThickness,
isRotate
});
Expand Down
1 change: 1 addition & 0 deletions src/server/services/machine/channels/SacpTcpChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class SacpTcpChannel extends SacpChannelBase {

await this.sacpClient.updateCoordinate(CoordinateType.WORKSPACE);

// Fixme: multi call to set work orign coordinate
if (isCameraCapture) {
const newX = new CoordinateInfo(Direction.X1, xNow);
const newY = new CoordinateInfo(Direction.Y1, yNow);
Expand Down

0 comments on commit 40298d8

Please sign in to comment.