Ejemplo n.º 1
0
def main(nh):
    s =  yield json_server_proxy.get_server(nh)
    try:
        #url_was_set = s.interact('http://ec2-52-7-253-202.compute-1.amazonaws.com:80','openTest')
        url = raw_input('url: ')
        course = raw_input('Course:')
        url_was_set = yield s.interact('http://' + url, course) 

        if url_was_set.was_set:

            print "Url and course were set succesfully"

            challenge_was_set = (yield s.set_current_challenge('gates')).was_set

            if challenge_was_set:

                print "Challenge was set succesfully"

                yield s.end_run()
                print 'Ended last run'
                run_started = (yield s.start_run()).success

                if run_started:

                    print "Run started succesfully"

                    images = yield s.get_server_images()
                    print images

                    sent_image = yield s.send_image_info('0.png', 'ZERO')
                    print sent_image

                    dock = yield s.get_dock_info()

                    print dock

                    gates = yield s.get_gate_info()

                    print gates
                    color = 'blue'
                    for c in ['blue', 'green', 'red', 'yellow', 'black']:
                        check = yield s.send_buoy_info(c)
                        if check.is_right_buoy:
                            print 'Got the right buoy: ' + c
                            color = c
                            break
                        else:
                            print 'Got the wrong buoy: ' + c


                    print test

                    print '____Beat?____'
                    yield util.sleep(60)


    finally:
        yield s.end_run()
        print 'Ended run'
Ejemplo n.º 2
0
def main(nh):
    global course
    global obstical_info
    global docking_info
    global images_info
    global sent_image

    # Grab interfaces for boat and JSON server
    boat = yield boat_scripting.get_boat(nh)
    s =  yield json_server_proxy.get_server(nh)

    # Grab mission input such as JSON server ip, and course
    ip_port = raw_input('Enter ip:port (ex. 10.0.2.1:8080): ')
    course = raw_input('Enter course with corect spelling! (courseA, courseB, ...): ')

    # Check that the course is in the dictionaries
    assert course in DOCK.keys(), '%s is not in %s' % (course, DOCK.keys())

    shape1 = None
    shape2 = None
    color1 = None
    color2 = None

    boat.default_state()

    # Giant try finally to make sure boat ends run and returns to its default state
    try:
        
        # Main mission code

        # JSON initilization
        # TODO: if any failures start over
        # IP - http://10.0.2.1:8080

        url_was_set = (yield s.interact('http://'+ip_port, course)).was_set
        assert url_was_set, 'Failed to set URL to ' + 'http://'+ip_port + ' on course ' + course

        # Set the current challange
        set_challenge = (yield s.set_current_challenge('gates')).was_set
        print "Url and course were set succesfully"

        # end run before start just in case
        end_run = yield s.end_run()
        run_started = (yield s.start_run()).success
        assert run_started, 'Run failed to start'
        print "Run started succesfully"


##------------------------------- Grab all JSON data --------------------------------------------------

        print 'Starting mass JSON download'
        obstical_info = s.get_gate_info()
        docking_info = s.get_dock_info()
        images_info = s.get_server_images()

##-------------------------------- GATES ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(start_gates(nh, boat, s), START_GATE_TIME)
            print 'succesfully'
        except Exception as e:
            print 'Could not complete start gates: ' + str(e)
        finally:
            print 'Finally start gate'
            #boat.default_state()


##-------------------------------- OBS COURSE ------------------------------------------------------------
        
        print 'obstical'
        try:
            yield util.wrap_timeout(obstical_course(nh, boat, s), OBS_COURSE_TIME)
            print 'util'
        except:
            print 'Could not complete obstacle course'
        finally: pass
            #boat.default_state()
        

##-------------------------------- DOCKING ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(docking(nh, boat, s), DOCK_TIME)
        except:
            print 'Could not complete docking'
        finally: pass
            #boat.default_state()


##-------------------------------- QUAD ---------------------------------------------------------------
    
        try:
            yield util.wrap_timeout(interoperability(nh, boat, s), NTROP_TIME)
        except:
            print 'Could not complete interoperability'
        finally: pass
            #boat.default_state()

##-------------------------------- PINGER ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(pinger(nh, boat, s), HYDRO_TIME)
        except:
            print 'Could not complete pinger'
        finally: pass
            #boat.default_state()

