Subscribe to a topic with flag
I have a gripper embedded with a sensor in the finger. The sensor will tell if there is something between the gripper by True/False in 500 Hz. So I hope the gripper to go to successive positions to detect if there is something between the gripper, if there the sensor data is true, a marker is drawn in the rviz. I imitate some codes and modified as follows(I write it in a general way). While it seems scan_sub can't subscribe the data properly, I am confused with when the scan_sub begins to subscribe and when it is shut down. I have also write some notes in the following code which I am confused about.....Hope some one could kindly help me with that ...
import scan_execute
class PlanServer:
def __init__(self):
......
rospy.Service('scan_object', Empty, scan_object_callback)
self.sc = scan_execute.ScanExecute()
def scan_object_callback(self, req):
result = False
result = self.sc.pretouch_scan()
***the scan_execute file***
class ScanExecute:
def __init__(self):
......
def pretouch_scan(self):
self.detected = False
self.start_time = rospy.Time.now()
self.scan_sub = rospy.Subcsriber("sensor/data", SensorData, sensor_callback)
# what does this *while* mean for ....
while not self.detected:
rospy.sleep(0.5)
return True
def sensor_callback(msg):
time_limit = rospy.Duration(10.0)
time_past = rospy.Time.now() - self.start_time
if time_past > time_limit:
self.detected = True # when *detected* is True, will the *scan_object_callback* return True?
self.count = 0
self.scan_sub.unregister()
else:
self.count += 1
# I hope the gripper of robot will go to the successively position for 5 times.
# and when it detect the sensor data, a marker is drawn in rviz
self.current_mat = self.current_mat * self.step_mat
self.moveit_cmd.go(current_mat, wait = True)
if msg.data
self.detected = True
self.draw_marker()
if self.count > 5:
self.detected = True