I want to know how to interact with JSON files to define vehicle code

103 views
Skip to first unread message

马浩楠

unread,
Sep 5, 2023, 1:40:54 AM9/5/23
to ProjectChrono
"I'm reading the code for the 'chrono' vehicle library, and I've understood some of the inheritance relationships between the header files. Specifically, the vehicle CPP files are responsible for reading JSON data. I want to know in which header file or method the JSON data is imported into the vehicle. In other words, if I've defined a new vehicle in the form of a JSON file, how do I import my defined vehicle file for simulation or import a demo to see how it behaves? I'm using translation software, so there may be some syntax errors.

Marcel Offermans

unread,
Sep 5, 2023, 3:18:34 AM9/5/23
to projec...@googlegroups.com

On the vehicle tutorials page [1] you see a reference to a demo called "demo_VEH_WheeledJSON" which is a good starting point to learn about how to read a vehicle from JSON files. The demo itself you can see here [2] and around line 50 there is a list of available models that you can try. Note that this demo does need to be changed (C++ source) and recompiled if you want it to load a different vehicle. I'm not aware of a demo that will allow you to simply point to a main vehicle JSON file that will automatically load all other JSON files without any modifications and/or recompiling. That said, if that is the direction you want to go in, that is certainly possible with some changes.

Greetings, Marcel


[1] https://api.projectchrono.org/development/tutorial_table_of_content_chrono_vehicle.html

[2] https://github.com/projectchrono/chrono/blob/main/src/demos/vehicle/wheeled_models/demo_VEH_WheeledJSON.cpp

On 05-Sep-23 7:40, '马浩楠' via ProjectChrono wrote:
"I'm reading the code for the 'chrono' vehicle library, and I've understood some of the inheritance relationships between the header files. Specifically, the vehicle CPP files are responsible for reading JSON data. I want to know in which header file or method the JSON data is imported into the vehicle. In other words, if I've defined a new vehicle in the form of a JSON file, how do I import my defined vehicle file for simulation or import a demo to see how it behaves? I'm using translation software, so there may be some syntax errors.
--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/a235ae7a-2c8a-4a40-9a84-260ca54f965fn%40googlegroups.com.

马浩楠

unread,
Sep 5, 2023, 4:06:58 AM9/5/23
to ProjectChrono
I've read the code and this is my understanding. If I create a new vehicle A, if I want to import JSON I also need to do it like in the demo. 1. Create a class A, inherit Vehicle_Model, and then configure the json path such as virtual std::string VehicleJSON() const override { return "mtv/vehicle/MTV_Vehicle_WalkingBeam.json"; } 2. I use WheeledVehicle vehicle(vehicle::GetDataFile(vehicle_model.VehicleJSON()), vehicle_model.ContactMethod()); in the int function to read Json information
Reply all
Reply to author
Forward
0 new messages