C++API controls the configuration of Airsim-static link library

1. Control the drone effect demonstration in Airsim through C++ API

                                                    console screenshot

                                                     Screenshots in UE4

2. Include the correct static link library

1. Find the required link library

Refer to Airsim official website: C++ APIs - AirSim

As can be seen from the screenshot of the official website guidance above, the header file we need has four parts:

①include

②AirLib/include

③AirLib/deps/rpclib/include

④AirLib/deps/eigen3

⑤AirLib/deps/MavLinkCom/include

The static link library we need has the following three parts:

①rpc.lib

②AirLib.lib

③MavLinkCom.lib

Therefore, we can find the AirLib project from the official git clone file, copy the content in my screenshot to our own project, and then configure the static link library according to the above configuration, and include the correct header file.

2. Additional include directory

Refer to my screenshot above to configure and include the correct header file

3. Configure additional library directories

Refer to the screenshot above to configure the directory of the additional library (where the static link library is located)

4. Configure additional dependencies

Refer to my screenshot above to configure additional dependencies

3. Write control code

The code is actually an official example of copying, and some comments are added below:

#include <iostream>
#include "vehicles/multirotor/api/MultirotorRpcLibClient.hpp"

int main()
{
    msr::airlib::MultirotorRpcLibClient client;

    std::cout << "Press Enter to enable API control\n"; std::cin.get(); // 按下回车键开启API控制
    client.enableApiControl(true);

    std::cout << "Press Enter to arm the drone\n"; std::cin.get(); // 按下回车解锁无人机
    client.armDisarm(true);

    std::cout << "Press Enter to takeoff\n"; std::cin.get(); // 按下回车键起飞无人机
    client.takeoffAsync(5)->waitOnLastTask();

    std::cout << "Press Enter to move 5 meters in x direction with 1 m/s velocity\n"; std::cin.get(); // 按下回车键往前飞行
    auto position = client.getMultirotorState().getPosition(); // from current location
    client.moveToPositionAsync(position.x() + 5, position.y(), position.z(), 1)->waitOnLastTask();

    std::cout << "Press Enter to land\n"; std::cin.get(); // 按下回车键降落无人机
    client.landAsync()->waitOnLastTask();

    std::cout << "Press Enter to disenable\n"; std::cin.get(); // 按下回车键关闭API控制
    client.enableApiControl(false);

    return 0;
}

Fourth, the end

The above are all the steps, so far we can control the drone or car in Airsim through a C++ program. In the future, these codes will be encapsulated into classes in UE4. (Or use Qt, press different buttons, and control airsim by calling different APIs)

Guess you like

Origin blog.csdn.net/hu853712064/article/details/130650668