Main Page
Namespaces
Files
File List
scripts
rtlightsensors.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
import
sys, rospy
3
from
raspimouse_ros.msg
import
LightSensorValues
4
5
if
__name__ ==
'__main__'
:
6
#freq = 10
7
#if rospy.has_param('lightsensors_freq'):
8
freq = rospy.get_param(
'lightsensors_freq'
,10)
9
10
devfile =
'/dev/rtlightsensor0'
11
rospy.init_node(
'rtlightsensors'
)
12
pub = rospy.Publisher(
'lightsensors'
, LightSensorValues, queue_size=1)
13
rate = rospy.Rate(freq)
14
15
while
not
rospy.is_shutdown():
16
try
:
17
with open(devfile,
'r') as f:
18
data = f.readline().split()
19
d = LightSensorValues()
20
d.right_forward = int(data[0])
21
d.right_side = int(data[1])
22
d.left_side = int(data[2])
23
d.left_forward = int(data[3])
24
pub.publish(d)
25
except
:
26
rospy.logerr(
"cannot open "
+ devfile)
27
28
rate.sleep()
29
msg
raspimouse_ros
Author(s):
autogenerated on Mon Jun 10 2019 14:27:02