Go To Mechanical Simulation Corporation Home Page
Go To Mechanical Simulation Corporation's Facebook Page
Go To Mechanical Simulation Corporation's LinkedIn Page
Go To Mechanical Simulation Corporation's YouTube Page
synched plot and video
Run a VS Solver from VB Basic. Click for more detail.

The math models in VehicleSim products can be extended several ways:

  1. The VS Math Model can be connected to a model in another simulation environment, such as Simulink.
  2. Equations and and variables can be added using VS Commands.
  3. Variables can be exchanged with custom programs as is done with Simulink.
  4. Variables in the math model can be accessed directly by custom programs that support C/C++ pointers.

This page describes options 3 and 4 (above) for using custom simulation programs that make use of the VS API.

VS API: VehicleSim Application Program Interface

A VS Solver is a program in a VehicleSim product that reads input files, writes output files, and calculates variables from an internal math model. Although each specific VS Solver is intended to represent a different kind of vehicle or other simulated system, all operate the same way when it comes to reading and writing files, solving differential equations, and communicating with other software.

VS Solvers are provided for Windows OS as dynamically linked library (DLL) files. As such, they are controlled by other software using the VS application program interface (API) — a set of functions that exist in all VS Solver programs.

The same solver DLL is used in all Windows simulation environments (built-in, Simulink, LabView, ASCET, command-line EXE, etc.). When no other software is used, the DLLs are loaded and run directly by the VS Browser (e.g., carsim.exe). Support for other software such as Simulink is handled by small "wrapper programs" that load and run the VS Solver and communicate as needed with the other software.

Besides supporting the use of a VS Solver DLL with the VS Browser and commercial simulation software, the VS API works well for use with custom Windows programs.

Basic Control with VS API

The API supports basic steps in simulation: initializing, running, and terminating. Any programming language that can load a DLL and access the public functions can be used to run simulations using VS Solvers.

Variables can be exchanged in the same manner used with Simulink and other commercial simulation environments. Arrays are set up for import and export variables (in these cases, going back and forth between the VS Solver and the custom wrapper program).

Example source code (Visual Basic, MATLAB, C) is provided showing how to use the VS API to run the VS solvers.

The VS API also provides access to the 3D geometry of the VS roads for use with external models such as user-defined vehicle models and advanced driver models that look ahead at the road geometry.

Advanced Control with C/C++

Running a VS Solver from ANSI C is simpler than from VB or MATLAB, because variables and functions can be shared directly via C pointers.

The VS API gives access to any variable or parameter in the math model that has a keyword. These include hundreds of parameters and thousands of variables.

The VS Solvers also support the use of externally defined callback functions at various times during the simulation. The API is used to provide pointers to the externally defined functions, and they are added to lists of functions used multiple times during each time step in the simulation. The support of callback function allows even tighter integration between the wrapper and the VS Solver than is possible with the once-per-time-step communication used with import and export arrays.

Example Applications

VehicleSim products include example custom program in MATLAB, VB, and ANSI C that show how to load and run the VS Solver, and possibly use the custom program to interact with the VS math models.

Driving Simulators

CarSim and TruckSim math models are used in over 1400 driving simulators. The vast majority of these were done with the ordinary Windows versions of the products. The makers of the driving simulators combine third-party visualization software and databases with the VS Math Model. Communication with the DLL is handled using the VS API functions.

Motorsport Team Applications

CarSim is in use today by sophisticated top-tier teams to reduce the workload of producing simulations. The VS API makes it possible to run third-party tire models, advanced damper models, detailed aero maps, and alternative engines and transmissions, to name just a few. Complex detailed arrangements can be accommodated, such as highly asymmetric suspensions, preloaded components, third springs, and inerters.

Race engineers extend CarSim to get the fastest available simulation together with all the advanced systems and components unique to their level of competition. CarSim is in use right now to simulate 7 post rigs, conduct optimization studies, study tire wear effects on lap time, examine trade-offs in set ups for mechanical versus aerodynamic grip, and to optimize setup of differentials and control systems.

CarSim engineers have worked with race engineers from NASCAR, Formula 1, ALMS, and IndyCar series who want to add their theories and knowledge to a fast, stable, and proven simulation tool.


video + plots
This figure from the API documentation shows the sequence of operations at the second half of each time step during a simulation. Click for full size.
video + plots
A MATLAB M-file can be used to run the VS Solver with model extensions. Click for more detail.
video + plots
A custom C program can install callback functions that will be used by the VS Solver. Click for more detail.
video + plots
Callback functions defined in an external C program can be called from within the VS Solver. Click for more detail.
Contact Us
Subscribe to Newsletter
© 2005-2019 Mechanical Simulation Corporation, All Rights Reserved. CarSim, SuspensionSim, TruckSim, BikeSim,
and VehicleSim are registered trademarks of Mechanical Simulation Corporation in the USA and other countries.