Esempio n. 1
0
    def __init__(self, master=None):
        self.data = ""
        self.latitude = 0.0
        self.longitude = 0.0
        self.height = 0.0
        self.lat0 = 40.242865
        self.lon0 = 140.010450

        # pyproj
        self.geo = geod.Geod(ellps='WGS84')

        # communication
        self.com = com.Communication(COMPORT)
        # [緯度, 経度(, 高度)]

        # figure
        self.fig_map = figure.Map()
        # self.fig_height = figure.Height()

        # Tkinter
        super().__init__(master)
        self.master = master
        self.master.title("TelemetryViewer")
        self.master.geometry("1024x768")
        self.master.resizable(True, True)
        self.pack()
        self.create_widgets()
        self.master.after(1000, self.update_widgets)
Esempio n. 2
0
 def __init__(self,
              behavior=BEHAVIOR_DEFAULT,
              ivy_address=IVY_ADDRESS_DEFAULT,
              static_obstacles_file=STATIC_OBSTACLES_FILE,
              lidar_mask_file=LIDAR_MASK_FILE,
              teensy_serial_path=TEENSY_SERIAL_PATH_DEFAULT):
     self.map = map.Map(self, static_obstacles_file, lidar_mask_file)
     self.table = Table(self)
     self.storages = {
         AtomStorage.Side.RIGHT: AtomStorage(robot, AtomStorage.Side.RIGHT),
         AtomStorage.Side.LEFT: AtomStorage(robot, AtomStorage.Side.LEFT)
     }
     self.communication = communication.Communication(teensy_serial_path)
     self.communication.start()
     self.io = IO(self)
     self.locomotion = Locomotion(self)
     self.ivy = ivy_robot.Ivy(self, ivy_address)
     if behavior == Behaviors.FSMMatch.value:
         from behavior.fsmmatch import FSMMatch
         self.behavior = FSMMatch(self)
     elif behavior == Behaviors.FSMTests.value:
         raise NotImplementedError("This behavior is not implemented yet !")
     elif behavior == Behaviors.Slave.value:
         from behavior.slave import Slave
         self.behavior = Slave(self)
     else:
         raise NotImplementedError("This behavior is not implemented yet !")
def main():
    c = communication.Communication("/dev/ttyUSB0")
    iv = perform_IV_exchange(c)
    Cipher = cipher.Cipher(iv)
    Encoder = encoder.Encoder(Cipher)

    while True:
        communicate(c, Encoder, Cipher)
Esempio n. 4
0
def main(screen):
	comm = communication.Communication(username, password, ip, port, sourceport)
	screen.nodelay(1)
	percentagedir = 100
	percentage = 80
	while True:
		char = screen.getch()
		if char == 113: break  # q
		elif char == 65: comm.auth() # A = authentication
		elif char == 119: comm.movePercentage('forward',percentage) # w
		elif char == 87: comm.movePercentage('left', 0) # W
		elif char == 97: comm.movePercentage('left',percentagedir) # a
		elif char == 115: comm.movePercentage('backward',percentage) # s
		elif char == 100: comm.movePercentage('right',percentagedir) #d
		elif char == 32: comm.movePercentage('forward',0) # space
		time.sleep(0.1)
Esempio n. 5
0
def initNetwork():
    global communicator
    global sourceIP
    Users = ConfigParser.ConfigParser()
    Users.read('users.ini')
    options = Users.options('users')
    #    print(options)
    dict1 = {}
    for option in options:
        username = option
        #        print(username)
        try:
            dict1[option] = Users.get('users', option)
            password = dict1[username]
            #            print(password)
            #            print(dict1)
            if dict1[option] == -1:
                DebugPrint("skip: %s" % option)
            break
        except:
            print("exception on %s!" % option)
            dict1[option] = None
    Network = ConfigParser.ConfigParser()
    Network.read('network.ini')
    netOptions = Network.options('network')

    dict1 = {}
    for option in netOptions:
        try:
            dict1[option] = Network.get('network', option)

            if dict1[option] == -1:
                DebugPrint("skip: %s" % option)

        except:
            print("exception on %s!" % option)
            dict1[option] = None

    ip = dict1['ip']
    sourceIP = ip
    port = int(dict1['port'])
    sourceport = int(dict1['sourceport'])

    communicator = communication.Communication(username, password, ip, port,
                                               sourceport)
    communicator.auth()
