Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Manual control axidraw to help with registration
/*
This requires nodejs to run
install
npm install terminal-kit
npm install superagent
run
node axidraw-manual-control.js
Keys
left, right, up, down -> control pen position
+ , - -> control movement increments
a , z -> control pen height
*/
var term = require( 'terminal-kit' ).terminal ;
var request = require('superagent');
// go Home
request
.put('localhost:4242/v1/pen')
.send({ state: 0})
.end(function(err, res){});
request
.put('localhost:4242/v1/pen')
.send({ x: 0, y: 0 })
.set('Accept', 'application/json')
.end(function(err, res){});
// axidraw width: 29.9cm
var canvasWidth = 29.9;
// axidraw height 21.6
var canvasHeight = 21.6;
var x = 0;
var y = 0;
var increment = 30;
var penHeight = 0;
// applys increments in mm
function applyIncrement(increment, direction) {
var result = 0;
if(direction === 'x'){
result = increment * canvasWidth / 100 ;
} else if(direction === 'y') {
result = increment * canvasHeight / 100;
}
if( result < 0) result = 0;
if(result > 100) result = 100;
return result;
}
term.grabInput() ;
term.on( 'key' , function( name , matches , data ) {
term.clear() ;
// console.log( "'key' event:" , name ) ;
if(name === '0') {
x = 0;
y = 0;
}
if(name === 'RIGHT') {
x += applyIncrement(increment, 'x');
}
else if(name === 'LEFT') {
x -= applyIncrement(increment, 'x');
}
else if(name === 'DOWN') {
y += applyIncrement(increment, 'y');
}
else if(name === 'UP') {
y -= applyIncrement(increment, 'y');
}
else if(name === '+') {
if (increment < 1) {
increment += 0.1;
}else {
increment += 1;
}
term.green( 'increment: ' + increment + "% \n") ;
}
else if(name === '-') {
if(increment > 0) {
if (increment <= 1) {
increment -= 0.1;
}else {
increment -= 1;
}
term.green( 'increment: ' + increment + "%\n") ;
}
}
else if(name === 'a' || name === 'z'){
if(name === 'a') {
if(penHeight < 1) {
penHeight += 0.05;
}
}
else if(name === 'z') {
if(penHeight > 0) {
penHeight -= 0.05;
}
}
request
.put('localhost:4242/v1/pen')
.send({ state: penHeight})
.end(function(err, res){});
term.green( 'penHeight: ' + penHeight.toFixed(2) + "\n") ;
}
request
.put('localhost:4242/v1/pen')
.send({ x: x, y: y})
.end(function(err, res){
term.green( 'x: ' + (x * canvasWidth / 100).toFixed(2) +'cm y: ' + (y * canvasHeight / 100).toFixed(2) +"cm\n") ;
});
// Detect CTRL-C and exit 'manually'
if ( name === 'CTRL_C' || name === 'q' ) { process.exit() ; }
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.