Custom Simulated Motor

The Custom Simulated Motor feature allows users to simulate custom motor behavior on simulated axes in KINGSTAR. To use this feature, users must prepare a user application and a custom simulated motor RTDLL. KINGSTAR provides a set of APIs and implementation samples to support the development of user applications and custom RTDLL.

NOTE:  The Custom Simulated Motor feature is supported in KINGSTAR 4.5.4 and later.

IN THIS SECTION:

Workflow

This basic workflow outlines how to use the Custom Simulated Motor feature:

  1. Create a user application
    Use the following APIs to create a custom application. For details, refer to the C++ and .NET implementation samples in Using Custom Simulated Motors in KINGSTAR.
  2. Implement a custom simulated motor RTDLL
    • To use your custom simulated motor in KINGSTAR, you must implement it as an RTDLL. The RTDLL must implement the following functions for KINGSTAR to load and execute your motor simulation. For more details on implementation, see Implementing Custom Simulated Motor in RTDLL.

      Required functions: CreateSimMotor, DestroySimMotor, RunSimMotor, GetSimMotorData, ResetSimMotorData
    • KINGSTAR Motion will pass motion target settings to the RTDLL through RunSimMotor to run custom simulated motor.
    • KINGSTAR Motion will retrieve actual data from the custom simulated motor through GetSimMotorData.

Implementing Custom Simulated Motor in RTDLL

Overview

To integrate a custom simulated motor with KINGSTAR, you must implement it as an RTDLL. This enables KINGSTAR to load and execute the motor simulation.

NOTE:  RTDLL implementations must be error-free, and it is not recommended to use KINGSTAR APIs within the RTDLL. Review Important Guidelines before starting development.

Getting Started
  1. Use the KsUserApp sample code. Please contact KINGSTAR Support to obtain KsUserApp.
  2. Navigate to the KsCustomSimulatedMotorRTDLL project, which serves as a reference implementation.
Project Structure
File Purpose Modification required

DllMain.cpp

RTDLL entry point

Do NOT modify

CustomSimulatedMotorRTDLL.h

Function declarations for KINGSTAR integration

Do NOT modify

CustomSimulatedMotorRTDLL.cpp

Sample implementation using BasicSimulatedMotor

Customize as needed

BasicSimulatedMotor.h

Basic motor simulator class declaration

Customize as needed

BasicSimulatedMotor.cpp

Basic motor simulator class implementation

Customize as needed

Implementation Steps
  1. Analyze the sample code:
    Review the sample implementation to understand the overall structure and workflow.
  2. Modify the RTDLL implementation:
    Update CustomSimulatedMotorRTDLL.cpp with your custom motor logic.
  3. Implement motor behavior:
    Customize BasicSimulatedMotor.h and BasicSimulatedMotor.cpp to match your motor's characteristics.
Important Guidelines

When developing your RTDLL implementation, adhere to the following requirements:

  1. Error-free execution:
    The implementation must not generate errors or throw exceptions.
  2. API restrictions:
    It is not recommended to use KINGSTAR APIs within the RTDLL.
  3. Build configuration:
    It is recommended to compile the RTDLL in Release mode to ensure optimal performance in production environments.

Using Custom Simulated Motors in KINGSTAR

This section describes how to integrate and run custom simulated motors using both KINGSTAR C and .NET APIs. The integration process follows a standardized workflow:

  1. Initialize the KINGSTAR Subsystem:
    Use Create to establish the KINGSTAR environment.
  2. Load the custom motor library:
    Call LoadCustomMotorLibrary with your RTDLL path. If there are no errors, this returns a library ID for the specified RTDLL.
  3. Configure simulated axes:
    Use SetConfiguredAxesCount to define the number of simulated axes.
  4. Set up axis configuration:
    Call ConfigureAxisEx to associate an axis with your custom simulated motor.
    Note: In the .NET API, this function is named ConfigureAxis.
  5. Configure motion parameters:
    Set up axis motion settings according to your requirements.
  6. Execute motor simulation:
    Run your simulated axis test scenarios.
  7. Cleanup:
    Stop and destroy the KINGSTAR Subsystem when execution is complete.

Detailed implementation examples are provided in both C++ and .NET API sample projects below.

C++ Implementation Sample

Getting Started

  1. Use the KsUserApp sample code. Please contact KINGSTAR Support to obtain KsUserApp.
  2. Open the KsCustomSimulatedMotorAppCPP project.

Project Components

File Purpose Modification required

CustomSimulatedMotorApi.h

Custom simulated motor API declarations

Do NOT modify

main.cpp

Complete workflow example

Customize as needed

Running the C++ Sample

  1. Configure the KINGSTAR Runtime environment:
    1. Open Runtime Settings from the KINGSTAR Control Panel.
    2. If a NIC is assigned to KINGSTAR, release it to ensure KINGSTAR runs in simulation mode.
  2. Prepare your RTDLL:
    1. Build the KsCustomSimulatedMotorRTDLL project.
    2. Deploy the compiled RTDLL to your target directory.
  3. Configure the sample project:
    1. Open the sample project in Visual Studio.
    2. Update the CUSTOM_SIMULATED_MOTOR_RTDLL_FILE_PATH constant with the absolute ASCII path to your RTDLL.
  4. Build and execute:
    1. Compile the sample project.
    2. Run the executable and verify the console output.

Creating a Custom C++ Application

  1. Generate a project template:
    Use the RTX64 Project Wizard to create a new C++ project.
  2. Configure linker dependencies:
    1. WIN32 configuration: Add ksapi.lib to the linker settings.
    2. RTSS configuration: Add ksapi_rtss.lib to the linker settings.
  3. Import API headers:
    Copy CustomSimulatedMotorApi.h from the sample project into your project.
  4. Implement your logic:
    Use the sample workflow as a foundation and customize the motor testing logic for your specific requirements.
.NET Implementation Sample

The following example uses KINGSTAR .NET Local APIs.

Getting Started

  1. Use the KsUserApp sample code. Please contact KINGSTAR Support to obtain KsUserApp.
  2. Open the KsCustomSimulatedMotorAppDotNet project.

Project Components

File Purpose Modification required

Program.cs

Complete workflow example

Customize as needed

Running the .NET Sample

  1. Configure the KINGSTAR Runtime environment:
    1. Open Runtime Settings from the KINGSTAR Control Panel.
    2. If a NIC is assigned to KINGSTAR, release it to ensure KINGSTAR runs in simulation mode.
  2. Prepare your RTDLL:
    1. Build the KsCustomSimulatedMotorRTDLL project.
    2. Deploy the compiled RTDLL to your target directory.
  3. Configure the sample project:
    1. Open the sample project in Visual Studio.
    2. Update CUSTOM_SIMULATED_MOTOR_RTDLL_FILE_PATH with the absolute ASCII path to your RTDLL.
  4. Build and execute:
    1. Compile the sample project.
    2. Run the executable and check console output.

Creating a Custom .NET Application

  1. Generate a project template:
    Use Visual Studio to create a new .NET project.
  2. Configure references:
    1. For projects using KINGSTAR .NET Local API, add:
      1. IntervalZero.KINGSTAR.Base
      2. IntervalZero.KINGSTAR.Local
    2. For projects using KINGSTAR .NET OpcUa API, add:
      1. IntervalZero.KINGSTAR.Base
      2. IntervalZero.KINGSTAR.OpcUa.Client
  3. Implement your logic:
    Use the sample workflow as a foundation and customize the motor testing logic for your specific requirements.