##-------------------------------- RETURN ---------------------------------------------------------------

        print "Run complete, coming back to the dock"
        s.set_current_challenge('return')

        """
        if course is 'courseA':
            print "Moving to safe point to avoid fountain"
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, SAFE_POINT_1[course]), ECEF_TIME)
        """

        print "Moving to zero point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_0[course]), ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Moving to first point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_1[course]), ECEF_TIME)
        except:
            print 'ECEF timeout'        
        print "Moving to second point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_2[course]), ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Moving to third point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_3[course]), ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Adjusting heading"
        yield boat.move.heading(HOME_3_HEADING[course]).go()


##------------------------------ CLEAN UP -----------------------------------------------------
        
        print 'Returned to dock'
        # Make sure quad copter image sent before we end the mission
        yield sent_image

        print 'Eneded run succesfully! Go Gators!'
        s.end_run()

 
    finally:
        # We do not yield here because if something hangs we still want everything else to complete
        print 'Finally: Ending run and returning to default state'
        s.end_run()
        boat.default_state()
Ejemplo n.º 3
0
def main(nh):

    assert TOTAL_TIME > CIRCLE_TIME + CROSS_TIME + TRIANGLE_TIME + (
        ECEF_TIME * 4) + START_GATE_TIME
    '''

	Test Main Mission:

	1. Go to point A and turn North, then begin speed gate challenge - One minute timeout
	2. Do speedgates, then go to point F and turn South - One minute timeout
	3. Go to position E to begin docking challenges - One minute each
	4. When done with docking move back to point A and turn north

	SPEED ONLY SET TO ONE TO START

	'''

    boat = yield boat_scripting.get_boat(nh)

    ################## Start server like this ########################

    s = yield json_server_proxy.get_server(nh)

    url_was_set = (yield s.interact(
        'http://ec2-52-7-253-202.compute-1.amazonaws.com:80',
        'openTest')).was_set

    if url_was_set:

        print "Url and course were set succesfully"

        challenge_was_set = (yield s.set_current_challenge('gates')).was_set

        if challenge_was_set:

            print "Challenge was set succesfully"

            run_started = (yield s.start_run()).success

            if run_started:

                print "Run started succesfully"

    ##################################################################

    ############## Get gate info #####################################

    #request that the gate info be retrieved
    gate_info = s.get_gate_info()

    ############### Get the docking bay info like so ##################

    #request that the dock info be retrieved
    dock_info = s.get_dock_info()

    #################################################################

    ################# Get server images #############################

    print "Downloading images..."

    #requests that the images be dowloaded
    images_info = s.get_server_images()

    ################################################################

    print "Starting main mission"

    print "Moving to first position: ", str(WAYPOINT_A)
    try:

        yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_A, SPEED),
                                ECEF_TIME)
        yield boat.move.heading(NORTH).go()
        print "Arrived at first position"
    except Exception:
        print "Could not make it to first position in " + str(
            ECEF_TIME) + " seconds"
    finally:
        boat.default_state()

    print "Starting speed gates now"
    try:
        # Set the current challenge to gates
        s.set_current_challenge('gates')

        ##################### Recover gate info #######################

        gate_info = yield gate_info

        entrance_gate = gate_info.entrance

        exit_gate = gate_info.exit

        print "Gate info: " + entrance_gate + " " + exit_gate

        ##############################################################

        start_gate = yield util.wrap_timeout(start_gate_laser.main(nh),
                                             ONE_MINUTE)
        print "Startgates completed succesfully!"
    except Exception:
        print "Could not complete stargates in" + str(
            START_GATE_TIME) + " seconds"
    finally:
        boat.default_state()

    print "Moving to safe position now: ", str(WAYPOINT_F)

    try:
        yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_F, SPEED),
                                ONE_MINUTE)
        yield boat.move.heading(EAST).go()
        print "Moved to " + str(WAYPOINT_F) + ", now moving to " + str(
            WAYPOINT_E) + " to begin docking"
    except Exception:
        print "Could not make it to second position in " + str(
            ONE_MINUTE) + " seconds"
    finally:
        boat.default_state()

    try:
        yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_E, SPEED),
                                ONE_MINUTE)
        yield boat.move.heading(EAST).go()
        print "Moved to " + str(WAYPOINT_E) + ", starting docking challenge"
    except Exception:
        print "Could not make it to third position in " + str(
            ONE_MINUTE) + " seconds"
    finally:
        boat.default_state()

    try:
        # Set the current challenge to docking
        s.set_current_challenge('docking')

        ######################## Recover docking info ###################

        dock_info = yield dock_info

        dock_one_symbol = dock_info.first_dock_symbol

        dock_one_color = dock_info.first_dock_color

        dock_two_symbol = dock_info.second_dock_symbol

        dock_two_color = dock_info.second_dock_color

        print "Dock info: " + dock_one_symbol + " " + dock_one_color + " " + dock_two_symbol + " " + dock_two_color

        #################################################################

        yield do_dock(nh, 'circle')
    except Exception:
        pass
    finally:
        boat.default_state()

    try:

        s.set_current_challenge('docking')
        yield do_dock(nh, 'triangle')
    except Exception:
        pass
    finally:
        boat.default_state()

    try:
        yield s.set_current_challenge('docking')
        yield do_dock(nh, 'cross')
    except Exception:
        pass
    finally:
        boat.default_state()

        print "Docking complete"
        print "Moving back to startate begining position", str(WAYPOINT_A)

    # Set current challenge to interop

    s.set_current_challenge('interop')

    ################ Recover image path and image count #############

    images_info = yield images_info

    images_path = images_info.file_path

    images_count = images_info.image_count

    print "Images info: " + images_path + " " + str(images_count)

    ################################################################

    ############### Report an image to te server ####################

    print "Sending image to server..."

    #The paramenters would be the information regarding the identified image
    send_image = yield s.send_image_info('1.jpg', 'ONE')
    #Only yield the server response right away if you need to work with the respose
    #right away. This might take some time if the server is slow and the mission will
    #halt at this point until you get a server response

    print "Is it the right image?: " + str(send_image.is_right_image)

    #################################################################

    ############## Report the pinger buoy to the server #############

    #Set challenge to pinger
    s.set_current_challenge('pinger')

    print "Sending buoy color to server..."

    #The paramenter is the identified color
    send_buoy = yield s.send_buoy_info('yellow')
    #Only yield the server response right away if you need to work with the respose
    #right away. This might take some time if the server is slow and the mission will
    #halt at this point until you get a server response

    print "Is this the right buoy?: " + str(send_buoy.is_right_buoy)

    #################################################################

    try:
        s.set_current_challenge('return')
        yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_A, SPEED),
                                ONE_MINUTE)
        yield boat.move.heading(NORTH).go()
        print "Arrived at ", str(WAYPOINT_A)
    except Exception:
        print "Could not make it to third position in " + str(
            ONE_MINUTE) + " seconds"
    finally:
        ######### Make sure the run is ended with the server ###############
        print "Ending run"
        yield s.end_run()
        ####################################################################
        boat.default_state()
