Tool Control Contributions
What is Tool Control?
Tool Control allows a contribution to specify the various parameters that will be sent to the tool. For example, a gripper contribution might require that the tool be set to 24V. The UI provides a dropdown called ‘Controlled By’ on the Application -> Communication -> Tool I/O screen, where all tool control contributions are listed. When a particular contribution is selected, it’s parameters will then be sent to the tool, and the tool parameters will be disabled in the UI. The following are the parameters that can be controlled by a Tool Control contribution
Tool Output. Setting either 0, 12, or 24 V
Dual Pin Power. Setting true/false
Dual Pin Power. Setting true/false
The Domain for analog inputs. Setting Current or Voltage per analog input
The Power Output for digital outputs. Setting Sinking or Sourcing or Push/Pull per digital output
The Tool Communication settings. These settings are not available on the user interface, but are the enabled, baud rate, parity, stop bits, rx idle chars, tx idle chars
These parameters will be sent when selected in the dropdown, and when a program is loaded
How to add Tool Control to a Front-end Contribution?
Tool Control is part of an application contribution If you have a URCap that does not contain an application contribution you can add one by following these steps:
1. Add the Folders and Files
Add a folder to your frontend where you store your application(s), and add the application behavior worker TS file to that folder. In our example we call our folder gripper-application and likewise for the behavior worker (it is not required that the folder and the behavior worker are named the same):
└─ src
├─ app
│ ├─ app.module.ts
│ └─ components
│ └── gripper-application-node
│ ├─ gripper-application.behavior.worker.ts
│ ├─ gripper-application.component.html
│ ├─ gripper-application.component.ts
│ └─ gripper-application.ts
├─ assets
│ ├─ i18n
│ └─ icons
├─ contribution.json
├─ index.html
├─ main.ts
└─ styles.scss
2. Add the Behavior
Add the default behavior to the empty gripper-application.behavior.worker.ts file:
There are two extra methods that need to be added.
The first is ‘toolControllers’. This will be used to add entries into the ‘Controlled By’ dropdown. The id should be unique to you contribution, and should not change.
The second is ‘toolControlInfo’. This will get called when a particular tool controller is selected
import { registerApplicationBehavior, ApplicationBehaviors } from '@universal-robots/contribution-api';
const behaviors: ApplicationBehaviors = {
// factory is required
factory: () => {
return { type: 'gripper-application', version: '1.0.0' };
},
toolControllers: (node): ToolController[] => {
return [
{ id: '01', name: 'Just Voltage' },
{ id: '02', name: 'Everything!' },
];
},
toolControlInfo: (node, toolController): ToolControl => {
if (toolController.id === '01') {
return {
toolOutput: {
dualPinPower: false,
voltage: { value: 12, unit: 'V' },
powerOutput: {
'DO 0': PowerOutputEnum.SOURCING,
'DO 1': PowerOutputEnum.PUSH_PULL,
},
},
};
}
else {
return {
toolAnalogDomainMap: {
'AI 0': SignalAnalogDomainValueEnum.VOLTAGE,
'AI 1': SignalAnalogDomainValueEnum.CURRENT,
},
toolOutput: {
dualPinPower: false,
voltage: { value: 24, unit: 'V' },
powerOutput: {
'DO 0': PowerOutputEnum.SOURCING,
'DO 1': PowerOutputEnum.PUSH_PULL,
},
},
toolCommunication: {
enabled: true,
baudRate: BaudRateEnum.BAUD_9600,
parity: ParityEnum.NONE,
stopBits: StopBitsEnum.ONE,
txIdleChars: 1,
rxIdleChars: 1,
},
};
}
},
};
registerApplicationBehavior(behaviors);
3. Add the application to the app.module.ts:
registerWorkersWithWebPack() {
...
new Worker(new URL('./components/gripper-application/gripper-application.behavior.worker.ts' /* webpackChunkName: "gripper-application.worker" */, import.meta.url), {
name: 'gripper-application',
type: 'module',
});
}
4. Add the translations for your new application in the en.json:
{
"application": {
"gripper-application": { //Note that this _MUST_ match the componentTagName found in contribution.json
"title": "Gripper"
}
}
}
5. Edit the contribution.json file to include the application:
{
"application": [
{
"name": "gripper-application",
"iconURI": "assets/icons/gripper-icon.svg",
"presenterURI": "main.js",
"behaviorURI": "gripper-application-behavior-worker.js",
"translationPath": "assets/i18n/",
"componentTagName": "gripper-application",
"size": "large"
}
]
}
Rebuild and reinstall the URCap!