Esempio n. 6
0
 def __init__(self,
              behavior=BEHAVIOR_DEFAULT,
              ivy_address=IVY_ADDRESS_DEFAULT,
              lidar_mask_file=LIDAR_MASK_FILE,
              teensy_serial_path=TEENSY_SERIAL_PATH_DEFAULT):
     self.map = map.Map(self, lidar_mask_file)
     self.communication = communication.Communication(teensy_serial_path)
     self.io = IO(self)
     self.locomotion = Locomotion(self)
     self.ivy = ivy_robot.Ivy(self, ivy_address)
     if behavior == Behaviors.FSMMatch.value:
         from behavior.fsmmatch import FSMMatch
         self.behavior = FSMMatch(self)
     elif behavior == Behaviors.FSMTests.value:
         raise NotImplementedError("This behavior is not implemented yet !")
     elif behavior == Behaviors.Slave.value:
         from behavior.slave import Slave
         self.behavior = Slave(self)
     else:
         raise NotImplementedError("This behavior is not implemented yet !")
Esempio n. 7
0
    def init_communication(self, data=None):
        """
        Initialize communication

        :param data: Optional data
        """
        logging.debug('Initializing communication')
        try:
            self.com.__del__()
        except AttributeError:
            # self.com may not exist. This is not an issue: keep going
            pass

        try:
            self.com = communication.Communication()
        except IOError:
            self.msg_print("Failed to initialize communication")
            self.show_alert_communication()
        else:
            self.msg_print("Communication initialized")
            self.init_device()
    from PyQt5.QtGui import QFont

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import communication

#progname = os.path.basename(sys.argv[0])
progname = "GPS Coordinate Entry UI"
progversion = "0.1"

# format is [[x], [y], [x2], [y2], [x3], [y3]]
dataPoints = [[], [], [], [], [], []]

com = communication.Communication(sys.argv[1], float(sys.argv[2]))


class MyMplCanvas(FigureCanvas):
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)

        self.compute_initial_figure()

        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding,
                                   QtWidgets.QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
 def __init__(self):
     self.comm = communication.Communication()
Esempio n. 10
0
                        type=int,
                        help='Only test purposes!',
                        default=0,
                        required=False)
    parser.add_argument('--humid',
                        type=int,
                        help='Only test purposes!',
                        default=0,
                        required=False)
    parser.add_argument('--pressure',
                        type=int,
                        help='Only test purposes!',
                        default=0,
                        required=False)
    return parser.parse_args()


args = parse_args()

from airsensor import MockAirSensor

# Sensors decorator
air_sensor = MockAirSensor(args.pm1_0, args.pm2_5, args.pm10, args.temp,
                           args.humid, args.pressure)

import communication
communication = communication.Communication(args.url)

import common_app
app = common_app.CommonApp(air_sensor, communication, args)
app.start()
Esempio n. 11
0
 def connect_thread(self):
     self.connect = communication.Communication(mode='CONNECT',
                                                msg_queue=msg_queue)
Esempio n. 12
0
 def listen_thread(self):
     self.listen = communication.Communication(mode='LISTEN',
                                               msg_queue=msg_queue)
     self.listen.listen_manager()
Esempio n. 13
0
 def __init__(self, port):
     self.connection = communication.Communication(port)
