示例#1
0
    def __init__(self):
        super().__init__()
        self.running = False

        self.reload()

        self.motors = []
        try:
            self.motors.append(motor.LargeMotor(motor.OUTPUT_A))
        except:
            pass
        try:
            self.motors.append(motor.LargeMotor(motor.OUTPUT_B))
        except:
            pass
        try:
            self.motors.append(motor.LargeMotor(motor.OUTPUT_C))
        except:
            pass
        try:
            self.motors.append(motor.LargeMotor(motor.OUTPUT_D))
        except:
            pass

        self.servos = []
        try:
            self.servos.append(motor.MediumMotor(motor.OUTPUT_A))
            self._servo_counter += 1
        except:
            pass
        try:
            self.servos.append(motor.MediumMotor(motor.OUTPUT_B))
            self._servo_counter += 1
        except:
            pass
        try:
            self.servos.append(motor.MediumMotor(motor.OUTPUT_C))
            self._servo_counter += 1
        except:
            pass
        try:
            self.servos.append(motor.MediumMotor(motor.OUTPUT_D))
            self._servo_counter += 1
        except:
            pass

        self.sound = None
        try:
            self.sound = sound.Sound()
        except:
            pass

        self.infrared_sensor = None
        try:
            self.infrared_sensor = lego.InfraredSensor(sensor.INPUT_1)
        except:
            pass

        self.running = True
示例#2
0
    def __init__(self):
        # motors
        self.motor_links_poort = OUTPUT_B
        self.motor_rechts_poort = OUTPUT_C
        self.motor_links = LargeMotor(self.motor_links_poort)
        self.motor_rechts = LargeMotor(self.motor_rechts_poort)
        self.geluid = sound.Sound()
        self.motor_grijper = MediumMotor(OUTPUT_A)

        # sensors
        self.gyro = GyroSensor(address=INPUT_2)
        self.touch = TouchSensor(address=INPUT_1)
        self.kleur = ColorSensor(address=INPUT_3)

        # start data logger in eigen thread
        t_data_logger = threading.Thread(target=self.data_logger)
        t_data_logger.start()

        # slechte oplossing gyro probleem
        self.laatst_gemeten_hoek = 0

        self.gyro.mode = self.gyro.MODE_GYRO_RATE
        time.sleep(1)
        self.gyro.mode = self.gyro.MODE_GYRO_ANG
示例#3
0
#!/usr/bin/env python3

print("start program")

from time import sleep

from ev3dev2 import sound
mySound = sound.Sound()

# import logging library specially for ev3
from ev3devlogging import getLogger
# for levels import standard logging library
# all possible levels: DEBUG,INFO,WARNING,ERROR,CRITICAL
import logging

# get logger
#   * without times
#   * which only shows log messages from level INFO or higher
logger = getLogger(timing=False, defaultThresholdLevel=logging.INFO)

## uncomment next line to disable logging
#logger.disabled=True;

# in advanced logger you can log in different levels
logger.debug("debug msg")
logger.critical("critical msg")
logger.info("info msg")
logger.warn("warn msg")
logger.error("error msg")

# play beep sound