예제 #1
0
def _scan_roll(stepper_device: stepper_motor.StepperMotor, lux_meter_device: lux_meter.LuxMeter, led_device: led.Led, skip_button: Button, camera_device: camera.Camera) -> int:
    count = 0
    for photo_index in _scroll_to_next(stepper_device, lux_meter_device, led_device, skip_button):
        time.sleep(0.5)     # Wait 1/2s in order to stabilize
        camera_device.take_photo()
        count += 1
    
    return count
예제 #2
0
 def __init__(self, engine):
   """
     engine is an instance of the Engine object that controls
     the hardware of the raspberry pi.
   """
   self.created = time.time()
   self.engine = engine
   # Number of times a move command has been issued
   self.moves = 0
   # What times move commands were issued at
   self.moves_times = []
   # Camera control 
   self.camera = Camera(flip_vertical=True, width=320, height=240)
예제 #3
0
    def __init__(self, offsite=False):
        """
        Measurement sequence class

        Parameters
        ----------
        offsite: bool, optional
            Determines if the system is operating with a connected setup or simulating the process from previously captured images
        """
        self.offsite = offsite
        print(_C.CYAN + _C.BOLD + 'Initializing sequence' + _C.ENDC)
        if self.offsite:
            self.prime = self._placeholder
            self.disable = self._placeholder
            self.calibrate = self.calibrateOffsite
            self.evaluate = self.evaluateOffsite
            self.measure = self.measureOffsite

        else:
            self.cam = Camera()
            if not self.cam.camera_available:
                print(_C.RED +
                      'No camera connected. Check USB and power connection.' +
                      _C.ENDC)
                sys.exit()

            self.stp = Stepper(autoEnable=False)
            print(_C.LIME + 'Ready for priming' + _C.ENDC)
        self.primed = False
예제 #4
0
    def __init__(self):
        self.rear_motor = Motor(motor_type="rear_motor")
        self.front_motor = Motor(motor_type="front_motor")

        self.front_right_blinker = Blinker(7)
        self.fron_left_blinker = Blinker(11)

        self.range_sensor = RangeSensor()
        self.camera = Camera()
예제 #5
0
def main(args):
    cam = Camera(1)
    projector = Projector(1)
    projector.load_configuration(args.calibration_path)

    segmenter_brain = DeeplabImageSegmenter.from_path(args.segment_path,
                                                      args.segment_map)

    detector_brain = None  # ObjectDetector.from_path(args.detector_path, args.detector_labels)

    device = Device(args.device_port)

    demo = Demo(camera=cam,
                projector=projector,
                segmentation_brain=segmenter_brain,
                detector_brain=detector_brain,
                device=device)
    demo.run()
예제 #6
0
 def __init__(self):
     self.rear_motor = Motor(motor_type="rear_motor")
     self.front_motor = Motor(motor_type="front_motor")
     self.range_sensor = RangeSensor()
     self.camera = Camera()
예제 #7
0
                        help="The path/filename to save the config *.json to.")
    parser.add_argument("-c",
                        "--cam-id",
                        type=int,
                        required=True,
                        help="The camera ID (must be integer > 0)")
    parser.add_argument("-p",
                        "--projector-id",
                        type=int,
                        required=True,
                        help="The monitor ID representing the projector. "
                        "Try numbers 0-# monitors, if you don't know.")
    args = parser.parse_args()

    p = Projector(args.projector_id)
    c = Camera(1)

    factory = SurfaceFactory(c, p)
    print(intro_text)
    input()
    while True:
        new_surface = factory.create_surface()
        p.surfaces.append(new_surface)

        ans = ""
        while "y" not in ans.lower() and "n" not in ans.lower():
            ans = input("Would you like to create another surface? (y/n)")
        if "n" in ans.lower():
            break

    p.save_configuration(args.save_to)
예제 #8
0
class Car(object):
  WHEEL_RADIUS_CM = 1

  def __init__(self, engine):
    """
      engine is an instance of the Engine object that controls
      the hardware of the raspberry pi.
    """
    self.created = time.time()
    self.engine = engine
    # Number of times a move command has been issued
    self.moves = 0
    # What times move commands were issued at
    self.moves_times = []
    # Camera control 
    self.camera = Camera(flip_vertical=True, width=320, height=240)
  
  def get_distance_travelled(self):
    """ Returns how much distance has been travelled in total """

    circumference = 2 * math.pi * self.WHEEL_RADIUS_CM 
    return circumference * self.engine.revolutions_per_move * self.moves
  
  def currently_moving(self):
    """ Returns whether car moved in the last two seconds """

    try:
      return abs((self.moves_times[-1] + self.engine.move_duration) - time.time()) <= 2
    except IndexError:
      return False

  def move_car(self, direction):
    """
      Moves the car in the direction specified by one unit, which is
      defined as the duration in the engine. Direction is a string
      ['straight', 'left' or 'right'].
    """
    directions = {
      'straight': self.engine.go_straight,
      'left': self.engine.go_left,
      'right': self.engine.go_right
    }
    try:
      move_success = directions[direction]()
      self.moves_times.append(time.time())
      self.moves += 1
    except KeyError:
      # Illegal command was issued
      move_success = False
    return move_success

  def go_straight(self):
    """
      Moves the car forward; returns False is failure or tuple of current car 
      sensors if successful (inputs are Ultrasonic and camera)
    """

    return self.move_car('straight')

  def go_left(self):
    """
      Moves the car forward; returns False is failure or tuple of current car 
      sensors if successful (inputs are Ultrasonic and camera)
    """
    return self.move_car('left')

  def go_right(self):
    """
      Moves the car right; returns False is failure or tuple of current car 
      sensors if successful (inputs are Ultrasonic and camera)
    """

    return self.move_car('right')

  def get_image(self):
    """ Returns a processed image from the car - a base64 representation of a JPEG """
    latest_image_data = self.camera.get_latest_image()
    # tobase64 produces a bytes object that stringifies as "b'<data>'" ; start at pos 2 
    # to chop off the quotation mark and 'b' character and get a proper string
    try:
      return str(latest_image_data.tobase64())[2:-1]
    except IndexError:
      # In the odd case that string is too short
      return str(latest_image_data.tobase64())

  def get_distance(self):
    """ Returns current forward distance """
    return self.engine.get_us_distance()

  def get_moves(self):
    return self.moves
예제 #9
0
 def test_resolution(self):
     camera = Camera(width=999, height=999)
     self.assertEqual(camera.width, 999)
     self.assertEqual(camera.height, 999)
예제 #10
0
 def test_frame(self):
     camera = Camera()
     self.assertEqual(camera.frame, None,
                      'frame is defined before data acquired')
예제 #11
0
from examples import demos
from hardware.camera import Camera
from hardware.projector import Projector
"""
This is a quick example on how to run a demo from the demos module
"""

# Open a camera
cam = Camera(0)

# Calibrate the projector
projector = Projector(2)
projector.load_configuration("../projector-config.json")

# Run the demo of your choice
# demos.draw_edged(cam, projector)
# demos.draw_pointer(cam, projector)
# demos.draw_edged_snapshot(cam, projector)
demos.draw_inverted(cam, projector)