Skip to content

Commit

Permalink
Merge pull request #20 from makermadecnc/zkc-calibration
Browse files Browse the repository at this point in the history
Calibration UI, Better Tabs, Cleanup
  • Loading branch information
zaneclaes committed Aug 20, 2020
2 parents c05dccb + f84adf4 commit 630d64f
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 496 deletions.
3 changes: 2 additions & 1 deletion .cncrc.default
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"watchDirectory": "",
"accessTokenLifetime": "30d",
"allowRemoteAccess": false
"allowRemoteAccess": false,
"workspaces": []
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Pre-build assets; this prevents the multi-arch from running each build in the Dockerfile.
- npm run build-latest
# Only the master branch supports a "deploy" step. For others, go ahead and push a dev image.
- travis_wait 20 scripts/docker.sh build
- scripts/docker.sh build
after_success: [] # Override.
addons:
apt:
Expand All @@ -54,7 +54,7 @@ jobs:
deploy:
skip_cleanup: true # Leave build artifacts in place (don't git clean)
provider: script
script: travis_wait 20 scripts/docker.sh deploy
script: scripts/docker.sh deploy
# [Job] [Linux]
- name: "Linux"
os: linux
Expand Down
26 changes: 20 additions & 6 deletions examples/.cncrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{
"ports": [
{
"comName": "/dev/ttyAMA0",
"manufacturer": ""
}
"workspaces": [
{
"name": "My CNC Machine",
"path": "/machine1",
"controller": {
"controllerType": "Maslow",
"port": "/dev/ttyACM0",
"baudRate": 57600,
"rtscts": false,
"reconnect": false
},
"limits": {
"xmin": -1219.2,
"xmax": 1219.2,
"ymin": -609.6,
"ymax": 609.6,
"zmin": -25.4,
"zmax": 12.7
}
}
],
"baudrates": [115200, 250000],
"mountPoints": [
{
"route": "/widget",
Expand Down
13 changes: 7 additions & 6 deletions src/app/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class App extends PureComponent {
const workspacePaths = Object.keys(Workspaces.all).map((workspaceId) => {
return Workspaces.all[workspaceId].path;
});
const paths = [
const staticPaths = [
'/home',
'/settings',
'/settings/general',
Expand All @@ -30,8 +30,10 @@ class App extends PureComponent {
'/settings/commands',
'/settings/events',
'/settings/about'
] + workspacePaths;
const accepted = (paths.indexOf(location.pathname) >= 0);
];
const isWorkspace = workspacePaths.indexOf(location.pathname) >= 0;
const isStaticPath = staticPaths.indexOf(location.pathname) >= 0;
const accepted = isWorkspace || isStaticPath;

if (!accepted) {
return (
Expand Down Expand Up @@ -65,15 +67,14 @@ class App extends PureComponent {
/>
{Object.keys(Workspaces.all).map((workspaceId) => {
const workspace = Workspaces.all[workspaceId];
const active = location.pathname === workspace.path;
workspace.isActive = location.pathname === workspace.path;
return (
<Workspace
{...this.props}
key={workspaceId}
isActive={active}
workspaceId={workspaceId}
style={{
display: active ? 'block' : 'none'
display: workspace.isActive ? 'block' : 'none'
}}
/>
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/containers/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Sidebar extends PureComponent {
render() {
const { pathname = '' } = this.props.location;

console.log(styles.iconHome);

return (
<nav className={styles.navbar}>
<ul className={styles.nav}>
Expand Down
1 change: 0 additions & 1 deletion src/app/containers/Workspace/Workspace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Workspace extends PureComponent {
static propTypes = {
...withRouter.propTypes,
workspaceId: PropTypes.string.isRequired,
isActive: PropTypes.bool.isRequired,
};

get workspace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class MaslowCalibration {
recomputeIdeals() {
this.idealCoordinates = this.calculateIdealCoordinates();
this.idealChainLengths = this.calculateChainLengths(this.idealCoordinates);
this.gcode = this.generateGcode(this.idealCoordinates, this.opts.cutDepth);
}

calibrate(measurements, callback) {
Expand Down Expand Up @@ -201,16 +200,21 @@ class MaslowCalibration {
return ret;
}

generateGcode(points, cutDepth) {
const ret = ['G21', 'G90'];
const cutOrder = [points[1], points[2], points[5], points[4], points[3], points[0]];
generateGcodePoint(pointIndex, gcode = ['$X', 'G21', 'G90']) {
const p = this.idealCoordinates[pointIndex];
gcode.push(`G0 X${p.x} Y${p.y}`);
if (this.opts.cutDepth) {
gcode.push(`G0 Z-${this.opts.cutDepth}`);
gcode.push(`G0 Z${this.opts.safeTravel}`);
}
return gcode;
}

generateGcode() {
const ret = ['$X', 'G21', 'G90'];
const cutOrder = [1, 2, 5, 4, 3, 0];
for (var i = 0; i < cutOrder.length; i++) {
const p = cutOrder[i];
ret.push(`G0 X${p.x} Y${p.y}`);
if (cutDepth) {
ret.push(`G0 Z-${cutDepth}`);
ret.push(`G0 Z${this.opts.safeTravel}`);
}
this.generateGcodePoint(cutOrder[i], ret);
}
ret.push('G0 X0 Y0');
return ret;
Expand Down
File renamed without changes.
165 changes: 150 additions & 15 deletions src/app/lib/workspaces.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import log from 'app/lib/log';
import store from '../store';
import controller from './controller';
import {
Expand All @@ -13,11 +14,6 @@ import {
class Workspaces {
static all = {};

// Easy access to the current UI tab (if applicable).
static get current() {
return null;
}

static findByPath(path) {
return _.find(Workspaces.all, (w) => {
return w.path === path;
Expand Down Expand Up @@ -47,9 +43,43 @@ class Workspaces {
return this._record.name;
}

// Workspaces own controllers, which each represent a single connection to the hardware.
get controller() {
return controller;
get controllerAttributes() {
return {
type: this._record.controller.controllerType,
port: this._record.controller.port,
baudRate: Number(this._record.controller.baudRate),
rtscts: !!this._record.controller.rtscts,
reconnect: !!this._record.controller.reconnect,
};
}

// Flag set by main App.jsx to indicate if this is the active workspace.
get isActive() {
return this._isActive || false;
}

set isActive(active) {
const wasActive = !!this._isActive;
this._isActive = !!active;
if (wasActive !== this._isActive) {
if (this._isActive) {
this.onActivated();
} else {
this.onDeactivated();
}
}
}

onActivated() {
this.addControllerEvents();
if (this.controllerAttributes.reconnect) {
this.openPort();
}
}

onDeactivated() {
this.removeControllerEvents();
this.closePort();
}

// Sidebar icon.
Expand All @@ -58,18 +88,123 @@ class Workspaces {
return this._record.icon;
}
let icon = 'xyz';
if (this.controllerType === MASLOW) {
if (this.controllerAttributes.type === MASLOW) {
icon = 'maslow';
} else if (this.controllerType === GRBL) {
} else if (this.controllerAttributes.type === GRBL) {
icon = 'cnc';
} else if (this.controllerType === MARLIN) {
} else if (this.controllerAttributes.type === MARLIN) {
icon = '3dp';
}
return `images/icons/${icon}.svg`;
}

get controllerType() {
return this._record.controller.controllerType;
// ---------------------------------------------------------------------------------------------
// Workspaces own controllers, which each represent a single connection to the hardware.
// WIP: controller is still a global, but it gets (dis/re)connected when switching workspaces.
// ---------------------------------------------------------------------------------------------

_hasControllerEvents = false;
_connecting = false;
_connected = false;

_controllerEvents = {
'serialport:change': (options) => {
const { port } = options;
if (port !== this.controllerAttributes.port) {
return;
}
log.debug(`Changed ports to "${port}"`);
},
'serialport:open': (options) => {
const { port } = options;
if (port !== this.controllerAttributes.port || !this._connecting) {
return;
}

log.debug(`Established a connection to the serial port "${port}"`);
this._connecting = false;
this._connected = true;
},
'serialport:close': (options) => {
const { port } = options;
if (port !== this.controllerAttributes.port) {
return;
}

log.debug(`The serial port "${port}" is disconected`);
this._connecting = false;
this._connected = false;
},
'serialport:error': (options) => {
const { port } = options;
if (port !== this.controllerAttributes.port) {
return;
}

log.error(`Error opening serial port "${port}"`);
this._connecting = false;
this._connected = false;
}
};

get controller() {
return controller;
}

get isConnected() {
return this._connected;
}

get isConnecting() {
return this._connecting;
}

openPort(callback) {
const atts = this.controllerAttributes;
controller.openPort(atts.port, {
controllerType: atts.type,
baudrate: atts.baudRate,
rtscts: atts.rtscts
}, (err) => {
if (err) {
this._connecting = false;
this._connected = false;
log.err(err);
}
if (callback) {
callback(err);
}
});
}

closePort(callback) {
this._connecting = false;
if (!this.isConnected) {
return;
}
this._connected = false;
controller.closePort(this.controllerAttributes.port, (err) => {
if (err) {
log.err(err);
}
if (callback) {
callback(err);
}
});
}

addControllerEvents() {
Object.keys(this._controllerEvents).forEach(eventName => {
const callback = this._controllerEvents[eventName];
this.controller.addListener(eventName, callback);
});
}

removeControllerEvents() {
Object.keys(this._controllerEvents).forEach(eventName => {
const callback = this._controllerEvents[eventName];
controller.removeListener(eventName, callback);
});
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -80,8 +215,8 @@ class Workspaces {

// ---------------------------------------------------------------------------------------------
get primaryWidgets() {
const ret = ['connection', 'console', this.controllerType.toLowerCase()];
return ret;
const controllerWidget = this.controllerAttributes.type.toLowerCase();
return ['connection', 'console', controllerWidget];
}

get primaryWidgetsVisible() {
Expand Down

0 comments on commit 630d64f

Please sign in to comment.