Dynamics Example¶
Note
Example directory: [SimOne installation directory]\SimOneAPI\Tutorial\Dynamics
Algorithm Overview
The Dynamics example calls SimOneAPI to perform standard dynamics tests on the ego vehicle, including full braking, acceleration to a target speed, and sinusoidal steering. It is used to verify the vehicle dynamics response.
Example Code
The following is the complete main.cpp example, demonstrating API initialization and three dynamics test calls:
#include "SimOneServiceAPI.h"
#include "SimOnePNCAPI.h"
#include "SimOneSensorAPI.h"
#include "TestSample.hpp"
#include <string.h>
using namespace std;
int main(int argc, char* argv[])
{
// Step1: Initialize SimOne API and connect to the local simulation service
if (SimOneAPI::InitSimOneAPI("0", false, "127.0.0.1"))
{
cout << "InitSimOneAPI Done" << endl;
}
// Step2: Set the driver name (used to distinguish control sources in multi-vehicle scenarios)
SimOneAPI::SetDriverName("0", "DynaTest");
// Optional: specify the output CSV path via command-line argument
std::string csvPath = "";
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-csvPath") == 0) {
csvPath = argv[i + 1];
++i;
}
else {
csvPath = "resultsALL.csv";
}
}
TestSample test;
// Step3: Run a dynamics test (uncomment one to enable)
/* Test 1: Full braking — emergency brake with a braking intensity of 1.0 */
test.FullBrakeTest("0", 1.0f, csvPath);
/* Test 2: Accelerate to target speed (100 km/h, throttle intensity 1.0) */
// test.DriveToSpeed(0, 100.f, 1.0f, csvPath);
/* Test 3: Sinusoidal steering dynamics test (initial speed 60 km/h) */
// test.SteerDynamicTest(0, 60.f, TestSample::SteerType::sineSteer, csvPath);
return 0;
}
Build Environment
CMakeLists.txt supports generating Visual Studio projects for Windows and Makefiles for Ubuntu.
Build:
-
Windows:
-
Enter the
Builddirectory and rungen_vs_proj_debug.batorgen_vs_proj_release.batto generate a Visual Studio project. -
Open the Visual Studio project and build the
DynamicsTestproject. -
Linux:
-
cd Build -
./gen_make_debug.sh(or./gen_make_release.sh) -
cd build_debug(orcd build_release) -
make -j4
Usage
-
Start SimOne and create a new use case.
-
Create a new ego vehicle (set the control mode to Manual / API Control).
-
Run the use case (select the ego vehicle).
-
Build the test code; the executable is generated in the
bindirectory. -
Run the example program and view the results.