API

Learn details about the interfaces to the controller in the API reference and use them to effectively develop your applications.


API Structure

API Structure Image

OmniCore SDK: Leverage RWS to interact with endpoints provided by the OmniCore SDK. Use RWS. to call the interfaces. A comprehensive list of supported endpoints is available in the OmniCore SDK Documentation.

CODE
RWS.Network = new function() {
  this.send = (method, path, requestHeaders = {}, body = null) => {
      return new Promise((resolve, reject) => {
          let req = new XMLHttpRequest();
          ......
      }).catch(err => Promise.reject(err));
  };
  this.get = (path, additionalRequestHeaders = {}) => {
      return this.send("GET", path, Object.assign({
          Accept: "application/hal+json;v=2.0"
      }, additionalRequestHeaders));
  };
  }();

AppStudio Extensions: AppStudio integrates certain RWS interfaces with business logic encapsulation, making them available in the API layer, which are detailed in this reference.

  1. API.RWS: API.RWS provides a set of RWS interfaces that are not supported by the OmniCore SDK. It is a supplement to the OmniCore SDK interfaces.

    CODE
    API.RWS.RAPID.getModuleText = async function (moduleName, taskName = 'T_ROB1') {
      let res = await RWS.Network.get(`/rw/rapid/tasks/${taskName}/modules/${moduleName}/text`);
      var fixedResponse = res.responseText.replace(/""(.*?)""/g, '"$1"');
      let obj = parseJSON(fixedResponse);
      if (typeof obj === 'undefined') return Promise.reject('Could not parse JSON.');
      if (!obj.state[0]) return Promise.reject('Failed to get module text.');
    
      return obj.state[0];
    };
  2. API: The API layer extends the functionality of RWS by adding business logic and additional features. It provides a higher-level abstraction for developers to build applications without needing to directly interact with low-level RWS interfaces.

    CODE
    API.RAPID.getModuleText = async function (moduleName, taskName = 'T_ROB1') {
      try {
        const res = await API.RWS.RAPID.getModuleText(moduleName, taskName);
        const moduleText = res['module-text'];
        ......
      } catch (e) {
        API.rejectWithStatus(`Failed to get ${taskName}:${moduleName} text.`, e);
      }
    };

How to Create Unsupported RWS Interfaces

If you need to use an RWS interface that is not yet supported by the API layer or OmniCore SDK, you can perform the following steps to create a custom implementation:

  1. Refer to the RWS Documentation: Start from reviewing the official RWS documentation to understand the URL, HTTP method (e.g., GET, POST), and request/response format of the desired interface.

  2. Create a POST Request: Use the interface RWS.Network to construct a custom request. For example:

    CODE
    RWS.Network.post(
      '/rw/panel/speedratio',
      'speed-ratio=' + speedRatio.toString()
    );
  3. Create a GET Request: Use the interface RWS.Network to construct a custom request. For example:

    CODE
    let speedRes = await RWS.Network.get('/rw/panel/speedratio');
  4. Test and Validate: Call the custom function to make sure it can communicate correctly with RWS and return the expected results.


TPU & Browser Environment

Typically you can run your webapp in two environments: browser environment for debugging and TPU environment for production. Please note that there might be subtle behavioral differences in the provided APIs between these two environments.

EnvironmentClient TypeTypical Device
TPU environmentLocal ClientFlexPendant (Teach Pendant)
Browser environmentRemote ClientBrowser, RobotStudio, PC

The navigation interface is exclusively available in the TPU environment.

Local Client Identity in Browser Environment: When opening your webapp in a web browser, if functionality relies on APIs exclusive to the Local Client (e.g., jogging), you may need to register as a Local Client using the RWS POST request 'users/register/local'. Otherwise, the system will default to treating it as a Remote Client and reject such requests. To determine if the current session is a local client login, use the API.UAS.isLoggedInAsLocalClient() interface.

The following commonly used interfaces exhibit behavioral differences between the two environments:

APIFunctionModeRemote ClientLocal Client
API.RWS.MOTIONSYSTEM.setMechunitSet active mechanical unitsAuto√√
Manual×√
API.MOTION.align API.MOTION.goToPositionJog functionsAuto××
Manual×√
API.RWS.requestMastership('edit')Request edit mastershipAuto√√
Manual×(need to handle RMMP in manual mode)√
API.RWS.requestMastership('motion')Request motion mastershipAuto√√
Manual√√
API.RAPID.startExecutionExecute RAPID programAuto√√
Manual×√
API.RAPID.stopExecutionStop RAPID programAuto√√
Manual√√
API.RAPID.setPPToMain API.RAPID.setPPToRoutineSet program pointer to main / routineAuto√√
Manual×√
API.RWS.MOTIONSYSTEM.setLeadThroughStatusEnable / disable leadthroughAuto√√
Manual√√
API.CONTROLLER.setOpModeSwitch operation modeAuto×√(witch acknowledge)
Manual×√