The CNC Model (implemented by CNC class) will contain an updated representation of the connected elements of the QUERCUS Cnc with its respective group of services:
The object will be emitting events on every connection-related event:
CNC class instance doesn't request cnc model by default, we have to request the model ourselves invoking...
cnc.requestModel();
Once model is created, update loop is launched and every change in data model will be reflected in real time. If we do not need any update we should unsubscribe from model...
cnc.disconnectModel();
Some model properties are handled by a dedicated Variable class. This class is able to convert the internal value used by cnc to human readable formats. Properties that are not affected by any conversion, such as booleans and strings are represented by primary data types.
Provides some getters to convert the values from internal format to external ones. For example, a space format stored in decumicras can be exported indistincly to mm or inches.
const axis = cnc.getChannel(1).getAxis(1);
// ppos property is Variable type
// we can get stord internal value
console.log(axis.ppos.value);
// 275000.01544570044
As we see in above example, this value is defined in decimicras. Variable provides external getter that depending on internal flags and variable type converts internal value to another more readable based in international system of units.
console.log(axis.ppos.external);
// 27.500001544570043
if we want to show the value in imperial system, we must use inches:
console.log(axis.ppos.inches);
// 1.082677226164175
There are other cases where variable type can be special like when an axis is parameterized as diameters. When this happens, stored value must be multiplied by two. Variable exposes diameters flag to indicate that value can be affected by this fact, also provides two getters, mmDiameter and inchesDiameter to convert the values. If variable type is not affected by diameters, these getters will return the same value as mm and inches does return.
console.log(ax.ppos.diameters);
// 1
console.log(ax.ppos.mmDiameter);
// 55.00000308914009
console.log(ax.ppos.inchesDiameter);
// 2.16535445232835
All services are handled in the same way, every service returns a promise of ServiceResponse object.
If service execution has gone well, promise is resolved with a object that contains:
{
returnCode: 0,
data: "everything is ok!"
}
As a rule, if returnCode is different than 0, data could contain desired data (if the service returns some kind of data). If returnCode is not 0, data could contain an explanation of error.
// We want to know the value of first local parameter in level 1.
cnc.getChannel(1).parametersServices.getLocalParameterData(1, ["0"]).then(ret => {
if(ret.returnCode === 0) //OK
{
console.log(ret.data);
/*
{
data:{
name: "0"
value: 0
},
returnCode: 0
}
*/
}
});
//Now we will force an errored service response. we will try to start execution via service with real kernel cnc instance.
cnc.getChannel(1).cncServices.startExecution().then(ret => {
if(ret.returnCode !== 0) //error
{
console.log(ret.data);
/*
{
returnCode: -1
}
*/
}
});
⚠️(Only available when model is requested)
Cnc has a collection of all available axis of the cnc machine. Each axis object is a representation of the physical axis and contains all relevant information (name, position, type, ...).
There are somme accessors implemented to get a specific axis from Cnc object:
let ax = cnc.getAxis('X');
console.log(ax.logicId, ax.name);
//1 X
let ax2 = cnc.getAxis(ax.logicId);
console.log(ax2.logicId, ax2.name)
//1 X
let ax = cnc.axes[0];
console.log(ax.name);
//X
⚠️(Only available when model is requested)
Cnc has a collection of available spindles of the cnc machine. Each spindle object is a representation of the physical spindle and contains all relevant information of it.
There are somme accessors implemented to get a specific axis from Cnc object:
let sp = cnc.getSpindle('S1');
console.log(sp.logicId, sp.name);
//5 S1
let sp2 = cnc.getSpindle(sp.logicId);
console.log(sp2.logicId, sp2.name)
//5 S1
let sp = cnc.spindles[0];
console.log(sp.name);
//S
⚠️(Only available when model is requested)
Cnc has a collection of available operation channel that Cnc kernel can use. It is a logical representation of how the cnc kernel executes commands and programs. Each channel has associated some axis and spindles that they don't have to correspond with the system axes represented in Cnc object, and are not inmutable, an axis can be moved through different channels. So that, a channel is the main logical element to interact with cnc kernel and most of the services are groupped under this class. Each channel is identified with a logical id starting from 1. For now, the cnc can handle a maximum of 4 channels.
There are somme accessors implemented to get a specific channel from Cnc object:
let ch = cnc.getChannel(1);
console.log(ch.logicId);
//1
let ch = cnc.channels[0];
console.log(ch.logicId);
//1
Spindles and axes associated to a channel can be accessed in the same way as we do with system ones, using getAxis or getSpindles methods or accessing directly to spindles and axes array.
console.log(cnc.getChannel(1).axes.map(ax => ax.name));
//["X","Y","Z","C"]
//If we execute #SET AX [X,Y,Z], channel's array will change to [X,Y,Z]
const channel = cnc.getChannel('1');
channel.cncServices.enterBlockMode().then(console.log);
channel.on('axesUpdated', (axes) => {
console.log(axes.map(ax => ax.name));
})
// EVENTS
// When Cnc mode event arrives, we program '#SET AX [X,Y,Z]' block.
cnc.on('CncModeEvent', event => {
console.log(`Cnc operation mode has changed: ${event.data.mode}`);
if(event.data.mode === 'BLK_SELEC') {
console.log(`About to execute [cnc.getChannel('1').cncServices.setBlock('#SET AX [X,Y,Z]')]`);
channel.cncServices.setBlock('#SET AX [X,Y,Z]').then((data) => {
if(data.return.returnCode === 0){
console.log('Execution block has been assumed properly.')
} else {
console.error('Execution block has not been assumed properly.')
}
})
}
});
//When we press start we will see in output console
//["X","Y","Z"]
//we can execute #SET instruction modifying multiple axis at once. For example,
// #SET AX [X]. In this case, the changes are made one by one, so we will see this in console log:
// ["X","Y","Z"]
// ["X","Y"]
// ["X"]
console.log(cnc.getChannel(1).spindles.map(sp => sp.name));
//["S","S1"]
//If we execute #FREE SP [S1], channel's array will change to [S]
const channel = cnc.getChannel('1');
channel.cncServices.enterBlockMode().then(console.log);
channel.on('spindlesUpdated', (spindles) => {
console.log(spindles.map(sp => sp.name));
})
// EVENTS
// When Cnc mode event arrives, we program '#FREE SP [S1]' block.
cnc.on('CncModeEvent', event => {
console.log(`Cnc operation mode has changed: ${event.data.mode}`);
if(event.data.mode === 'BLK_SELEC') {
console.log(`About to execute [cnc.getChannel('1').cncServices.setBlock('#FREE SP [S1]')]`);
channel.cncServices.setBlock('#FREE SP [S1]').then((data) => {
if(data.return.returnCode === 0){
console.log('Execution block has been assumed properly.')
} else {
console.error('Execution block has not been assumed properly.')
}
})
}
});
//When we press start we will see in output console
//["S"]
Further information about cncEvents can be found in Cnc Events section.
In order to enhance the access to properties and services related to channel, these have been grouped in logical subclasses:
CncServices: Class that groups all services used to interact with cnc kernel.
ProgramProperties: Class that groups all properties related to program execution.
ActiveToolProperties: Class that groups all properties related to active tool.
InspectionServices: Class that groups all services related to tool inspection.
MachiningConditionProperties: Class that groups all properties related to machining conditions.
ParametersServices: Class that groups all services related to user parameter tables.