class Brain: def __init__(self, sensors=None, actuators=None, handler=None): self.drone = DroneWrapper() self.handler = handler # self.drone.takeoff() def update_frame(self, frame_id, data): self.handler.update_frame(frame_id, data) def execute(self): img_frontal = self.drone.get_frontal_image() img_ventral = self.drone.get_ventral_image() # Both the above images are cv2 images self.update_frame('frame_0', img_frontal) self.update_frame('frame_1', img_ventral)
def __init__(self): rospy.init_node("HAL") self.image = None self.drone = DroneWrapper(name="rqt")
class HAL: IMG_WIDTH = 320 IMG_HEIGHT = 240 def __init__(self): rospy.init_node("HAL") self.image = None self.drone = DroneWrapper(name="rqt") # Explicit initialization functions # Class method, so user can call it without instantiation @classmethod def initRobot(cls): new_instance = cls() return new_instance # Get Image from ROS Driver Camera def get_frontal_image(self): image = self.drone.get_frontal_image() image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image_rgb def get_ventral_image(self): image = self.drone.get_ventral_image() image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image_rgb def get_position(self): pos = self.drone.get_position() return pos def get_velocity(self): vel = self.drone.get_velocity() return vel def get_yaw_rate(self): yaw_rate = self.drone.get_yaw_rate() return yaw_rate def get_orientation(self): orientation = self.drone.get_orientation() return orientation def get_roll(self): roll = self.drone.get_roll() return roll def get_pitch(self): pitch = self.drone.get_pitch() return pitch def get_yaw(self): yaw = self.drone.get_yaw() return yaw def get_landed_state(self): state = self.drone.get_landed_state() return state def set_cmd_pos(self, x, y, z, yaw): self.drone.set_cmd_pos(x, y, z, yaw) def set_cmd_vel(self, vx, vy, vz, yaw_rate): self.drone.set_cmd_vel(vx, vy, vz, yaw_rate) def set_cmd_mix(self, vx, vy, z, yaw_rate): self.drone.set_cmd_mix(vx, vy, z, yaw_rate) def takeoff(self, h=3): self.drone.takeoff(h) def land(self): self.drone.land()
for i in range(times): print 'Forward' drone.set_cmd_vel(vx=side_vel) wait(side_time) print 'Left' drone.set_cmd_vel(vy=side_vel) wait(side_time) print 'Reverse' drone.set_cmd_vel(vx=-side_vel) wait(side_time) print 'Right' drone.set_cmd_vel(vy=-side_vel) wait(side_time) drone = DroneWrapper(verbose=False) print '***********************************Rectangle************************************' print 'Calling Takeoff' drone.takeoff(2) wait(7) doRectange(5) wait(5) print 'Landing' drone.land() wait(3) print '***********************************Circle************************************' print 'Calling Takeoff'
def execute(event): global drone img_frontal = drone.get_frontal_image() img_ventral = drone.get_ventral_image() # Both the above images are cv2 images ################# Insert your code here ################################# set_image_filtered(img_frontal) set_image_threshed(img_ventral) ######################################################################### if __name__ == "__main__": drone = DroneWrapper() rospy.Subscriber('gui/takeoff_land', Bool, gui_takeoff_cb) rospy.Subscriber('gui/play_stop', Bool, gui_play_stop_cb) rospy.Subscriber('gui/twist', Twist, gui_twist_cb) gui_filtered_img_pub = rospy.Publisher('interface/filtered_img', Image, queue_size=1) gui_threshed_img_pub = rospy.Publisher('interface/threshed_img', Image, queue_size=1) code_live_flag = False code_live_timer = rospy.Timer(rospy.Duration(nsecs=50000000), execute) code_live_timer.shutdown() while not rospy.is_shutdown(): rospy.spin()
#!/usr/bin/env python from drone_wrapper import DroneWrapper import rospy drone = DroneWrapper() rospy.sleep(1) if drone.get_position().z < 0.1: print 'taking off due to ', drone.get_position().z drone.takeoff(3) else: drone.take_control() while True: vels = raw_input( 'Enter space seperated velocities as vx vy vz az and then press enter\nValues: ' ) if vels == '': break vx, vy, vz, az = map(float, vels.strip().split(' ')) drone.set_cmd_vel(vx, vy, vz, az)
code_live_timer.shutdown() def set_image_filtered(img): gui_filtered_img_pub.publish(HAL.bridge.cv2_to_imgmsg(img)) def set_image_threshed(img): gui_threshed_img_pub.publish(HAL.bridge.cv2_to_imgmsg(img)) def execute(event): global HAL img_frontal = HAL.get_frontal_image() img_ventral = HAL.get_ventral_image() # Both the above images are cv2 images ################# Insert your code here ################################# set_image_filtered(img_frontal) set_image_threshed(img_ventral) ######################################################################### if __name__ == "__main__": HAL = DroneWrapper() rospy.Subscriber('gui/play_stop', Bool, gui_play_stop_cb) gui_filtered_img_pub = rospy.Publisher('interface/filtered_img', Image, queue_size = 1) gui_threshed_img_pub = rospy.Publisher('interface/threshed_img', Image, queue_size = 1) code_live_flag = False code_live_timer = rospy.Timer(rospy.Duration(nsecs=50000000), execute) code_live_timer.shutdown() while not rospy.is_shutdown(): rospy.spin()
def __init__(self, sensors=None, actuators=None, handler=None): self.drone = DroneWrapper() self.handler = handler
def __init__(self): rospy.init_node("HAL") self.image = None self.cat = DroneWrapper(name="rqt", ns="cat/") self.mouse = DroneWrapper(name="rqt", ns="mouse/")
class HAL: IMG_WIDTH = 320 IMG_HEIGHT = 240 def __init__(self): rospy.init_node("HAL") self.image = None self.cat = DroneWrapper(name="rqt", ns="cat/") self.mouse = DroneWrapper(name="rqt", ns="mouse/") # Explicit initialization functions # Class method, so user can call it without instantiation @classmethod def initRobot(cls): new_instance = cls() return new_instance def start_mouse(self, path_level): print("MOUSE", path_level) self.mouse.takeoff(h=5) # while True: # v = path_obfuscated(path_level) # if v is not None: # vx, vy, vz, yaw = v # self.mouse.set_cmd_vel(vx, vy, vz, yaw) # else: # print("[Mouse] Path {} not available".format(path_level)) # break # Get Image from ROS Driver Camera def getFrontalImage(self): image = self.cat.get_frontal_image() image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image_rgb def getVentralImage(self): image = self.cat.get_ventral_image() image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image_rgb def get_position(self): pos = self.cat.get_position() return pos def get_velocity(self): vel = self.cat.get_velocity() return vel def get_yaw_rate(self): yaw_rate = self.cat.get_yaw_rate() return yaw_rate def get_orientation(self): orientation = self.cat.get_orientation() return orientation def get_roll(self): roll = self.cat.get_roll() return roll def get_pitch(self): pitch = self.cat.get_pitch() return pitch def get_yaw(self): yaw = self.cat.get_yaw() return yaw def get_landed_state(self): state = self.cat.get_landed_state() return state def set_cmd_pos(self, x, y, z, yaw): self.cat.set_cmd_pos(x, y, z, yaw) def set_cmd_vel(self, vx, vy, vz, yaw_rate): self.cat.set_cmd_vel(vx, vy, vz, yaw_rate) def set_cmd_mix(self, vx, vy, z, yaw_rate): self.cat.set_cmd_mix(vx, vy, z, yaw_rate) def takeoff(self, h=3): self.cat.takeoff(h) def land(self): self.cat.land()
def __init__(self): self.mouse = DroneWrapper(name="rqt", ns="mouse/") self.reset_state = rospy.ServiceProxy('/gazebo/set_model_state', SetModelState)
class Mouse: def __init__(self): self.mouse = DroneWrapper(name="rqt", ns="mouse/") self.reset_state = rospy.ServiceProxy('/gazebo/set_model_state', SetModelState) # Explicit initialization functions # Class method, so user can call it without instantiation @classmethod def initRobot(cls): new_instance = cls() return new_instance def takeoff(self): self.mouse.takeoff(h=5) def start_mouse(self, path_level): self.takeoff() self.thread = StoppableThread(target=self.autonomous_mouse, args=[path_level]) self.thread.start() def land(self): self.mouse.land() def stop_mouse(self): self.thread.stop() self.mouse.set_cmd_mix(vx=0, vy=0, z=self.mouse.get_position()[2], az=0) def reset_mouse(self): self.thread.stop() self.mouse.land() req = ModelState() req.model_name = "iris_red" req.pose.position.x = 2.0 req.pose.position.y = 0.0 req.pose.position.z = 0.05 req.pose.orientation.x = 0.0 req.pose.orientation.y = 0.0 req.pose.orientation.z = 0.0 req.pose.orientation.w = 1.0 req.twist.linear.x = 0.0 req.twist.linear.y = 0.0 req.twist.linear.z = 0.0 req.twist.angular.x = 0.0 req.twist.angular.y = 0.0 req.twist.angular.z = 0.0 self.reset_state(req) def autonomous_mouse(self, path_level): v = path_obfuscated(path_level) if v is not None: vx, vy, vz, yaw = v self.mouse.set_cmd_vel(vx, vy, vz, yaw) else: print("[Mouse] Path {} not available".format(path_level))
class HAL: IMG_WIDTH = 320 IMG_HEIGHT = 240 def __init__(self): rospy.init_node("HAL") self.image = None self.drone = DroneWrapper(name="rqt") # Explicit initialization functions # Class method, so user can call it without instantiation @classmethod def initRobot(cls): new_instance = cls() return new_instance # Get Image from ROS Driver Camera def get_frontal_image(self): image = self.drone.get_frontal_image() image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image_rgb def get_ventral_image(self): image = self.drone.get_ventral_image() image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image_rgb def get_position(self): pos = self.drone.get_position() return pos def get_velocity(self): vel = self.drone.get_velocity() return vel def get_yaw_rate(self): yaw_rate = self.drone.get_yaw_rate() return yaw_rate def get_orientation(self): orientation = self.drone.get_orientation() return orientation def get_roll(self): roll = self.drone.get_roll() return roll def get_pitch(self): pitch = self.drone.get_pitch() return pitch def get_yaw(self): yaw = self.drone.get_yaw() return yaw def get_landed_state(self): state = self.drone.get_landed_state() return state def set_cmd_pos(self, x, y, z, yaw): self.drone.set_cmd_pos(x, y, z, yaw) def set_cmd_vel(self, vx, vy, vz, yaw_rate): self.drone.set_cmd_vel(vx, vy, vz, yaw_rate) def set_cmd_mix(self, vx, vy, z, yaw_rate): self.drone.set_cmd_mix(vx, vy, z, yaw_rate) def takeoff(self, h=3): self.drone.takeoff(h) def land(self): self.drone.land() def init_beacons(self): self.beacons = [] self.beacons.append(Beacon('beacon1', np.array([0, 5, 0]), False, False)) self.beacons.append(Beacon('beacon2', np.array([5, 0, 0]), False, False)) self.beacons.append(Beacon('beacon3', np.array([0, -5, 0]), False, False)) self.beacons.append(Beacon('beacon4', np.array([-5, 0, 0]), False, False)) self.beacons.append(Beacon('beacon5', np.array([10, 0, 0]), False, False)) self.beacons.append(Beacon('initial', np.array([0, 0, 0]), False, False)) def get_next_beacon(self): for beacon in self.beacons: if beacon.is_reached() == False: return beacon return None
gui_threshed_img_pub.publish(HAL.bridge.cv2_to_imgmsg(img)) def execute(event): global HAL img_frontal = HAL.get_frontal_image() img_ventral = HAL.get_ventral_image() # Both the above images are cv2 images ################# Insert your code here ################################# set_image_filtered(img_frontal) set_image_threshed(img_ventral) ######################################################################### if __name__ == "__main__": HAL = DroneWrapper() # Hardware Abstraction Layer aka the drone rospy.Subscriber('gui/play_stop', Bool, gui_play_stop_cb) gui_filtered_img_pub = rospy.Publisher('interface/filtered_img', Image, queue_size=1) gui_threshed_img_pub = rospy.Publisher('interface/threshed_img', Image, queue_size=1) code_live_flag = False code_live_timer = rospy.Timer(rospy.Duration(nsecs=50000000), execute) code_live_timer.shutdown() while not rospy.is_shutdown(): rospy.spin()