Skip to content
Snippets Groups Projects
Commit 0c0dc209 authored by Zach Eisele's avatar Zach Eisele
Browse files

add attitude and stop setpoint

parent a3aa01fc
No related branches found
No related tags found
3 merge requests!76lots of gui updates,!75Lost of gui updates,!74lots of gui updates among others
......@@ -338,41 +338,45 @@ bool CCrazyflie::parseReceivedUserCommand() {
float yaw = build_float(&command.payload[17]);
float fthrust = build_float(&command.payload[5]);
float ftime = build_float(&command.payload[1]);
int nSize = 4 * sizeof(float) + sizeof(char);
char cBuffer[nSize];
if(command.payload[0] == 1) {
short thrust = (short) fthrust;
this->sendSetpoint(roll, pitch, yaw, thrust);
cBuffer[0] = 9;
}
else if(command.payload[0] == 2) {
int nSize = 4 * sizeof(float) + sizeof(char);
char cBuffer[nSize];
cBuffer[0] = 8;
memcpy(&cBuffer[0 * sizeof(float) + 1], &roll, sizeof(float));
memcpy(&cBuffer[1 * sizeof(float) + 1], &pitch, sizeof(float));
memcpy(&cBuffer[2 * sizeof(float) + 1], &yaw, sizeof(float));
memcpy(&cBuffer[3 * sizeof(float) + 1], &fthrust, sizeof(float));
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 7);
crtpPacket->setChannel(0x00);
int milliseconds = ftime*1000;
CCRTPPacket *crtpReceived = NULL;
if(ftime == 0) {
}
else {
break;
}
memcpy(&cBuffer[0 * sizeof(float) + 1], &roll, sizeof(float));
memcpy(&cBuffer[1 * sizeof(float) + 1], &pitch, sizeof(float));
memcpy(&cBuffer[2 * sizeof(float) + 1], &yaw, sizeof(float));
memcpy(&cBuffer[3 * sizeof(float) + 1], &fthrust, sizeof(float));
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, 7);
crtpPacket->setChannel(0x00);
int milliseconds = ftime*1000;
CCRTPPacket *crtpReceived = NULL;
if(ftime == 0) {
crtpReceived = m_crRadio->sendPacket(m_nRadioChannel, crtpPacket, this);
}
else {
auto start = std::chrono::high_resolution_clock::now();
auto timeNow = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow-start);
while(duration.count() < milliseconds) {
usleep(10);
crtpReceived = m_crRadio->sendPacket(m_nRadioChannel, crtpPacket, this);
timeNow = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow-start);
}
else {
auto start = std::chrono::high_resolution_clock::now();
auto timeNow = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow-start);
while(duration.count() < milliseconds) {
usleep(10);
crtpReceived = m_crRadio->sendPacket(m_nRadioChannel, crtpPacket, this);
timeNow = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow-start);
}
}
delete crtpPacket;
cBuffer[0] = 0;
nSize = sizeof(char);
crtpPacket->setData(cBuffer, nSize);
crtpReceived = m_crRadio->sendPacket(m_nRadioChannel, crtpPacket, this);
}
delete crtpPacket;
break;
}
case ACMD_GETLOGFILE:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment