libcflie icon indicating copy to clipboard operation
libcflie copied to clipboard

setThrust is work or not?

Open qwertyuiop7370 opened this issue 8 years ago • 3 comments

Hello I am newbie in crazyflie2. I built your code in windows and it works in mainly. But I have a trouble with setting thrust from program. I do the next

int main(int argc, char **argv) {
    CCrazyRadio crRadio("radio://0/80/250K");
    if(crRadio.startRadio())
    {
        CCrazyflie cflieCopter(&crRadio);
        cflieCopter.setThrust(10001);
        cflieCopter.setSendSetpoints(true);
        for (int i=0;cflieCopter.cycle()&&i<100; ++i)
        {
            std::cout << cflieCopter.yaw() << " " << cflieCopter.pitch() << " " << cflieCopter.roll() << " " << cflieCopter.thrust() << " " << cflieCopter.batteryLevel()<< std::endl;
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
            // Range: 10001 - (approx.) 60000
            cflieCopter.setThrust(10001+i*20);
        }
    } else {
        std::cerr << "Could not connect to dongle. Did you plug it in?" << std::endl;
    }
}

I get

Opening radio 0/80/250K
Got device version 0.83
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Registered logging block `stabilizer'
Registered logging block `gyroscope'
Registered logging block `accelerometer'
Registered logging block `battery'
Registered logging block `magnetometer'
Registered logging block `altimeter'
0 0 0 0 0
-2.03507 0.462907 0.134263 0 3.73724
-2.03507 0.462907 0.134263 0 3.73724
-2.03507 0.462907 0.134263 0 3.73724
...
-1.9969 0.464878 0.142745 0 3.74252
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.
libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.

I am not able to set thrust and engines are not work. Could you advice me, whatI do incorrectly?

qwertyuiop7370 avatar Sep 18 '16 11:09 qwertyuiop7370

Hi @qwertyuiop7370, thanks for getting in touch.

This could be related to this other issue where the setThrust command doesn't work until you sent a thrust of 0. You could try that and see whether this solves your problem. This is related to changes in the firmware from Crazyflie 1.0 to Crazyflie 2.0 as pointed out by others in that issue thread.

libcflie was specifically written for the Crazyflie 1.0 (as 2.0 wasn't out back then) and doesn't account for weirdness in compatibility yet. Let me know if the workaround works for you.

Apart from that, I have never seen the error message you mentioned:

libusb: warning [winusbx_submit_control_transfer] ControlTransfer failed: [87] The parameter is incorrect.

Given that winusbx is mentioned, I guess this is a compatibility problem between the libusb I used and the one present on your windows system. Can you verify that libusb's version? libcflie was built using, compiled, and tested with libusb-1.0. This could be a versioning problem.

Cheers, Jan

fairlight1337 avatar Sep 18 '16 12:09 fairlight1337

Win7 x64, libusb from here https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.20/. Used WinGW64 static lib. All built with mingw x86_64-5.2.0-posix-seh-rt_v4-rev1. I set libusb_set_debug(m_ctxContext, LIBUSB_LOG_LEVEL_INFO);

crazyflie client from original site is work, but without Joystic the copter is not controlled. (i tried with Android client - the copter flies OK)

These libusb warnings are received somewhere in destructors after cycle was done.

I tried with CCrazyflie cflieCopter(&crRadio); cflieCopter.setThrust(0); Result is some as above.

qwertyuiop7370 avatar Sep 18 '16 12:09 qwertyuiop7370

Hi,

Recently, I bought Crazyflie 2.0 and I am trying to setup the environment using libcflie. I have now managed to get the 'setThrust' function working by modifying CCrazyflie.h and CCrazyflie.cpp. I hope this can help you slove the issue.

-------- CCrazyflie.h----------

class CCrazyflie {
 private:
	bool m_bLocked; //cspk: add this member variable
...
};

-------- CCrazyflie.cpp---------

CCrazyflie::CCrazyflie(CCrazyRadio *crRadio) {
	m_bLocked = true; //cspk: initialize it in the constructor
        ....
}
bool CCrazyflie::sendSetpoint(float fRoll,float fPitch,float fYaw,unsigned short sThrust) {
	fPitch = -fPitch;

	if(m_bLocked) sThrust = 0; //cspk: add this line

	int nSize = 3 * sizeof(float) + sizeof(unsigned short);
	char cBuffer[nSize]; 
	memcpy(&cBuffer[0 * sizeof(float)],&fRoll,sizeof(float));
	memcpy(&cBuffer[1 * sizeof(float)],&fPitch,sizeof(float));
	memcpy(&cBuffer[2 * sizeof(float)],&fYaw,sizeof(float));
	memcpy(&cBuffer[3 * sizeof(float)],&sThrust,sizeof(unsigned short));

	CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer,nSize,3);
	CCRTPPacket *crtpReceived = m_crRadio->sendPacket(crtpPacket);

	delete crtpPacket;
	if(crtpReceived != NULL) {
		delete crtpReceived;
		m_bLocked = false;  //cspk: Motors are unlocked. Now we can use setThrust!!
		return true;
	}
	else {
		return false;
	}
}

cspk17 avatar Feb 01 '18 01:02 cspk17