Add Python version of vl53l1x driver

This commit is contained in:
Oleg Kalachev
2018-09-27 06:11:52 +03:00
parent 27a748c6a6
commit 07d33798a0
3 changed files with 43 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
<arg name="aruco" default="false"/>
<arg name="rc" value="true"/>
<arg name="arduino" default="false"/>
<arg name="vl53l1x" default="false"/>
<!-- mavros -->
<include file="$(find clever)/launch/mavros.launch">
@@ -54,6 +55,11 @@
<!-- rosbridge -->
<include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch" if="$(eval rosbridge or rc)"/>
<!-- vl53l1x ToF rangefinder -->
<node name="vl53l1x" pkg="clever" type="vl53l1x.py" output="screen" if="$(arg vl53l1x)">
<!-- <remap from="~range" to="mavros/distance_sensor/rangefinder_3_sub"/> -->
</node>
<!-- rc backend -->
<node name="rc" pkg="clever" type="rc" output="screen" if="$(arg rc)"/>

View File

@@ -1,3 +1,5 @@
flask==0.12.2
geopy==1.11.0
pymavlink==2.2.10
smbus2==0.2.1
VL53L1X==0.0.2

35
clever/src/vl53l1x.py Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python
from __future__ import division
import rospy
import VL53L1X
from sensor_msgs.msg import Range
rospy.init_node('vl53l1x')
# range_pub = rospy.Publisher('~range', Range, queue_size=5)
# TODO: why remmaping is not working?
range_pub = rospy.Publisher('mavros/distance_sensor/rangefinder_3_sub', Range, queue_size=10)
msg = Range()
msg.radiation_type = Range.INFRARED
msg.field_of_view = 0.471239
msg.min_range = 0
msg.max_range = 4
msg.header.frame_id = 'rangefinder'
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open() # Initialise the i2c bus and configure the sensor
tof.start_ranging(3) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
rospy.loginfo('vl53l1x: start ranging')
r = rospy.Rate(14)
while not rospy.is_shutdown():
msg.header.stamp = rospy.get_rostime()
msg.range = tof.get_distance() / 1000
range_pub.publish(msg)
r.sleep()
tof.stop_ranging() # Stop ranging