AirSim icon indicating copy to clipboard operation
AirSim copied to clipboard

Question: How to get car state in C++?

Open dehavenm opened this issue 8 years ago • 6 comments

I'm working on a C++ ROS node to interface a ROS package with a car in Airsim. To properly control the car, I would need to be able to read the car's speed and angular velocity, then compare them to the commanded values coming through the ROS messages. The example code mentions a client.getCarState() command for Python, but nothing in the documentation mentions anything equivalent for C++. How do I get the car's state through C++? Thank you.

dehavenm avatar Sep 14 '18 23:09 dehavenm

For C++ you use CarRpcLibClient. Method is

CarApiBase::CarState getCarState(const std::string& vehicle_name = "")

APIs: https://github.com/Microsoft/AirSim/blob/77f84fff2c60d9b3d361bc2d2121cf10436d0996/AirLib/include/vehicles/car/api/CarRpcLibClient.hpp#L19

Example: https://github.com/Microsoft/AirSim/blob/77f84fff2c60d9b3d361bc2d2121cf10436d0996/HelloCar/main.cpp#L19

sytelus avatar Sep 17 '18 18:09 sytelus

No method by the name getCarState appears in either of those files.

dehavenm avatar Sep 17 '18 21:09 dehavenm

@dehavenm - were you able to use the API (it is defined).. tho there doesn't seem to be a sample for it quite as yet. Perhaps you can post it, if you managed to work it out.

bimalkmehta avatar Dec 18 '18 21:12 bimalkmehta

@dehavenm did you find how to use getCarState() in C++?

jonyMarino avatar Aug 12 '20 19:08 jonyMarino

No, I never was able to find that information.

dehavenm avatar Aug 12 '20 20:08 dehavenm

Hi @dehavenm! Yo can see that method in the file commented by stylus but three lines below. I tried adding this line CarApiBase::CarState state = client.getCarState(); to HelloCar/main.cpp successfully. Let me know if you need more help. Regards

jonyMarino avatar Sep 17 '20 16:09 jonyMarino