Esempio n. 14
0
    def __init__(self):
        window = Tk()
        window.title(TITLE)
        window.config(bg=COLOR_WINDOW_BG)
        window.protocol("WM_DELETE_WINDOW", self.__onClose)

        labelBrdId = Label(window,
                           text=LABEL_TEXT_BRD_ID,
                           width=LABEL_WIDTH,
                           anchor=LABEL_ANCHOR)
        labelBrdName = Label(window,
                             text=LABEL_TEXT_BRD_NAME,
                             width=LABEL_WIDTH,
                             anchor=LABEL_ANCHOR)
        labelPort = Label(window,
                          text=LABEL_TEXT_PORT,
                          width=LABEL_WIDTH,
                          anchor=LABEL_ANCHOR)
        labelMode = Label(window,
                          text=LABEL_TEXT_MODE,
                          width=LABEL_WIDTH,
                          anchor=LABEL_ANCHOR)
        labelReadout = Label(window,
                             text=LABEL_TEXT_READOUT,
                             width=LABEL_WIDTH,
                             anchor=LABEL_ANCHOR)
        labelHeatup = Label(window,
                            text=LABEL_TEXT_HEATUP,
                            width=LABEL_WIDTH,
                            anchor=LABEL_ANCHOR)
        labelCooldown = Label(window,
                              text=LABEL_TEXT_COOLDOWN,
                              width=LABEL_WIDTH,
                              anchor=LABEL_ANCHOR)
        labelTime = Label(window,
                          text=LABEL_TEXT_TIME,
                          width=LABEL_WIDTH,
                          anchor=LABEL_ANCHOR)

        variablesPort = StringVar(window)
        ports = COMM.serial_ports()
        variablesPort.set(ports[-1])
        self.__variablesPort = variablesPort

        variablesMode = StringVar(window)
        modes = list(SETTINGS.MODES)
        variablesMode.set(modes[0])
        self.__variablesMode = variablesMode

        variablesTime = StringVar(window)
        times = list(SETTINGS.TIMES)
        variablesTime.set(times[0])
        self.__variablesTime = variablesTime

        entryBrdId = Entry(window, width=ENTRY_WIDTH)
        entryBrdName = Entry(window, width=ENTRY_WIDTH)
        #        entryPort       = Entry(window, width=ENTRY_WIDTH);
        entryPort = OptionMenu(window, variablesPort, *ports)
        entryPort.config(width=ENTRY_OPTION_WIDTH)
        entryMode = OptionMenu(window, variablesMode, *modes)
        entryMode.config(width=ENTRY_OPTION_WIDTH)
        entryReadout = Entry(window, width=ENTRY_WIDTH)
        entryHeatup = Entry(window, width=ENTRY_WIDTH)
        entryCooldown = Entry(window, width=ENTRY_WIDTH)
        entryTime = OptionMenu(window, variablesTime, *times)
        entryTime.config(width=ENTRY_OPTION_WIDTH)

        entryBrdId.insert(0, DEFAULT_BRD_ID)
        entryBrdName.insert(0, DEFAULT_BRD_NAME)
        entryReadout.insert(0, DEFAULT_READOUT)
        entryHeatup.insert(0, DEFAULT_HEATUP)
        entryCooldown.insert(0, DEFAULT_COOLDOWN)

        buttonCon = Button(window,
                           text=BUTTON_TEXT_CONNECT,
                           command=self.__button_action_con,
                           width=BUTTON_WIDTH)
        buttonMeasurement = Button(window,
                                   text=BUTTON_TEXT_MEASUREMENT,
                                   command=self.__button_action_measurement,
                                   width=BUTTON_WIDTH)
        buttonVisualize = Button(window,
                                 text=BUTTON_TEXT_VISUALIZE,
                                 command=self.__button_action_visualize,
                                 width=BUTTON_WIDTH)
        labelStatus = Label(window,
                            text=TEXT_STATUS_DISCONNECT,
                            width=BUTTON_WIDTH,
                            anchor='center',
                            bg=STATUS_COLOR_DISCONNECT)
        labelError = Label(window,
                           text="",
                           width=BUTTON_WIDTH,
                           anchor='center',
                           bg=ERROR_COLOR_NON)

        progress = ttk.Progressbar(window, orient="horizontal", length=300)
        labelProgress = Label(window,
                              text="",
                              width=ENTRY_WIDTH + BUTTON_WIDTH + LABEL_WIDTH,
                              anchor='center')

        labelBrdId.grid(row=0, column=0)
        labelBrdName.grid(row=1, column=0)
        labelPort.grid(row=2, column=0)
        labelMode.grid(row=3, column=0)
        labelReadout.grid(row=4, column=0)
        labelHeatup.grid(row=5, column=0)
        labelCooldown.grid(row=6, column=0)
        labelTime.grid(row=7, column=0)

        entryBrdId.grid(row=0, column=1, padx=5)
        entryBrdName.grid(row=1, column=1, padx=5)
        entryPort.grid(row=2, column=1, padx=5)
        entryMode.grid(row=3, column=1, padx=5)
        entryReadout.grid(row=4, column=1, padx=5)
        entryHeatup.grid(row=5, column=1, padx=5)
        entryCooldown.grid(row=6, column=1, padx=5)
        entryTime.grid(row=7, column=1, padx=5)

        labelStatus.grid(row=0, column=2, padx=20)
        buttonCon.grid(row=1, column=2, padx=20)
        buttonMeasurement.grid(row=2, column=2, padx=20)
        buttonVisualize.grid(row=3, column=2, padx=20)
        labelError.grid(row=4, column=2, padx=20, rowspan=3)

        progress.grid(row=8, column=0, columnspan=3, pady=5)
        labelProgress.grid(row=9, column=0, columnspan=3)

        self.__progress = progress
        self.__labelProgress = labelProgress

        self.__entryBrdId = entryBrdId
        self.__entryBrdName = entryBrdName
        self.__entryPort = entryPort
        self.__entryMode = entryMode
        self.__entryReadout = entryReadout
        self.__entryHeatup = entryHeatup
        self.__entryCooldown = entryCooldown
        self.__entryTime = entryTime
        self.__labelStatus = labelStatus
        self.__labelError = labelError
        self.__buttonCon = buttonCon
        self.__buttonMeasurement = buttonMeasurement
        self.__buttonVisualize = buttonVisualize

        s = SETTINGS.Settings()
        self.__comm = COMM.Communication(s)

        self.__measuring = 0

        self.__visWindows = []

        self.__window = window
        self.__window.mainloop()
