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.
It works like this.
Recommended Posts