Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples for Python client library #53

Merged
merged 5 commits into from
Mar 24, 2015
Merged

Conversation

fnoble
Copy link
Contributor

@fnoble fnoble commented Mar 24, 2015

An example of how we may want to incorporate examples using the python client library.

Adds two examples:

  • Simple example of reading and printing BASELINE_NED messages
  • Sending SBP over UDP

In this case I needed something to send SBP over UDB so it can be fed into MAVProxy and eventually make its way into the telemetry stream up to a ArduPilot quadcopter (so we can use just one pair of radios for corrections and telemetry).

@fnoble
Copy link
Contributor Author

fnoble commented Mar 24, 2015

@mookerji @mfine : ok, now we are good to go!


with PySerialDriver(args.serial_port[0], args.baud[0]) as driver:
with Handler(driver.read, driver.write) as handler:
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe throw the socket in a with statement?

  with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp

... but nevermind, because python sockets don't implement context manager apparently. Might be good to have a close on the socket just to be proper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, I tried that first too. I like this method mentioned in the SO thread:

from contextlib import closing
import socket

with closing(socket.socket()) as s:
    print s

sound good?

@mfine
Copy link
Contributor

mfine commented Mar 24, 2015

Looks good to me!

@mookerji
Copy link
Contributor

Looking.

args = parser.parse_args()

# Open a connection to Piksi using the default baud rate (1Mbaud)
with PySerialDriver(args.port[0], 1000000) as driver:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: baud_rate = 1000000.

@mookerji
Copy link
Contributor

just a few nits. otherwise fine to merge.

fnoble added a commit that referenced this pull request Mar 24, 2015
Examples for Python client library
@fnoble fnoble merged commit 84cebd4 into swift-nav:master Mar 24, 2015
@fnoble fnoble deleted the udp_example branch March 24, 2015 21:40
IsakTjernberg pushed a commit that referenced this pull request May 6, 2020
Co-authored-by: Swift Svc Jenkins <jenkins@swift-nav.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants