Please follow below steps in order to include ForceSeatMI into your project.
- Create Unity 3D project
- Inside Assets directory of your project create ForceSeatMI directory
- Copy following files into ForceSeatMI directory (for the reference you can check any of our Unity 3D examples)
- ForceSeatMI.cs
- ForceSeatMI_Common.cs
- ForceSeatMI_Positioning.cs
- ForceSeatMI_Status.cs
- ForceSeatMI_TactileTranscuders.cs
- ForceSeatMI_Telemetry.cs
- ForceSeatMi_UnityAeroplane.cs
- ForceSeatMi_UnityVehicle.cs
ForceSeatMI API uses DLL which is installed as part of the ForceSeatPM software. Make sure that you have ForceSeatPM installed on your computer. |
Application: position control
Examples:- TableLogPos_Unity shows positioning in abstract(logical, percents) units
- TablePhyPos_Unity shows positioning in real world units (Inverse Kinematics)
- Import ForceSeatMI
using MotionSystems;
- Create an API object variable inside your class:
private ForceSeatMI m_fsmi;
- Initialize it in Start method:
m_fsmi = new ForceSeatMI();
- If everything is loaded call:
if (m_fsmi.IsLoaded()) { m_fsmi.BeginMotionControl(); }
- The SIM should send positioning data in constant intervals using one of the following functions:
m_fsmi.SendTopTablePosLog(...); m_fsmi.SendTopTablePosPhy(...); m_fsmi.SendTopTableMatrixPhy(...);
- At the end of simulation call:
if (m_fsmi.IsLoaded()) { m_fsmi.EndMotionControl(); m_fsmi.Dispose(); }
Code
Below code comes from TableLogPos_Unity example.// FSMI api private ForceSeatMI m_fsmi; // Position in logical coordinates that will be send to the platform private FSMI_TopTablePositionLogical m_platformPosition = new FSMI_TopTablePositionLogical(); void Start () { // Load ForceSeatMI library from ForceSeatPM installation directory // ForceSeatMI - BEGIN m_fsmi = new ForceSeatMI(); if (m_fsmi.IsLoaded()) { // Find platform's components m_shaft = GameObject.Find("Shaft"); m_board = GameObject.Find("Board"); SaveOriginPosition(); SaveOriginRotation(); // Prepare data structure by clearing it and setting correct size m_platformPosition.mask = 0; m_platformPosition.structSize = (byte)Marshal.SizeOf(m_platformPosition); m_platformPosition.state = FSMI_State.NO_PAUSE; // Set fields that can be changed by demo application m_platformPosition.mask = FSMI_POS_BIT.STATE | FSMI_POS_BIT.POSITION; m_fsmi.BeginMotionControl(); SendDataToPlatform(); // ForceSeatMI - END } else { Debug.LogError("ForceSeatMI library has not been found!Please install ForceSeatPM."); } } void OnDestroy() { // ForceSeatMI - BEGIN if (m_fsmi.IsLoaded()) { m_fsmi.EndMotionControl(); m_fsmi.Dispose(); } // ForceSeatMI - END } private void SendDataToPlatform() { // Convert parameters to logical units // ForceSeatMI - BEGIN m_platformPosition.state = FSMI_State.NO_PAUSE; m_platformPosition.roll = (short)Mathf.Clamp(m_roll / DRAWING_ROLL_MAX * PLATFORM_POSITION_LOGIC_MAX, PLATFORM_POSITION_LOGIC_MIN, PLATFORM_POSITION_LOGIC_MAX); m_platformPosition.pitch = (short)Mathf.Clamp(m_pitch / DRAWING_PITCH_MAX * PLATFORM_POSITION_LOGIC_MAX, PLATFORM_POSITION_LOGIC_MIN, PLATFORM_POSITION_LOGIC_MAX); m_platformPosition.heave = (short)Mathf.Clamp(m_heave / DRAWING_HEAVE_MAX * PLATFORM_POSITION_LOGIC_MAX, PLATFORM_POSITION_LOGIC_MIN, PLATFORM_POSITION_LOGIC_MAX); // Send data to platform m_fsmi.SendTopTablePosLog(ref m_platformPosition); // ForceSeatMI - END }
Application: vehicle simulation
Examples: Telemetry_Veh_Unity (use built-in ForceSeatPM profile SDK – Vehicle Telemetry) For vehicle simulation application ForceSeatMI_UnityVehicle helper interface can be used. Typical operation routine consists of following steps:- Create an API object variable inside your class:
private ForceSeatMI_UnityVehicle m_Api;
- Initialize it in Start method:
m_Api = new ForceSeatMI_UnityVehicle();
- Call:
m_Api.Begin();
- The SIM should send telemetry data in constant intervals using following function::
m_Api.Tick(...);
- At the end of simulation call:
m_Api.End();
Code
Below code comes from Telemetry_Veh_Unity example.private void Start() { m_Rigidbody = GetComponent(); // ForceSeatMI - BEGIN m_Api = new ForceSeatMI_UnityVehicle(); m_Api.Begin(); // ForceSeatMI - END } private void OnDestroy() { // ForceSeatMI - BEGIN m_Api.End(); // ForceSeatMI - END } private void Move(float steering, float accel, float footbrake, float handbrake) { ... // ForceSeatMI - BEGIN m_Api.Tick(m_Rigidbody, Time.deltaTime, false, 0, 0, m_CurrentGearNumber); // ForceSeatMI - END }
Application: flight simulation
Examples: Telemetry_Fly_Unity (use built-in ForceSeatPM profile SDK – Plane Telemetry) For flight simulation application ForceSeatMi_UnityAeroplane helper interface can be used. Typical operation routine consists of following steps:- Create an API object variable inside your class:
private ForceSeatMi_UnityAeroplane m_Api;
- Initialize it in Start method:
m_Api = new ForceSeatMi_UnityAeroplane();
- Call:
m_Api.Begin();
- The SIM should send telemetry data in constant intervals using following function::
m_Api.Tick(...);
- At the end of simulation call:
m_Api.End();
Code
Below code comes from Telemetry_Fly_Unity example.private void Start() { m_Rigidbody = GetComponent(); m_OriginalDrag = m_Rigidbody.drag; m_OriginalAngularDrag = m_Rigidbody.angularDrag; // ForceSeatMI - BEGIN m_Api = new ForceSeatMI_UnityAeroplane(); m_Api.Begin(); // ForceSeatMI - END } private void OnDestroy() { // ForceSeatMI - BEGIN m_Api.End(); // ForceSeatMI - END } private void FixedUpdate() { ... // ForceSeatMI - BEGIN m_Api.Tick(m_Rigidbody, Time.deltaTime, false); // ForceSeatMI - END }