Exemplo n.º 1
0
def main():
    # CMD args parser
    parser = argparse.ArgumentParser(description='openmv stress test')
    parser.add_argument("-j", "--disable_fb", action = "store_true",  help = "Disable FB JPEG compression")
    parser.add_argument("-p", "--port",   action = "store", help = "OpenMV serial port")
    parser.add_argument("-t", "--time",   action = "store", default = 100, help = "Max time before stopping the script")
    parser.add_argument("-s", "--script", action = "store",\
            default="../scripts/examples/01-Basics/helloworld.py", help = "OpenMV script file")

    # Parse CMD args
    args = parser.parse_args()

    # init openmv
    if (args.port):
        portname = args.port
    elif 'darwin' in sys.platform:
        portname = "/dev/cu.usbmodem14221"
    else:
        portname = "/dev/openmvcam"
    
    print("\n>>>Reading script: %s\n" %(args.script))
    with open(args.script, "r") as f:
        script = f.read()
    print("%s\n" %(script))

    connected = False
    for i in range(10):
        try:
            # Open serial port.
            # Set small timeout when connecting
            pyopenmv.init(portname, baudrate=921600, timeout=0.050)
            connected = True
            break
        except Exception as e:
            connected = False
            sleep(0.100)
    
    if not connected:
        print ( "Failed to connect to OpenMV's serial port.\n"
                "Please install OpenMV's udev rules first:\n"
                "sudo cp openmv/udev/50-openmv.rules /etc/udev/rules.d/\n"
                "sudo udevadm control --reload-rules\n\n")
        sys.exit(1)
    
    # Set higher timeout after connecting.
    pyopenmv.set_timeout(0.500)

    # Enable/Disable framebuffer compression.
    print(">>>Enable FB JPEG compression %s" %(str(not args.disable_fb)))
    pyopenmv.enable_fb(not args.disable_fb)

    # Interrupt running script.
    pyopenmv.stop_script()
    max_timeout = int(args.time)
    for i in xrange(1000):
        pyopenmv.exec_script(script)
        sleep(randint(0, max_timeout)/1000)
        pyopenmv.stop_script()
Exemplo n.º 2
0
    def __init__(self, port="/dev/openmvcam"):
        self.port = port
        self.connected = False

        pyopenmv.disconnect()
        rospy.loginfo("Connecting...")
        for i in range(10):
            try:
                # opens CDC port.
                # Set small timeout when connecting
                pyopenmv.init(self.port, baudrate=921600, timeout=0.050)
                self.connected = True
                break
            except Exception as e:
                self.connected = False
                sleep(0.100)

        if not self.connected:
            rospy.logerr("Failed to connect to OpenMV's serial port.\n"
                        "Please install OpenMV's udev rules first:\n"
                        "sudo cp openmv/udev/50-openmv.rules /etc/udev/rules.d/\n"
                        "sudo udevadm control --reload-rules\n\n")
            return
        rospy.loginfo("Connected!")
        # Set higher timeout after connecting for lengthy transfers.
        pyopenmv.set_timeout(1*2)  # SD Cards can cause big hicups.
        pyopenmv.stop_script()
        pyopenmv.enable_fb(True)
        pyopenmv.exec_script(script)

        # init pub
        self.pub_image = rospy.Publisher("/image", Image, queue_size=10)

        # init thread
        self.running = False
        self.thread = Thread(target=self.run)
        self.thread.start()

        rospy.on_shutdown(self.shutdown)
Exemplo n.º 3
0
def camera_connect():
    """
    Camera connection loop.
    """

    connected = False
    pyopenmv.disconnect()
    # try and connect
    for i in range(10):

        try:
            # opens CDC port.
            # Set small timeout when connecting
            pyopenmv.init(port_name, baudrate=921600, timeout=0.050)
            connected = True
            break
        except Exception as e:
            connected = False
            sleep(0.100)
    if not connected:
        print("Failed to connect to OpenMV's serial port.\n"
              "Please install OpenMV's udev rules first:\n"
              "sudo cp openmv/udev/50-openmv.rules /etc/udev/rules.d/\n"
              "sudo udevadm control --reload-rules\n\n")
        sys.exit(1)
    # Set higher timeout after connecting for lengthy transfers.
    pyopenmv.set_timeout(1 * 2)  # SD Cards can cause big hicups.
    pyopenmv.stop_script()
    pyopenmv.enable_fb(True)
    pyopenmv.exec_script(blob_script)

    # init screen
    running = True
    Clock = pygame.time.Clock()
    font = pygame.font.SysFont("monospace", 15)

    return running, Clock, font
Exemplo n.º 4
0
        break
    except Exception as e:
        connected = False
        sleep(0.100)

if not connected:
    print ( "Failed to connect to OpenMV's serial port.\n"
            "Please install OpenMV's udev rules first:\n"
            "sudo cp openmv/udev/50-openmv.rules /etc/udev/rules.d/\n"
            "sudo udevadm control --reload-rules\n\n")
    sys.exit(1)

# Set higher timeout after connecting for lengthy transfers.
pyopenmv.set_timeout(1*2) # SD Cards can cause big hicups.
pyopenmv.stop_script()
pyopenmv.enable_fb(True)
pyopenmv.exec_script(script)

# init screen
running = True
Clock = pygame.time.Clock()
font = pygame.font.SysFont("monospace", 15)

while running:
    Clock.tick(100)

    # read framebuffer
    fb = pyopenmv.fb_dump()
    if fb != None:
        # create image from RGB888
        image = pygame.image.frombuffer(fb[2].flat[0:], (fb[0], fb[1]), 'RGB')
Exemplo n.º 5
0
        break
    except Exception as e:
        connected = False
        sleep(0.100)

if not connected:
    print ( "Failed to connect to OpenMV's serial port.\n"
            "Please install OpenMV's udev rules first:\n"
            "sudo cp openmv/udev/50-openmv.rules /etc/udev/rules.d/\n"
            "sudo udevadm control --reload-rules\n\n")
    sys.exit(1)

# Set higher timeout after connecting for lengthy transfers.
pyopenmv.set_timeout(1*2) # SD Cards can cause big hicups.
pyopenmv.stop_script()
pyopenmv.enable_fb(True)
pyopenmv.exec_script(script)

# init screen
running = True
Clock = pygame.time.Clock()
font = pygame.font.SysFont("monospace", 15)

while running:
    Clock.tick(100)

    # read framebuffer
    fb = pyopenmv.fb_dump()
    if fb != None:
        # create image from RGB888
        image = pygame.image.frombuffer(fb[2].flat[0:], (fb[0], fb[1]), 'RGB')