I've been using fairlight1337s C++ lib to control the Crazyflie from my PC, because I don't have any experience in python(even though my programming skills in C are pretty low). Available at https://github.com/fairlight1337/libcflie
I want to be able to change parameters, mainly turn altitude hold on or off. I've found the function that sends the Parameter packets in param.py:
Code: Select all
def set_value(self, complete_name, value):
"""
Set the value for the supplied parameter.
"""
element = self.toc.get_element_by_complete_name(complete_name)
if not element:
logger.warning("Cannot set value for [%s], it's not in the TOC!",
complete_name)
elif element.access == ParamTocElement.RO_ACCESS:
logger.debug("[%s] is read only, no trying to set value", complete_name)
else:
varid = element.ident
pk = CRTPPacket()
pk.set_header(CRTPPort.PARAM, WRITE_CHANNEL)
pk.data = struct.pack('<B', varid)
pk.data += struct.pack(element.pytype, eval(value))
self.param_updater.request_param_setvalue(pk)
Code: Select all
bool CCrazyflie::sendParam(bool althold) {
unsigned char varid = m_tocParameters->idForName("flightmode.althold");
int nSize = sizeof(unsigned char) + sizeof(bool);
char cBuffer[nSize];
memcpy(&cBuffer[0], &varid, sizeof(unsigned char));
memcpy(&cBuffer[1 * sizeof(unsigned char)], &althold, sizeof(bool));
CCRTPPacket *crtpPacket = new CCRTPPacket(cBuffer, nSize, PARAMPORT, WRITECHANNEL);
CCRTPPacket *crtpReceived = m_crRadio->sendPacket(crtpPacket);
delete crtpPacket;
if(crtpReceived != NULL) {
delete crtpReceived;
return true;
} else {
return false;
}
}
This doesn't work. Could anyone give me advice as to what the problem is?
Thank you in advance
Kind Regards
Rushin