Using the OpenSim API
The Developer's Guide has examples using the API, including:
Performing a Simulation - Write a main C++ program (a "tug of war") to create a model and run a forward simulation
Creating Your Own Analysis - Write your own Analysis to output the center of mass of each body in a model, plus velocities and accelerations
Creating a Controller - Extend the tug of war example with a custom controller
Creating an Optimization - Write an optimization to find muscle controls to maximize the forward velocity of the hand
Creating a Customized Actuator - Implement a spring with controllable stiffness
Creating a Customized Muscle Model - Implement a muscle model with fatigue
Building the API Examples
A summary of the steps to build the API examples is below. There are more details in the Developer's Guide. We will use the tug-of-war Example (Located in your OpenSimInstallationDirectory\sdk\APIExamples\ExampleMain folder) as an example.
- Prepare a working directory: Copy the example folder from the installation folder (by default, this is C:\OpenSim 3.0\sdk\APIExamples\ExampleMain) to a working folder. In this example, we will assume the working folder is C:\ExampleMain, but the name and path are arbitrary.
- Run CMake. Launch CMake. In the dialog box that appears:
- For the field "Where is the source code," select the working plug-in directory you just created (e.g., C:\ExampleMain).
- Select a directory for "Where to build the binaries." For this example, we will use the folder C:\TugOfWarBuild. (If the directory does not exist CMake will prompt you to ask if it should create the directory after you hit Configure)
- Hit Configure and you will see things highlighted in red. Make sure that the correct installation directory is specified for OPENSIM_INSTALL_DIR, and update it if needed. If you use any directory other than the default for installation, you will also need to update CMAKE_INSTALL_PREFIX to have the same value as OPENSIM_INSTALL_DIR.
- Click Configure again, and the highlighted red should be cleared, and then Generate.
- You will see a solution file (.sln) generated in the build directory. Double click on it and it will launch Visual Studio.
- Build solution. Use Visual Studio's "Build" menu to compile your project (or right click on ALL_BUILD and build). You need to switch from "Debug" to either "Release" or "RelWithDebInfo" if you do not have debuggable OpenSim libraries against which to link.
If you are building a plugin there will be an INSTALL project in the Solution Explorer on the left panel. you can build it in order to install your dll file to the plugins directory in OpenSim.