AirSim icon indicating copy to clipboard operation
AirSim copied to clipboard

Getting Acceleration

Open hngenc opened this issue 9 years ago • 6 comments

Is there an API call to get the drone's acceleration? I'd like something like the getVelocity() function in RpcLibClient.hpp

The main reason I want this is because I'd like to populate ROS IMU messages. I can populate the velocity and orientation fields myself, but not the acceleration fields.

hngenc avatar Sep 26 '17 19:09 hngenc

Maybe I can help you if you provide more information:

  • Which acceleration do you want? Ground truth from the physics engine or simulated estimations from the IMU?
  • What is your setup? Software in the loop or hardware in the loop?

Ricardus312 avatar Sep 27 '17 07:09 Ricardus312

Thanks for your response, @Ricardus312!

  • I'd like simulated estimations from the IMU.
  • I can use either SITL or HITL, although I'd prefer a solution that works with the simple_flight_controller.

hngenc avatar Sep 27 '17 17:09 hngenc

Well, it seems we both have the same problem (https://github.com/Microsoft/AirSim/issues/476). I haven't figured out how to get the acceleration from the IMU yet, but I think I am pretty close from it. I will share with you all what I have discovered until now, maybe it could be useful for you:

  • SitL setup (Simple Flight). On simple flight, if you press 'R' button during simulation, it starts to record flight images and writing a log file (in Windows, it saves to User\Documents\AirSim\ThisDate). That log file outputs the position and orientation of the drone, sampling several times per second, and you can modify easily the code of the log function to make it output velocities and accelerations, both linear and angular. Here is how to get velocities and accelerations (ground truth) in simple flight:

    • Go to the directory of your Unreal project (usually at \Documents\Unreal Projects\Project_name\ in Windows, but if you are using the default Blocks environment that comes with AirSim, it could be on \AirSim\Unreal\Environments\Blocks)

    • Open the 'Project.sln' file with Visual Studio (e.g. if you are using the default blocks environment, the file is Blocks.sln).

    • On the solutions explorator, navigate to \Games\Project\Plugins\AirSim\Source\Recording\RecordingFile.cpp" and open it (other option is going directly to the directory "..\Project_name\Plugins\AirSim\Source\Recording" and open with Visual Studio the file "RecordingFile.cpp".

    • About line 50 of that file, you will see this code: line.append(std::to_string(timestamp_millis)).append("\t") .append(std::to_string(kinematics.pose.position.x())).append("\t") .append(std::to_string(kinematics.pose.position.y())).append("\t") .append(std::to_string(kinematics.pose.position.z())).append("\t") .append(std::to_string(kinematics.pose.orientation.w())).append("\t") .append(std::to_string(kinematics.pose.orientation.x())).append("\t") .append(std::to_string(kinematics.pose.orientation.y())).append("\t") .append(std::to_string(kinematics.pose.orientation.z())).append("\t")

      All you have to do is add to that code these lines, and you will get all the velocities and accelerations (ground truth): .append(std::to_string(kinematics.twist.linear.x())).append("\t") .append(std::to_string(kinematics.twist.linear.y())).append("\t") .append(std::to_string(kinematics.twist.linear.z())).append("\t") .append(std::to_string(kinematics.twist.angular.x())).append("\t") .append(std::to_string(kinematics.twist.angular.y())).append("\t") .append(std::to_string(kinematics.twist.angular.z())).append("\t") .append(std::to_string(kinematics.accelerations.linear.x())).append("\t") .append(std::to_string(kinematics.accelerations.linear.y())).append("\t") .append(std::to_string(kinematics.accelerations.linear.z())).append("\t") .append(std::to_string(kinematics.accelerations.angular.x())).append("\t") .append(std::to_string(kinematics.accelerations.angular.y())).append("\t") .append(std::to_string(kinematics.accelerations.angular.z())).append("\t")

    • Also, if you don't want to get the screen captures, you only have to replace (or comment) the line 21 of that file: imageSavedOk = FFileHelper::SaveArrayToFile(image_data, *filePath); For this other one: imageSavedOk = true;

    • Regarding the IMU accelerations, if you read the paper (https://github.com/Microsoft/AirSim/blob/master/docs/paper/main.pdf), in the point 3.4 it says that

    "AirSim offers sensor models for accelerometer, gyroscope, barometer, magnetometer and GPS. All our sensor models are implemented as C++ header-only library and can be independently used outside of AirSim"

    So in theory, it is possible to write a code that just imports the IMU sensor, calls a method and gets the angular velocities and accelerations from it. Unfortunately, I am not a C++ programmer (yet) and my understanding of the code is very limited, so I still haven't been able to do this by myself. The code for the sensors is at "..\Project_name\Plugins\AirSim\Source\AirLib\include\sensors". Check out the code in "..\imu\ImuSimple.hpp". I think that somebody with good C++ skills could easily modify the code in "RecordingFile.cpp" to call the IMU ang get its outputs, but I still haven't that "good C++ skills".

  • For the Hardware int the Loop setting, theoretically it is possible to get the MavLink messages between your external flight controller hardware and the simulator using an external program called Px4LogViewer, look at the docs (https://github.com/Microsoft/AirSim/blob/master/docs/px4_logging.md).

These are all my insights until now, I hope this maybe useful for you. If you discover before me how to get that IMU data, please share with me!!!

Regards

Ricardus312 avatar Sep 28 '17 08:09 Ricardus312

We have added new APIs to get angular velocity (along with other kinematics quantities). Please see https://github.com/Microsoft/AirSim/blob/master/docs/apis.md#getmultirotorstate.

For cars, this is available in getCarState API.

Note that above are ground truth quantities and you should not use it as sensor data. We'll be adding sensor APIs as well soon.

sytelus avatar Dec 16 '17 04:12 sytelus

Hey @sytelus , are there any news regarding sensor API's? I could not find a specific issue for that yet.

Fab7c4 avatar Mar 04 '18 14:03 Fab7c4

Is there any updating about add adding sensor APIs (For IMU & GPS etc)?

DrifterFun avatar Nov 13 '18 12:11 DrifterFun