Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import roslib; roslib.load_manifest('starmac_kinect_obstacle_avoidance')
00036 import rospy
00037 import starmac_kinect.msg
00038 import flyer_controller.msg
00039 import joy.msg
00040
00041 class Demo(object):
00042 paused = False
00043 clear_time = None
00044 pause_cmd = flyer_controller.msg.control_mode_cmd('pause')
00045 proceed_cmd = flyer_controller.msg.control_mode_cmd('proceed')
00046 started = False
00047
00048 def __init__(self):
00049 self.pub_cmd = rospy.Publisher("control_mode_autosequence/cmd", flyer_controller.msg.control_mode_cmd)
00050 self.sub_joy = rospy.Subscriber("teleop_flyer/joy", joy.msg.Joy, self.joy_cb)
00051
00052 def joy_cb(self, joy_msg):
00053 if (not self.started) and (joy_msg.buttons[9] == 1):
00054 self.started = True
00055 rospy.loginfo("Starting demo..")
00056 self.sub_obstacle = rospy.Subscriber("kinect_estimator/obstacle", starmac_kinect.msg.Obstacle, self.obstacle_cb)
00057
00058 def obstacle_cb(self, obs_msg):
00059 zpos = obs_msg.location.z
00060 obstacle = (obs_msg.obstacle_found and zpos < 1.0)
00061 rospy.logdebug('Got obstacle message, obstacle_found=%d obstacle z=%f'
00062 % (obs_msg.obstacle_found, zpos))
00063
00064
00065 if obstacle and not self.paused:
00066 rospy.loginfo('Obstacle at %f, Pausing...' % zpos)
00067 self.send_pause()
00068 self.paused = True
00069
00070 if self.paused:
00071 if self.clear_time is None:
00072 self.clear_time = rospy.Time.now()
00073 else:
00074 if (not obstacle) and \
00075 (rospy.Time.now() - self.clear_time).to_sec() > 3.0:
00076 rospy.loginfo('Proceed..')
00077 self.send_proceed()
00078 self.clear_time = None
00079 self.paused = False
00080
00081 def send_pause(self):
00082 rospy.loginfo('Sending PAUSE command')
00083 self.pub_cmd.publish(self.pause_cmd)
00084
00085 def send_proceed(self):
00086 rospy.loginfo('Sending PROCEED command')
00087 self.pub_cmd.publish(self.proceed_cmd)
00088
00089 def spin(self):
00090 rospy.spin()
00091
00092 if __name__ == "__main__":
00093 rospy.init_node('kinect_obstacle_avoidance_demo')
00094 self = Demo()
00095 self.spin()