Ejemplo n.º 4
0
def main(nh):

	assert TOTAL_TIME > CIRCLE_TIME + CROSS_TIME + TRIANGLE_TIME + (ECEF_TIME * 4) + START_GATE_TIME

	'''

	Test Main Mission:

	1. Go to point A and turn North, then begin speed gate challenge - One minute timeout
	2. Do speedgates, then go to point F and turn South - One minute timeout
	3. Go to position E to begin docking challenges - One minute each
	4. When done with docking move back to point A and turn north

	SPEED ONLY SET TO ONE TO START

	'''

	boat = yield boat_scripting.get_boat(nh)

	################## Start server like this ########################

	s =  yield json_server_proxy.get_server(nh)

	url_was_set = (yield s.interact('http://ec2-52-7-253-202.compute-1.amazonaws.com:80','openTest')).was_set

	if url_was_set:

		print "Url and course were set succesfully"

	 	challenge_was_set = (yield s.set_current_challenge('gates')).was_set

	 	if challenge_was_set:

	 		print "Challenge was set succesfully"

	 		run_started = (yield s.start_run()).success

	 		if run_started:

	 			print "Run started succesfully"

	################################################################## 

	############## Get gate info #####################################

	#request that the gate info be retrieved
	gate_info = s.get_gate_info()

	############### Get the docking bay info like so ##################

	#request that the dock info be retrieved
	dock_info = s.get_dock_info()	

	#################################################################

	################# Get server images #############################

	print "Downloading images..."

	#requests that the images be dowloaded
	images_info = s.get_server_images()

	################################################################

	print "Starting main mission"




	print "Moving to first position: ", str(WAYPOINT_A)
	try:

		yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_A, SPEED), ECEF_TIME)
		yield boat.move.heading(NORTH).go()
		print "Arrived at first position"
	except Exception:
		print "Could not make it to first position in " + str(ECEF_TIME) + " seconds"
	finally:
		boat.default_state()


	print "Starting speed gates now"
	try:
		# Set the current challenge to gates
		s.set_current_challenge('gates')

		##################### Recover gate info #######################

		gate_info = yield gate_info

		entrance_gate = gate_info.entrance

		exit_gate = gate_info.exit

		print "Gate info: " + entrance_gate +" "+ exit_gate

		##############################################################		

		start_gate = yield util.wrap_timeout(start_gate_laser.main(nh), ONE_MINUTE)
		print "Startgates completed succesfully!"
	except Exception:
		print "Could not complete stargates in" + str(START_GATE_TIME) + " seconds"
	finally:
		boat.default_state()

	print "Moving to safe position now: ", str(WAYPOINT_F)

	try:
		yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_F, SPEED), ONE_MINUTE)
		yield boat.move.heading(EAST).go()
		print "Moved to " + str(WAYPOINT_F) + ", now moving to " + str(WAYPOINT_E) + " to begin docking"
	except Exception:
		print "Could not make it to second position in " + str(ONE_MINUTE) + " seconds"
	finally:
		boat.default_state()

	try:
		yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_E, SPEED), ONE_MINUTE)
		yield boat.move.heading(EAST).go()
		print "Moved to " + str(WAYPOINT_E) + ", starting docking challenge"
	except Exception:
		print "Could not make it to third position in " + str(ONE_MINUTE) + " seconds"
	finally:
		boat.default_state()

	try:
		# Set the current challenge to docking
		s.set_current_challenge('docking')

		######################## Recover docking info ###################
		
		dock_info = yield dock_info		

		dock_one_symbol = dock_info.first_dock_symbol

		dock_one_color = dock_info.first_dock_color

		dock_two_symbol = dock_info.second_dock_symbol

		dock_two_color = dock_info.second_dock_color

		print "Dock info: " + dock_one_symbol +" "+ dock_one_color +" "+ dock_two_symbol +" "+ dock_two_color

		#################################################################		

		yield do_dock(nh, 'circle')
	except Exception:
		pass
	finally:
		boat.default_state()

	try:

		s.set_current_challenge('docking')
		yield do_dock(nh, 'triangle')
	except Exception:
		pass
	finally:
		boat.default_state()

	try:
		yield  s.set_current_challenge('docking')
		yield do_dock(nh, 'cross')
	except Exception:
		pass
	finally:
		boat.default_state()


		print "Docking complete"
		print "Moving back to startate begining position", str(WAYPOINT_A)

	# Set current challenge to interop	

	s.set_current_challenge('interop')

	################ Recover image path and image count #############

	images_info = yield images_info

	images_path = images_info.file_path

	images_count = images_info.image_count

	print "Images info: " + images_path +" "+ str(images_count)

	################################################################

	############### Report an image to te server ####################

	print "Sending image to server..."

	#The paramenters would be the information regarding the identified image 
	send_image = yield s.send_image_info('1.jpg','ONE')
	#Only yield the server response right away if you need to work with the respose
	#right away. This might take some time if the server is slow and the mission will
	#halt at this point until you get a server response

	print "Is it the right image?: " + str(send_image.is_right_image)

	#################################################################

	############## Report the pinger buoy to the server #############

	#Set challenge to pinger
	s.set_current_challenge('pinger')

	print "Sending buoy color to server..."

	#The paramenter is the identified color
	send_buoy = yield s.send_buoy_info('yellow')
	#Only yield the server response right away if you need to work with the respose
	#right away. This might take some time if the server is slow and the mission will
	#halt at this point until you get a server response

	print "Is this the right buoy?: " + str(send_buoy.is_right_buoy)

	#################################################################

	try:
		s.set_current_challenge('return')
		yield util.wrap_timeout(go_to_ecef_pos.main(nh, WAYPOINT_A, SPEED), ONE_MINUTE)
		yield boat.move.heading(NORTH).go()
		print "Arrived at ", str(WAYPOINT_A)
	except Exception:
		print "Could not make it to third position in " + str(ONE_MINUTE) + " seconds"
	finally:
		######### Make sure the run is ended with the server ###############		
		print "Ending run"
		yield s.end_run()
		####################################################################		
		boat.default_state()
