예제 #1
0
class ScripterExt(Scripter):
    def run_main(self):
        args = self.get_args()
        connection = args.connection
        if connection is None:
            conn_str = self.n_cfg.udp_ext['picam_1_to_robot']
        else:
            conn_str = connection

        self.logger.log_info("Starting camera, connecting robot")
        self.camera = PicamImpl(PicamImpl.RAW_BAYER)
        self.dconn = DronekitConnector(conn_str)
        self.logger.log_info("Startup complete")

        dirname = 'sc_%d' % int(time.time())
        self.camera.set_save_directory(dirname)
        started = False

        self.logger.log_info("Start mission capture")
        while not self.exit_all_loops:
            if self.dconn.get_mode() == 'AUTO':
                started = True
                try:
                    self.camera.capture_single()
                except Exception as e:
                    self.logger.log_error("Could not capture frame: %s" % e)

            if started and self.dconn.get_mode() != 'AUTO':
                break

    def close_script(self):
        try:
            self.dconn.disconnect()
        except:
            pass
예제 #2
0
    def run_main(self):
        args = self.get_args()
        args_ = {}

        if args.pin is None:
            raise Exception("Servo pin required")
        else:
            try:
                args_['servo_pin'] = int(args.pin)
            except:
                raise Exception("Valid servo pin required")

        self.fpw = FilterPosWheel(**args_)

        camera = PicamImpl()
        camera.set_save_directory('tests', 'filter_pos')

        while not self.exit_threads:
            progress("\
n: rotate to next filter\n\
p: rotate to previous filter\n\
a: capture image\n\
e: exit\n\
filter id, >0 : rotate to filter no.\n\
            ")
            try:
                c = input()
                if c == "n":
                    self.logger.log_info("Rotate to next filter...")
                    self.fpw.rotate_to_next()
                    self.logger.log_info("Filter reached: %d" %
                                         self.fpw.filter_id)
                elif c == "p":
                    self.logger.log_info("Rotate to previous filter...")
                    self.fpw.rotate_to_prev()
                    self.logger.log_info("Filter reached: %d" %
                                         self.fpw.filter_id)
                elif c == "e":
                    self.logger.log_info("Exiting...")
                    break
                elif c == "a":
                    self.logger.log_info("Capturing image...")
                    camera.capture_single()
                else:
                    try:
                        fid = int(c)
                        self.logger.log_info("Rotate to filter %d..." % fid)
                        self.fpw.rotate_to_filter(fid)
                        self.logger.log_info("Filter reached: %d" %
                                             self.fpw.filter_id)
                    except:
                        self.logger.log_info("Got keyboard input %s" % c)

            except Exception as e:
                self.logger.log_debug(e)
예제 #3
0
    def run_main(self):
        args = self.get_args()
        args_ = {}

        if args.pin is None:
            raise Exception("Servo pin required")
        else:
            args_['servo_pin'] = args.pin

        if args.filters is None:
            raise Exception("Filter count required")
        else:
            args_['filter_count'] = args.filters

        if args.c_thresh:
            args_['c_threshold'] = args.c_thresh
        # else:
        #     args_['c_threshold'] = 1000

        if args.c_thresh_var:
            args_['c_threshold_var'] = args.c_thresh_var
        # else:
        #     args_['c_threshold'] = 50

        fcw = FilterContWheel(**args_)
        if args.speed:
            speed = args.speed
        else:
            speed = 0.5

        camera = PicamImpl()
        camera.set_save_directory('tests', 'filter_cont')

        while not self.exit_threads:
            progress("====================================\n\
n: rotate to next filter\n\
r: rotate at current set speed\n\
s: stop rotation\n\
w: increase speed (max 1)\n\
q: decrease speed (min -1)\n\
d: check if notch is detected\n\
c: calibrate c threshold\n\
a: capture image\n\
e: exit\n\
filter id, >0 : rotate to filter no.\n\
====================================\n\
            ")
            try:
                c = input()
                if c == "n":
                    self.logger.log_info("Rotate to next filter...")
                    fcw.rotate_to_next(speed)
                    self.logger.log_info("Filter reached: %d" % fcw.filter_id)
                elif c == "r":
                    self.logger.log_info("Rotate at speed %f" % speed)
                    fcw.rotate(speed)
                elif c == "s":
                    fcw.halt()
                    self.logger.log_info("Rotation stopped")
                elif c == "w":
                    if speed < 1.0:
                        speed += 0.1
                    self.logger.log_info("Speed set to %f" % speed)
                elif c == "q":
                    if speed > -1.0:
                        speed -= 0.1
                    self.logger.log_info("Speed set to %f" % speed)
                elif c == "d":
                    self.logger.log_info("Check notch detected...")
                    detected = str(fcw.is_notch_detected())
                    self.logger.log_info("Notch detected: %s" % detected)
                elif c == "c":
                    self.logger.log_info("Calibrating c threshold...")
                    a = fcw.detect_c_threshold()
                    self.logger.log_info("C threshold found: %d" %
                                         fcw.c_threshold)
                    self.logger.log_info("C threshold found: %s" % str(a))
                elif c == "a":
                    self.logger.log_info("Capturing image...")
                    camera.capture_single()
                elif c == "e":
                    self.logger.log_info("Exiting...")
                    break
                else:
                    try:
                        fid = int(c)
                    except:
                        self.logger.log_info("Got keyboard input %s" % c)
                    else:
                        self.logger.log_info("Rotate to filter %d..." % fid)
                        fcw.rotate_to_filter(fid)
                        self.logger.log_info("Filter reached: %d" %
                                             fcw.filter_id)

            except Exception as e:
                self.logger.log_debug(e)
예제 #4
0
#!/usr/bin/env python3

import time
import sys
import signal
import threading

from picam_lib import PicamImpl

#### Setup

print("Starting camera, connecting robot")
camera = PicamImpl(PicamImpl.RAW_BAYER)
subdir = "swc_" % int(time.time())
camera.set_save_directory(subdir)
print("Startup complete")

#### Functions

exit_all_loops = False
exit_code = 1


def _sigint_handler(sig, frame):
    global exit_all_loops
    exit_all_loops = True


def _sigterm_handler(sig, frame):
    global exit_all_loops, exit_code
    exit_all_loops = True