Changing Parameters in C++

Firmware/software/electronics/mechanics
Post Reply
rb13g11
Beginner
Posts: 3
Joined: Sat Dec 07, 2013 7:42 pm

Changing Parameters in C++

Post by rb13g11 »

Hi

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)
I've adapted the function SendSetpoint to send parameters instead, using Port 2 and Channel 3:

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 successfully retrieves the element ID(varid) and places it in the second byte of the packet after the Header, and puts the values of althold afterwards.
This doesn't work. Could anyone give me advice as to what the problem is?

Thank you in advance
Kind Regards
Rushin
adiego73
Beginner
Posts: 2
Joined: Wed Sep 18, 2013 1:21 pm

Re: Changing Parameters in C++

Post by adiego73 »

Hi!

Have you solved this? I'm trying to do the same, but I cannot accomplish it :(

Thanks in advance!

Diego.
Post Reply