Skip to content

A simple Python package for reading from the PX4Flow optical-flow sensor

License

Notifications You must be signed in to change notification settings

ooorin/PyPX4Flow

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPX4Flow

A simple Python package for reading from the PX4Flow optical-flow sensor

I needed an easy way to access data from the PX4Flow sensor using Python, so I wrote this little package, which you can download from github.
It runs on Windows, Linux, and OS X in Python 2 and 3. As with the other Python packages I've written, the API is very simple. For example, this program prints the computed X and Y flow velocities from the sensor:

from px4flow import PX4Flow

class ShowFlow(PX4Flow):

def update(self):

        print(self.getFlowComp())

if name == 'main':

sensor = ShowFlow('/dev/ttyACM0')

while True:

    sensor.refresh()

As this example shows, PX4Flow is an abstract class that you subclass with a class implementing the update method. To see the other methods avaiable, look at the documentation.

I've also included a program that will display the sensor data in a useful way (depicted above) and log the data to a .CSV file for Excel.

Instructions

You will need:

  1. A PX4Flow kit. I recommend following the Image Quality and Output instructions to make sure the sensor is working properly.
  2. The ability to program in Python

  3. The PySerial package installed on your computer. Like many people, I found it easiest to install from source.

  4. Administrator (root) privileges on your computer

  5. The PyPX4Flow repository.

Once you've downloaded the repositry, use a terminal (Linux or OS X) or command shell (Windows) to change to the directory where you put it, and issue the command

  python setup.py install

On Linux or OS X, you may need to issue this command as root:

  sudo python setup.py install

Then you should be able to run the px4flow_display.py program in the display folder.

Known issues

  1. Some users have reported a bug in which the display program crashes immediately with a stack trace ending in the following output:
     File "/usr/local/lib/python2.7/dist-packages/px4flow/mavlink_parser.py", line 99, in unpack
        return struct.unpack(fmt, self.msg[lo:hi])[0:n]
    error: unpack requires a string argument of length 4
    

    So far this bug seem to occur only with versions of Python below 2.7.5, so I've added a branch to the repository that should work with such earlier versions. If you are running 2.7.5 or above and still experience this problem, please let me know.

  2. At startup, the display program occasionally computes and displays bogus large values for the distance traveled. This may have to do with the fact that I am not using the checksum to validate each message.

Copyright and licensing

Copyright and licensing information (Gnu LGPL) can be found in the header of each source file.

Acknowledgments

This work was supported in part by a Commonwealth Research Commercialization Fund grant from the Center for Innovative Technology (CRCF #MF14F-011-MS) and a Lenfest summer research grant from Washington and Lee University.

About

A simple Python package for reading from the PX4Flow optical-flow sensor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%