Ejemplo n.º 5
0
def main(nh):
    global course
    global obstical_info
    global docking_info
    global images_info
    global sent_image

    # Grab interfaces for boat and JSON server
    boat = yield boat_scripting.get_boat(nh)
    s = yield json_server_proxy.get_server(nh)

    # Grab mission input such as JSON server ip, and course
    ip_port = raw_input('Enter ip:port (ex. 10.0.2.1:8080): ')
    course = raw_input(
        'Enter course with corect spelling! (courseA, courseB, ...): ')

    # Check that the course is in the dictionaries
    assert course in DOCK.keys(), '%s is not in %s' % (course, DOCK.keys())

    shape1 = None
    shape2 = None
    color1 = None
    color2 = None

    boat.default_state()

    # Giant try finally to make sure boat ends run and returns to its default state
    try:

        # Main mission code

        # JSON initilization
        # TODO: if any failures start over
        # IP - http://10.0.2.1:8080

        url_was_set = (yield s.interact('http://' + ip_port, course)).was_set
        assert url_was_set, 'Failed to set URL to ' + 'http://' + ip_port + ' on course ' + course

        # Set the current challange
        set_challenge = (yield s.set_current_challenge('gates')).was_set
        print "Url and course were set succesfully"

        # end run before start just in case
        end_run = yield s.end_run()
        run_started = (yield s.start_run()).success
        assert run_started, 'Run failed to start'
        print "Run started succesfully"

        ##------------------------------- Grab all JSON data --------------------------------------------------

        print 'Starting mass JSON download'
        obstical_info = s.get_gate_info()
        docking_info = s.get_dock_info()
        images_info = s.get_server_images()

        ##-------------------------------- GATES ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(start_gates(nh, boat, s), START_GATE_TIME)
            print 'succesfully'
        except Exception as e:
            print 'Could not complete start gates: ' + str(e)
        finally:
            print 'Finally start gate'
            #boat.default_state()

