Page 1 of 2

Crazyradio in PRX mode

Posted: Tue Nov 18, 2014 2:52 pm
by e-Rok
Thank you to whoenig for pointing out his repository that allows the Crazyradio to be configured in PRX mode. My question is to those who have used this feature. Would I be safe editing main.c in the crazyradio-firmware/firmware/src folder? I would be editing lines such as:

static enum radioMode_e radioMode = RADIO_MODE_PTX;

...

static enum HybridModeState hybridModeState = HybridModeStateTx;

...

radioInit(MODE_PTX);

etc.

Would I still be able to use crazyradio.py? Would I have to do all of my programming in c?

Re: Crazyradio in PRX mode

Posted: Wed Nov 19, 2014 5:09 am
by whoenig
You need to make sure that you always start with RADIO_MODE_PTX mode, otherwise the original crazyradio.py won't work anymore. If you update both, c-code and crazyradio.py, you can do most changes. (Just keep in mind that if you do make a mistake, you might need a JTAG programmer to revive your crazyradio!).

Re: Crazyradio in PRX mode

Posted: Wed Nov 19, 2014 4:35 pm
by e-Rok
Why do I need to change crazyradio.py and the c-code instead of exclusively the c-code? Would it be possible to change the crazyradio to PRX mode after I've started it using only the crazyradio.py driver?

Re: Crazyradio in PRX mode

Posted: Wed Nov 19, 2014 5:26 pm
by whoenig
My crazyradio firmware supports all modes. So you update the crazyradio firmware once and after that you can switch to other modes just by changing crazyradio.py. To keep it compatible with the original crazyflie software, you should just make sure that the crazyradio starts in PTX mode when you plug it in (This is what my firmware currently does). I should have a matching crazyradio.py which can switch those modes somewhere if you need it.

Re: Crazyradio in PRX mode

Posted: Thu Nov 20, 2014 8:46 pm
by e-Rok
If you can send me that crazyradio.py code that would be great. There's something subtle that I'm not understanding, though. How is the firmware connected to/ interacting with the python driver?

Re: Crazyradio in PRX mode

Posted: Fri Nov 21, 2014 3:49 am
by whoenig
The crazyradio firmware has some flags where it can be configured dynamically (e.g. change channel etc.) My firmware added an additional flag to switch to the PRX mode.
I made the updated crazyradio.py available here: https://github.com/whoenig/crazyradio-f ... zyradio.py
This was tested quite a while ago with python 3.x, however it might work with 2.x as well.

Re: Crazyradio in PRX mode

Posted: Mon Nov 24, 2014 4:24 pm
by e-Rok
Is there anything that I need to do to use all of the Crazyradio drivers with python 3.x instead of 2.7? The wiki says to use python 2.7.
Also, thank you for providing your crazyradio driver update. I added a _find_devices() outside of all of the class definitions, although I'm not sure that I have to. I notice that you use the RealCrazyradio as an inner class within the __enter__ method. How can I pass a device as a parameter to the RealCrazyradio inner class, so that I can track which physical Crazyradio device is in a specific mode at a given time?

Re: Crazyradio in PRX mode

Posted: Mon Nov 24, 2014 5:10 pm
by whoenig
If you just need the crazyradio driver you are good to go and it should work with python 3.x out of the box (possibly with python 2.7.x as well, but this is not tested). If you need more from the Bitcraze stack it won't work that easily because the SDK does not work with python 3.x yet. In that case I would recommend porting the crazyradio driver back to python 2.7.x.

The inner class and enter method was only introduced to be able to use a with statement. That ensures that there will be proper cleanup even in case of an error. I had issues previously where I had to reinsert the crazyradio because python would not clean up properly. To introduce arguments, you would add a __init__ function for the Crazyradio class and store whatever parameter you want to provide. Secondly, you would update the constructor of RealCrazyradio. Finally, update line 157 to pass the parameter from Crazyradio to RealCrazyradio.

Re: Crazyradio in PRX mode

Posted: Mon Dec 15, 2014 4:18 pm
by e-Rok
If crazyradio instantiation is done in the radiodriver.py module, or in a test module for that matter, how would I wrap crazyradio usage with a 'with' statement? I want to guarantee that I am using the same crazyradio each time I perform an action from a RadioDriver instance.

Re: Crazyradio in PRX mode

Posted: Mon Dec 15, 2014 4:32 pm
by e-Rok
For example, in the RadioDriver class' connect() method, would the following set self.cradio within the entire scope of the class/corresponding RadioDriverThread class?:

Code: Select all

        if self.cradio is None:
            with Crazyradio(devid=int(uri_data.group(1))) as self.cradio:
                if self.cradio.version >= 0.4:
                    self.cradio.set_arc(10)
                else:
                    logger.warning("Radio version <0.4 will be obsoleted soon!")
                self.cradio.set_channel(channel)
                self.cradio.set_data_rate(datarate)
And what would be the correct way to close in RadioDriver's close() method?