Beispiel #1
0
def start():
    sock = communication.init_receiver('', c.PORT)
    message = ''
    message, addr = communication.receive_message(sock)
    status = "In comm_bot_test"
    print status
    communication.send_broadcast_message(5003, status)
    return message
Beispiel #2
0
def start():
    sock = communication.init_receiver('', c.PORT)
    message = ''
    message, addr = communication.receive_message(sock)
    status = "In comm_bot_test"
    print status
    communication.send_broadcast_message(5003, status)
    return message
    
    
Beispiel #3
0
def send_new_status(msg, repetitions, space):
    for x in range(repetitions):
        com.send_broadcast_message(c.PORT, msg)
        time.sleep(space)
Beispiel #4
0
                # print state_list
            irCentre = pi2go.irCentre()

            if irCentre or distance < MIN_DIST:
                state_list[OWN_ID] = OBSTACLE
                # print "After setting it: own state: " + str(state_list[OWN_ID])
                # print "irCentre: " + str(irCentre)
            else:
                state_list[OWN_ID] = CLEAR
            # print "P : ", prev_state_list[OWN_ID]
            # print "C : ", state_list[OWN_ID]
            if prev_state_list[OWN_ID] != state_list[OWN_ID]:
                print "Sending state : ", str(state_list[OWN_ID])
                for x in range(10):
                    communication.send_broadcast_message(PORT, str(state_list[OWN_ID]))

            if distance < SLOW_DIST:
                slow = True
            else:
                slow = False

            # print "BEFORE RECEIVING: " + str(state_list)
            # RECEIVE
            message_list = communication.receive_message_list(sock)
            update_state_list()
            
            # #### SEND
            # print "    AFTER RECEIVING: " + str(state_list)
            
            # #### SET SUB_STATE
			state = STATE_RUN
			state_string = "RUN"
			
		if state != prev_state:
			print state_string
			if state == STATE_RUN:
				pi2go.setAllLEDs(LEDoff,LEDon,LEDoff)
			elif state == STATE_WARN:
				pi2go.setAllLEDs(LEDon,LEDon,LEDoff)
			elif state == STATE_STOP:
				pi2go.setAllLEDs(LEDon,LEDoff, LEDoff)
			else:
				print "unknown state!"
			#print time.time()
			#message = "State: " + state + " at " + str(time.time())
			print "Starting broadcast"
			for x in range(0,10):
				message = "    State: " + state_string + " at " + str(time.time()) + " #" + str(x)
				communication.send_broadcast_message(38234, message)
			#print time.time()
			print "Broadcast finished"
		prev_state = state
except KeyboardInterrupt:
	pass
finally:
	pi2go.cleanup()
		
				
	

Beispiel #6
0
    bot_type.append(c.VALUE_TYPE_AUTO)

print bcolors.UNDERLINE + "Either type command in form IDcommandvalue or one after the other. To repeat the last command, simply press 'r' and enter'\n" + bcolors.ENDC
while True:
    print "_" * 100
    identifier = raw_input(
        ('ID ([' + str(c.TEAM_START - 100) + ':' + str(c.TEAM_SIZE) +
         '] or (al)l | (co)m_bots | (au)to  or whole command: \t\t\t'))
    if identifier == 'r':
        if message == '':
            print bcolors.FAIL + 'No message sent so far!' + bcolors.ENDC
        else:
            # everything should be valid...
            # to all...
            if last_receiver == 'all':
                com.send_broadcast_message(c.PORT, message)

            # to all communicating bots
            elif last_receiver == 'com_bots':
                for target_id in range(len(bot_type)):
                    # print str(target_id) + " " + str(bot_type[target_id])
                    if bot_type[target_id] == c.VALUE_TYPE_COM:
                        target_ip = c.SUBNET_IP + str(c.TEAM_START + target_id)
                        # print "actually sending sth.! to " + target_ip
                        com.send_udp_unicast_message(target_ip, c.PORT,
                                                     message)

            # to all autonomous bots
            elif last_receiver == 'auto_bots':
                for target_id in range(len(bot_type)):
                    if bot_type[target_id] == c.VALUE_TYPE_AUTO:
Beispiel #7
0
                # print state_list
            irCentre = pi2go.irCentre()

            if irCentre or distance < MIN_DIST:
                state_list[OWN_ID] = OBSTACLE
                # print "After setting it: own state: " + str(state_list[OWN_ID])
                # print "irCentre: " + str(irCentre)
            else:
                state_list[OWN_ID] = CLEAR
            # print "P : ", prev_state_list[OWN_ID]
            # print "C : ", state_list[OWN_ID]
            if prev_state_list[OWN_ID] != state_list[OWN_ID]:
                print "Sending state : ", str(state_list[OWN_ID])
                for x in range(10):
                    communication.send_broadcast_message(
                        PORT, str(state_list[OWN_ID]))

            if distance < SLOW_DIST:
                slow = True
            else:
                slow = False

            # print "BEFORE RECEIVING: " + str(state_list)
            # RECEIVE
            message_list = communication.receive_message_list(sock)
            update_state_list()

            # #### SEND
            # print "    AFTER RECEIVING: " + str(state_list)

            # #### SET SUB_STATE