Esempio n. 15
0
def run():
    # DO NOT EDIT
    # the deploy script uses this variable to stop the mqtt client after your program stops or crashes.
    # your script isn't able to close the client after crashing.
    global client
    client = mqtt.Client(
        client_id=str(
            uuid.uuid4()),  # client_id has to be unique among ALL users
        clean_session=False,
        protocol=mqtt.MQTTv31)

    # the execution of all code shall be started from within this function
    # ADD YOUR OWN IMPLEMENTATION HEREAFTER
    global messageContent
    messageContent = msc.MessageContent()

    planet = p.Planet()

    comm = communication.Communication(client, messageContent, planet)
    # comm.send_test_planet_message() # testing purpose todo: remove at end

    firstNodeFound = False
    targetReached = False
    mapExplored = False
    lastNode = None
    turnTo = None
    isInShortestPath = False

    while not targetReached or not mapExplored:

        pid.follow_line()
        node = None
        if not firstNodeFound:
            comm.send_deploy_message()
            firstNodeFound = True
            print("Found first node!")
            node = planet.add_start_node(messageContent.getStartX(),
                                         messageContent.getStartY())
            print(">First node: ", node)

        else:
            comm.send_path_message()
            #planet.nodes.add(p.Node(messageContent.getStartX(), messageContent.getStartY()))
            print(">Path:", ((lastNode.x, lastNode.y), turnTo),
                  ((messageContent.getEndX(),
                    messageContent.getEndY()), messageContent.getComeFrom()),
                  messageContent.getPathWeight())
            node = planet.add_server_path(
                ((lastNode.x, lastNode.y), turnTo),
                ((messageContent.getEndX(), messageContent.getEndY()),
                 messageContent.getComeFrom()), messageContent.getPathWeight())
            print(">End node:", node)

        comeFrom = messageContent.getComeFrom()
        if type(comeFrom) != Direction:
            print("come from was no enum yet")
            comeFrom = to_enum(comeFrom)

        # unknown paths are in node after scan
        abc.scan(node, comeFrom)

        if node.has_unexplored_paths():
            turnTo = node.get_unexplored_paths().pop()
        else:
            #turnTo = comeFrom

            for n in planet.nodes:
                if n.has_unexplored_paths() and n.is_visited:
                    print("=====================")
                    print(">Node: ", node, "\nn: ", n)
                    print("=====================")
                    #print(planet.get_paths())
                    #nextNode = find_next_node(node, planet)
                    #print(nextNode)
                    pathlist = planet.shortest_path((node.x, node.y),
                                                    (n.x, n.y))
                    messageContent.setTargetX(n.x)
                    messageContent.setTargetY(n.y)

                    if pathlist != None:
                        turnTo = pathlist[0][1]

                    print("The pathlist: ", pathlist)
                    print("Turn to next nearest node: ", turnTo)

                else:
                    messageContent.setMessage(
                        "Planet" + messageContent.getPlanetName() +
                        " is now discovered property of group 106!")
                    print(messageContent.getMessage())
                    comm.send_exploration_completed_message()
                    mapExplored = True

            # make shortest path, drive this list, continue

        if type(turnTo) != Direction:
            print("turnTo was no enum yet")
            turnTo = to_enum(turnTo)

        messageContent.setStartDirection(turnTo)

        print("We come from: ", comeFrom)
        print("We turn to: ", turnTo)
        print("Node after scan: ", node)
        messageContent.setPathX(node.x)
        messageContent.setPathY(node.y)

        comm.send_path_selection()

        print("Comm sended path selection")
        print("new Start: ", messageContent.getStartDirection())
        print("new End: ", messageContent.getEndDirection())

        turns = rc.rotate_to_target(comeFrom, turnTo)
        if turns < 0:
            movement_definitions.turn_90degree_right()
        else:
            for i in range(0, turns):
                movement_definitions.turn_90degree_left()

        node.set_path_to_explored(turnTo)
        messageContent.setPathStatus("free")

        messageContent.setStartX(messageContent.getEndX())
        messageContent.setStartY(messageContent.getEndY())

        lastNode = node

        #print(node.unknownPaths)

    # when finishing successfully
    ev3.Sound.tone(15000, 1000).wait()
Esempio n. 16
0
import communication
import recognition
import threading
# import logging

haar_file_path = 'haarcascade_frontalface_default.xml'
SOURCE_IP = '127.0.0.1'
SOURCE_PORT = 5006
DESTINATION_IP = '127.0.0.1'
DESTINATION_PORT = 5005
connection = communication.Communication(SOURCE_IP, DESTINATION_IP,
                                         SOURCE_PORT, DESTINATION_PORT)
connection.bind_socket()
face_recognition = recognition.Recognition(haar_file_path)
# log = logging.getLogger(__name__)
# LOG_FILENAME = 'local.log'
# logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG, format='%(asctime)s %(message)s')


def receive():
    while True:
        data, address = connection.receive_packet()
        print(data, address)


command = ""
t = threading.Thread(target=receive)
t.daemon = True
t.start()

while command != 'q':