Page 1 of 1

PC Client Code no Longer Works the Same

Posted: Thu Apr 14, 2016 5:08 pm
by jackemoore
Hi,

In my application, I transfer packet data from the Crazyflie 2 to the PC client using crtp port 0x06.
My PC client source code works successfully using 2015.08 release and Python 2.7. In switching to release 2016.2 using Python 3.4, the same code works differently. Packet data being sent from the PC client to the Crazyflie looks ok. Packet data sent from the Crazyflie to the PC client is different. I'd appreciate your help with this problem.

A snippet of the python source in question is as follows:
import struct
from cflib.utils.callbacks import Caller
from cflib.crtp.crtpstack import CRTPPacket, CRTPPort
from PyQt4.QtCore import pyqtSlot, pyqtSignal
class Ablock:
receivedChar = Caller()
def __init__(self, crazyflie):
"""
Initialize the ablock and register it to receive data from the copter.
"""
self.cf = crazyflie
self.cf.add_port_callback(CRTPPort.ABLOCK, self.incoming)
def incoming(self, packet):
ablock_text = "%s" % struct.unpack("%is" % len(packet.data),
packet.data)
self.receivedChar.call(ablock_text)
print ("indata %s" % ablock_text)

Foe example, I receive
ablock_text == "<S>\n" using Python 2.7 PC client (release 2015.08)
but receive
ablock_text == "b'<S>\n''" using Python 3.4 PC client (release 2016.02)

I hope this is enough information to understand the problem.

Re: PC Client Code no Longer Works the Same

Posted: Thu Apr 14, 2016 10:43 pm
by jackemoore
Hi,
I've attempted to change the above sinippet of code that has worked using 2015.08 release baseline to the following code that hopefully is more compatible with the 2016.02 release baseline. I can't get pass the run time failure that says that ablock doesn't have the attribute update. Any suggestions regarding how to get past this and if I'm going in the right direction would be appreciated.

A snippet of the python source revision attempt is as follows:
from PyQt4.QtCore import pyqtSlot, pyqtSignal
class Ablock:
def __init__(self, helper):
self.helper = helper
self.update.connect(self.incoming)
self.helper.cf.ablock.receivedChar.add_callback(self.update.emit)
def incoming(self, text):
ablock_text = text
self.receivedChar.call(ablock_text)
print ("indata %s" % ablock_text)

[Solved] PC Client Code no Longer Works the Same

Posted: Fri Apr 15, 2016 11:10 pm
by jackemoore
Hi,

I tried a different approach and this worked!!

A snippet of the python source containing my fix is as follows:
import struct
from cflib.utils.callbacks import Caller
from cflib.crtp.crtpstack import CRTPPacket, CRTPPort
from PyQt4.QtCore import pyqtSlot, pyqtSignal
class Ablock:
receivedChar = Caller()
def __init__(self, crazyflie):
self.cf = crazyflie
self.cf.add_port_callback(CRTPPort.ABLOCK, self.incoming)
def incoming(self, packet):
ablock_text = packet.data.decode("UTF-8")
self.receivedChar.call(ablock_text)
print ("indata %s" % ablock_text)

Now I properly receive:
ablock_text == "<S>\n" using Python 2.7 PC client (release 2015.08) and using Python 3.4 PC client (release 2016.02)