Beispiel #8
0
for identifier in range(c.TEAM_START+c.COM_TEAM_SIZE, c.TEAM_END):
    bot_type.append(c.VALUE_TYPE_AUTO)


print bcolors.UNDERLINE + "Either type command in form IDcommandvalue or one after the other. To repeat the last command, simply press 'r' and enter'\n" + bcolors.ENDC
while True:
    print "_" * 100
    identifier = raw_input(('ID (['+str(c.TEAM_START-100)+':'+str(c.TEAM_SIZE) + '] or (al)l | (co)m_bots | (au)to  or whole command: \t\t\t'))
    if identifier == 'r':
        if message == '':
            print bcolors.FAIL + 'No message sent so far!' + bcolors.ENDC
        else:
            # everything should be valid...
            # to all...
            if last_receiver == 'all':
                com.send_broadcast_message(c.PORT, message)
                
            # to all communicating bots
            elif last_receiver == 'com_bots':
                for target_id in range(len(bot_type)):
                    # print str(target_id) + " " + str(bot_type[target_id])
                    if bot_type[target_id] == c.VALUE_TYPE_COM:
                        target_ip = c.SUBNET_IP + str(c.TEAM_START + target_id)
                        # print "actually sending sth.! to " + target_ip
                        com.send_udp_unicast_message(target_ip, c.PORT, message)
                        
            # to all autonomous bots            
            elif last_receiver == 'auto_bots':
                for target_id in range(len(bot_type)):
                    if bot_type[target_id] == c.VALUE_TYPE_AUTO:
                        target_ip = c.SUBNET_IP + str(c.TEAM_START + target_id)
Beispiel #9
0
                elif mode == 'STOP':
                    SPEED = SPEED_STOP
                # Speedlimits
                if SPEED > 100:
                    SPEED = 100
                elif SPEED < 0:
                    SPEED = 0
                pi2go.go(SPEED, SPEED)

            # Send
            if mode != prev_mode:
                if prev_mode == 'STOP':
                    #print 'RELEASE'
                    message = 'RELEASE'
                    for x in range(SENDING_ATTEMPTS):
                        communication.send_broadcast_message(PORT, message)
                        time.sleep(WAIT_SEND)
                elif mode == 'STOP':
                    #print 'PROBLEM'
                    message = 'PROBLEM'
                    for x in range(PUSH):
                        communication.send_broadcast_message(PORT, message)
                        time.sleep(WAIT_SEND)

        else:
            print 'impossible STATE'
            STATE == 'RUNNING'

except KeyboardInterrupt:
    print 'KEYBOARD'
Beispiel #10
0
                elif mode == "STOP":
                    SPEED = SPEED_STOP
                # Speedlimits
                if SPEED > 100:
                    SPEED = 100
                elif SPEED < 0:
                    SPEED = 0
                pi2go.go(SPEED, SPEED)

            # Send
            if mode != prev_mode:
                if prev_mode == "STOP":
                    # print 'RELEASE'
                    message = "RELEASE"
                    for x in range(SENDING_ATTEMPTS):
                        communication.send_broadcast_message(PORT, message)
                        time.sleep(WAIT_SEND)
                elif mode == "STOP":
                    # print 'PROBLEM'
                    message = "PROBLEM"
                    for x in range(PUSH):
                        communication.send_broadcast_message(PORT, message)
                        time.sleep(WAIT_SEND)

        else:
            print "impossible STATE"
            STATE == "RUNNING"

except KeyboardInterrupt:
    print "KEYBOARD"
            state = STATE_WARN
            state_string = "WARN"
        else:
            state = STATE_RUN
            state_string = "RUN"

        if state != prev_state:
            print state_string
            if state == STATE_RUN:
                pi2go.setAllLEDs(LEDoff, LEDon, LEDoff)
            elif state == STATE_WARN:
                pi2go.setAllLEDs(LEDon, LEDon, LEDoff)
            elif state == STATE_STOP:
                pi2go.setAllLEDs(LEDon, LEDoff, LEDoff)
            else:
                print "unknown state!"
            #print time.time()
            #message = "State: " + state + " at " + str(time.time())
            print "Starting broadcast"
            for x in range(0, 10):
                message = "    State: " + state_string + " at " + str(
                    time.time()) + " #" + str(x)
                communication.send_broadcast_message(38234, message)
            #print time.time()
            print "Broadcast finished"
        prev_state = state
except KeyboardInterrupt:
    pass
finally:
    pi2go.cleanup()
Beispiel #12
0
def send_new_status(msg,repetitions,space):
    for x in range(repetitions):
        com.send_broadcast_message(c.PORT, msg)
        time.sleep(space)