Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Airsim API moveByRollPitchYawThrottleAsync with px4 HITL #2878

Closed
ghost opened this issue Jul 25, 2020 · 2 comments
Closed

Airsim API moveByRollPitchYawThrottleAsync with px4 HITL #2878

ghost opened this issue Jul 25, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 25, 2020

Hi,

I am trying to control a piwhawk with px4 firmware v 1.10.1 in HITL (airsim recently updated) mode remotely with a joystick.
I have one program grabbing the input of the joystick and sending them through the network with a library named ingescape and based on zeromq (custom one you can take a look here https://ingescape.com/). I have a second one handle them by a callback mechanism and passing them to the px4 by the API function moveByRollPitchYawThrottleAsync.

It perfectly works as expected with simpleFlight. When I switch to px4 HITL config only the throttle value seems to be recognized. So API function is recognized. But Pitch, roll, yaw have no effect. If I use QGroundControl it works perfectly fine.

Could you please let me know if I missed something to use the API with HITL ?
I can't figure out why the API function partially works in HITL and why it works perfectly with simpleflight.

I copied the piece of code which is responsive of grabbing joystick input and passing the API command to the px4 bellow.

if you want to investigate how I am calling the API function.

Any help will be very appreciated !

#include "droneserverbridgegui.h"

#include <QApplication>
#include <QtGui>
#include <QtCore>
#include <QMessageBox>
#include <QStringList>
#include <QDebug>
#include <iostream>
#include <QObject>


DroneServerBridgeGUI *w;

bool isArmed = false;
bool debugWithoutClient = false;
double pitch = 0;
double roll = 0;
double yaw = 0;
double throttle = 0;

extern "C" {
    #include "ingescape/ingescape.h"
}

static QString UAVIpToConnect = "127.0.0.1"; // The local Ip of ZEUS when Unreal engine is AirSim plugin is running 192.168.88.137
static int portNumber = 41451; //ApiServerPort. It is fixed because it is hard coded into the source code of AiSim 41451

typedef common_utils::FileSystem FileSystem;

msr::airlib::MultirotorRpcLibClient * client = nullptr;

void droneArmCallbck(iop_t iopType, const char *name, iopType_t valueType, void *value, size_t valueSize, void *myData)
{
    bool droneArmState = igs_readInputAsBool(name);
    if(droneArmState == true)
    {
        isArmed = true;
    }
    else
    {
        isArmed = false;
    }

    if(w)
        {
            QMetaObject::invokeMethod(w,
                                    "setDroneArmState",
                                    Qt::QueuedConnection,
                                    Q_ARG(bool, droneArmState));
        }

    if(!debugWithoutClient){
        client->armDisarm(droneArmState);
        client->enableApiControl(true);
    }
}

void DronePitchRollYawCallback (iop_t iopType, const char *name, iopType_t valueType, void *value, size_t valueSize, void *myData)
{

    //"0.125;0.524;0.65"
    QString dronePitchRollYawThrottle = igs_readInputAsString(name);
    QStringList List;
    dronePitchRollYawThrottle = dronePitchRollYawThrottle.replace(",",".");
    List = dronePitchRollYawThrottle.split(";");
    pitch = List[0].toDouble();
    roll = List[1].toDouble();
    yaw = List[2].toDouble();
    throttle = List[3].toDouble();

    if(w && isArmed == true)
        {
            QMetaObject::invokeMethod(w,
                                    "setDronePitchRollYawThrottle",
                                    Qt::QueuedConnection,
                                    Q_ARG(double, pitch),
                                    Q_ARG(double, roll),
                                    Q_ARG(double, yaw),
                                    Q_ARG(double, throttle));
        }
    if ((!debugWithoutClient) &&(isArmed == true)){
            qInfo() <<"New Drone's orientation : Pitch = " << List[0] << "Roll = " << List[1] << "Yaw = " << List[2] << "Throttle = " << List[3];

            client->moveByRollPitchYawThrottleAsync(roll, pitch, yaw, throttle, 1);
    }
}

void observeAllInputs(){
    igs_observeInput("Drone_Arm_Disarm_State",droneArmCallbck, nullptr);
    igs_observeInput("Drone_Pitch_Roll_Yaw_Throttle",DronePitchRollYawCallback, nullptr);
}

void createDefAndStartIgsLayer()
{
    igs_setVerbose(true);
    igs_setLicensePath("C:\\Users\\Patxi\\Documents\\IngeScape\\licenses\\");

    //Ingescape layer initialization
    igs_setAgentName("DroneServerBridgeGUI");
    igs_createOutput("img_bytes", IGS_DATA_T, nullptr, 0);
    igs_createInput("Drone_Arm_Disarm_State", IGS_BOOL_T, nullptr, 0);
    igs_createInput("Drone_Pitch_Roll_Yaw_Throttle", IGS_STRING_T, nullptr, 0);

    //Ingescape input mapping
    igs_addMappingEntry("Drone_Arm_Disarm_State", "UAV-Cockpit-VR", "Joystick_arm_disarm_state");
    igs_addMappingEntry("Drone_Pitch_Roll_Yaw_Throttle", "UAV-Cockpit-VR", "Joystick_pitch_roll_yaw_throttle");

    //Ingescape start Agent
    igs_startWithDevice("Wi-Fi", 5671);

    //Observe all inputs
    observeAllInputs();
}

void iniatializeDroneClient(){
    //Initialization connection to drone
     client = new msr::airlib::MultirotorRpcLibClient(UAVIpToConnect.toLatin1().data(), portNumber);
     client->confirmConnection();
     client->enableApiControl(true);
}
int main(int argc, char *argv[])
{


    QApplication a(argc, argv);
    w = new DroneServerBridgeGUI();
    w->show();


    if(!debugWithoutClient){
        //Initialize the drone client
        iniatializeDroneClient();

        w->setDroneClient(client);
    }

    createDefAndStartIgsLayer();

    return a.exec();
}
@ghost
Copy link
Author

ghost commented Jul 25, 2020

Additional information : I am running everything in Win10. Airsim and airlib code at "Reduced warning level in Unity build (#2672)" commit 2020/05/09 at 12:02

@ghost
Copy link
Author

ghost commented Aug 6, 2020

Ok I found out the problem by going into the source code.
Previously I was using a function named moveByAngleThrottle. This one was taking as parameter pitch,roll,yaw and throttle with normalized values between -1 and 1 (0 and 1 for the throttle). It was working perfectly with simpleflight & PX4 HITL in the same way.
Now with the new function moveByRollPitchYawThrottleAsync you need to use normalised values for simpleflight as previously BUT you need to use degrees for PX4 HITL for the pitch,roll and yaw.
So shame the header RpcLibClientBase.hpp is not commented and that it doesn't exist a real API documentation.
Whatever this issue is closed.

@ghost ghost closed this as completed Aug 6, 2020
This issue was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants