riebl / artery

OMNeT++ V2X simulation framework for ETSI ITS-G5
GNU General Public License v2.0
202 stars 128 forks source link

Print ID, speed and position #309

Closed dnatividade closed 9 months ago

dnatividade commented 9 months ago

For each car, I need to print the information on the terminal: ID: XX | Speed: XX m/s | Position: XX

I was able to print the ID and speed as follows:

    // print ID
    std::cout << "ID: " << mVehicleDataProvider->station_id() << " | ";

    // get Speed
    vanetza::units::Velocity vehicleSpeed = mVehicleDataProvider->speed();
    // conversion
    double speedValue = vehicleSpeed.value();
    // print Speed
    std::cout << "Speed: " << speedValue << " m/s" << std::endl;

And I can get the position like this: mVehicleDataProvider->position() But how do I convert this to a format that can print to the terminal.

PS: I actually need to print to a file on disk, but I want to do that in the terminal first.

riebl commented 9 months ago

The return type of VehicleDataProvider::position() is an artery::Position, see https://github.com/riebl/artery/blob/cedc4ea9f4c05d00c323eddceedf1bedd2e2493e/src/artery/utility/Geometry.h#L27 Hence, you can access the Cartesian coordinate (x in the following example) in meters with mVehicleDataProvider->position().x.value().

dnatividade commented 9 months ago

It worked out! Thank you very much.