0

My project is a directional antenna which is mounted on a self-stabilizing base. The language I wish to use is python, but changing this to a more suited language, is a possibility, if needed.

Problem 1:

How would you go about taking in serial data in real-time[1], and then parse the data in python?

Problem 2:

How can I then send the output of the program to servos, which are mounted on the base? (feedback system).

[1](Fastest possible time for data transfer, processing and then output)

avitex
  • 2,478
  • 3
  • 22
  • 22
  • What hardware are you using for servos and how are they interfaced to the computer? – payne Feb 08 '11 at 00:00
  • 1
    As much as I love Python, I'm not sure I'd consider it suitable for realtime programming. – Nathan Ernst Feb 08 '11 at 00:02
  • @Payne I am going to be using a PIC mircocontroller and connecting it via a FTDI serial contevertor which plugs into a USB making a "Virtual Com port" – avitex Feb 08 '11 at 00:19
  • @Nathan I do agree, but I am most familiar with python than other programming languages. If you could help me embed my code (above) into a suitable language. It would be highly appreciated. – avitex Feb 08 '11 at 00:23
  • What firmware/system will you be using on the PIC microcontroller to drive the servos? That will dictate how you send data from the host computer to move the servos. – payne Feb 08 '11 at 00:33
  • @Payne 9600 BAUD UART -PIC16F628a – avitex Feb 08 '11 at 00:39
  • You'll need to get software for your PIC to control the servos. And that software will dictate how things work from your host PC. – payne Feb 08 '11 at 00:48
  • @Payne Thanks...back to the parsing annd receiving how can I recive the data and use in my equation above? I have had a look at pyserial before but can't get my head around it quite.. – avitex Feb 08 '11 at 00:52
  • Unfortunately, pyserial is about as simple/basic as it gets for reading the serial port in Python. I'd recommend starting with the code examples, and writing a simple starter program that reads GPS data lines and just prints them out. Once you get that working, you can add your parsing code. – payne Feb 08 '11 at 00:58

1 Answers1

2

You can use the pyserial module to read serial port data with Python. See: http://pyserial.sourceforge.net/shortintro.html

Here's a short usage example from the docs:

>>> ser = serial.Serial('/dev/ttyS1', 19200, timeout=1)
>>> x = ser.read()          # read one byte
>>> s = ser.read(10)        # read up to ten bytes (timeout)
>>> line = ser.readline()   # read a '\n' terminated line
>>> ser.close()

Next, you'll need to parse the GPS data. Most devices support "NMEA 0183" format, and here's another SO question with information about parsing that with Python: Parsing GPS receiver output via regex in Python

Finally, outputting data for servo control will depend entirely on whatever hardware you are using for the servo interface.

Community
  • 1
  • 1
payne
  • 13,833
  • 5
  • 42
  • 49