riebl / artery

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

Vehicle control #257

Closed ansb5 closed 1 year ago

ansb5 commented 2 years ago

Hello @riebl.

I'm trying to control vehicles via VehicleController. I'm calling VehicleController.h functions in CaService to stop a car. When I use get function it works perfectly:

auto& vehicle = getFacilities().get_const<traci::VehicleController>() vehicle.getSpeed().value()

But when I try the same with set it doesn't work: vehicle.setSpeed(0) //Stop the vehicle

When I write the object vehicle. I get the get functions in the suggestions but not the set functions. And of course, when i simulate doesn't work. What can be the problem?

riebl commented 2 years ago

When you say "it doesn't work" you mean it does not even compile, right? VehicleController::setSpeed expects a Boost.Unit quantity, i.e. 0 is not sufficient. You need to pass 0.0 * boost::units::si::meter_per_second, for example.

ansb5 commented 2 years ago

Thanks for your answer @riebl

Yes, I meant that it did not compile.

Now I tried these two things:

  1. vehicle.setSpeed(0.0 * boost::units::si::meter_per_second);
  2. static const vanetza::units::Velocity stop {0.0 * boost::units::si::meter_per_second}; vehicle.setSpeed(stop);

But I get the same error message:

image

ansb5 commented 2 years ago

Sorry I didn't meant to close the issue

riebl commented 2 years ago

You cannot call non-const methods on objects via const references. VehicleController::setSpeed is a non-const method whereas getSpeed is a const method. You can retrieve a non-const reference to VehicleController by getFacilities().get_mutable<traci::VehicleController>().