##-------------------------------- OBS COURSE ------------------------------------------------------------

        print 'obstical'
        try:
            yield util.wrap_timeout(obstical_course(nh, boat, s),
                                    OBS_COURSE_TIME)
            print 'util'
        except:
            print 'Could not complete obstacle course'
        finally:
            pass
        #boat.default_state()

        ##-------------------------------- DOCKING ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(docking(nh, boat, s), DOCK_TIME)
        except:
            print 'Could not complete docking'
        finally:
            pass
        #boat.default_state()

        ##-------------------------------- QUAD ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(interoperability(nh, boat, s), NTROP_TIME)
        except:
            print 'Could not complete interoperability'
        finally:
            pass
        #boat.default_state()

        ##-------------------------------- PINGER ---------------------------------------------------------------

        try:
            yield util.wrap_timeout(pinger(nh, boat, s), HYDRO_TIME)
        except:
            print 'Could not complete pinger'
        finally:
            pass
        #boat.default_state()

        ##-------------------------------- RETURN ---------------------------------------------------------------

        print "Run complete, coming back to the dock"
        s.set_current_challenge('return')
        """
        if course is 'courseA':
            print "Moving to safe point to avoid fountain"
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, SAFE_POINT_1[course]), ECEF_TIME)
        """

        print "Moving to zero point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_0[course]),
                                    ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Moving to first point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_1[course]),
                                    ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Moving to second point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_2[course]),
                                    ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Moving to third point to get home"
        try:
            yield util.wrap_timeout(go_to_ecef_pos.main(nh, HOME_3[course]),
                                    ECEF_TIME)
        except:
            print 'ECEF timeout'
        print "Adjusting heading"
        yield boat.move.heading(HOME_3_HEADING[course]).go()

        ##------------------------------ CLEAN UP -----------------------------------------------------

        print 'Returned to dock'
        # Make sure quad copter image sent before we end the mission
        yield sent_image

        print 'Eneded run succesfully! Go Gators!'
        s.end_run()

    finally:
        # We do not yield here because if something hangs we still want everything else to complete
        print 'Finally: Ending run and returning to default state'
        s.end_run()
        boat.default_state()