Display UTM-30LX data in Python

Hokuyo Electric's range sensor "UTM-30LX" was moved with python, so make a note.

I wondered if URG would work with pythonn, and when I searched for it, I found a good library, so I tried using it.

Source code for the time being

Test_LRF_v1.py


import pyurg
import matplotlib.pyplot as plt
import time

def draw():
   urg = pyurg.Urg()
   urg.set_urg('COM5')
   plt.ion()
   axis = plt.gca()
   while True:
      status = urg.request_me(0,1080,num = 1)
      urg.check_status(status)
      dist, intensity, timestamp = urg.get_distance_and_intensity()
      x,y = urg.convert_to_x_y(dist)
      plt.plot(x,y)
      plt.draw()
      axis.clear()
      time.sleep(0.01)
        
if __name__=="__main__":
   draw()

Just display it for the time being, and nothing in particular will be done from there.

import pyurg
import matplotlib.pyplot as plt
import time

Library import. pyurg (to use URG) matplotlib (draw on graph) time (for sleep)

def draw():
   urg = pyurg.Urg()
   urg.set_urg('COM5')
   plt.ion()
   axis = plt.gca()
   while True:
      status = urg.request_me(0,1080,num = 1)
      urg.check_status(status)
      dist, intensity, timestamp = urg.get_distance_and_intensity()
      x,y = urg.convert_to_x_y(dist)
      plt.plot(x,y)
      plt.draw()
      axis.clear()
      time.sleep(0.01)

urg is connected to COM5. Enter interactive mode with plt.ion ().

status = urg.request_me(0,1080,num = 1) Request a measurement request to urg in ME mode. (In this case, measure steps 0-1080 once)

urg.get_distance_and_intensity() Receive the data at urg.convert_to_x_y(dist) Convert to x, y data with.

After that, if you plot and draw, the graph will be displayed.

Since an infinite loop is created with while, it can be displayed while updating the data in chronological order.

IMAG1041.jpg

It works like this. スクリーンショット (160).png

スクリーンショット (159).png

Recommended Posts

Display UTM-30LX data in Python
Receive and display HTML form data in Python
Display candlesticks for FX (forex) data in Python
Handle Ambient data in Python
Get Leap Motion data in Python.
Read Protocol Buffers data in Python3
Handle NetCDF format data in Python
Waveform display of audio in Python
Display characters like AA in python
Hashing data in R and Python
Display LaTeX notation formulas in Python, matplotlib
Get additional data in LDAP with python
Quadtree in Python --2
Python in optimization
CURL in python
[Python, Julia] 3D display in Jupyter-Mayavi library
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Data input / output in Python (CSV, JSON)
Meta-analysis in Python
Unittest in python
Try working with binary data in Python
Display a list of alphabets in Python 3
Data analysis python
Display Python 3 in the browser with MAMP
Epoch in Python
Discord in Python
Get Google Fit API data in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Python: Preprocessing in machine learning: Data acquisition
How to display multiplication table in python
Get Youtube data in Python using Youtube Data API
Plink in Python
Constant in python
Easily graph data in shell and Python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Display pyopengl in a browser (python + eel)
Python: Preprocessing in machine learning: Data conversion
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
How to display Hello world in python