juanmanzanero / fastest-lap

Fastest-lap is a vehicle dynamics simulator. It can be used to understand vehicle dynamics, to learn about driving techniques, to design car prototypes, or just for fun!
MIT License
575 stars 43 forks source link

libfastestlapc: new functionality: export output names #30

Closed juanmanzanero closed 2 years ago

juanmanzanero commented 2 years ago

In the C++ core library, a new function is available as

limebeer2014f1<double>::curvilinear_p car(database);
const auto map = car.get_outputs_map()

this get_outputs_map() returns a std::unordered_map<std::string,scalar> with all the possible outputs that can be requested to a Dynamic_model_t. The map key is the name of the outputs, for example:

front-axle.right-tire.position.z
front-axle.left-tire.lambda
front-axle.right-tire.force.y
front-axle.right-tire.velocity.z
front-axle.left-tire.position.x
front-axle.left-tire.position.y
chassis.position.x
front-axle.right-tire.position.x
rear-axle.left-tire.force.y
front-axle.left-tire.dissipation
rear-axle.right-tire.force.z
front-axle.left-tire.velocity.z
rear-axle.right-tire.dissipation
front-axle.left-tire.position.z
chassis.torque.z
chassis.force.x
front-axle.left-tire.velocity.y
front-axle.left-tire.velocity.x
rear-axle.right-tire.velocity.y
chassis.position.y
front-axle.right-tire.dissipation
front-axle.right-tire.force.x
chassis.acceleration.y
chassis.force.y
front-axle.left-tire.force.x
chassis.torque.x
rear-axle.right-tire.lambda
front-axle.left-tire.force.z
chassis.torque.y
chassis.acceleration.yaw
rear-axle.left-tire.force.z
front-axle.left-tire.force.y
rear-axle.right-tire.position.x
rear-axle.left-tire.dissipation
rear-axle.left-tire.lambda
rear-axle.left-tire.position.z
front-axle.right-tire.position.y
rear-axle.left-tire.position.x
front-axle.right-tire.lambda
rear-axle.left-tire.velocity.x
chassis.acceleration.x
rear-axle.left-tire.velocity.z
rear-axle.left-tire.position.y
rear-axle.right-tire.position.y
front-axle.right-tire.velocity.x
rear-axle.right-tire.velocity.z
chassis.force.z
rear-axle.right-tire.force.x
front-axle.right-tire.force.z
rear-axle.left-tire.velocity.y
front-axle.right-tire.velocity.y
rear-axle.left-tire.force.x
rear-axle.right-tire.position.z
rear-axle.right-tire.velocity.x
rear-axle.right-tire.force.y

The task is to implement two functions in libfastestlapc.cpp with prototype:

int vehicle_get_number_of_output_variables(const char* vehicle_name);

void vehicle_get_output_variable_names(char** output_names, const int n_outputs, const int n_char, const char* vehicle_name);

The first one simply computes the map for the vehicle, and returns the number of output variables in the map (i.e. the map size). The second one, returns all the key names into output_names.

no new shall be executed inside the function. In fact, the caller provides the memory associated to the char** through n_outputs (the return from int vehicle_get_number_of_output_variables(const char* vehicle_name);) and n_char (a sufficiently big number).

Hence char** is equivalent to char[n_outputs][n_char]