def __init__(self, left_foot_motor_port: str = OUTPUT_B, right_foot_motor_port: str = OUTPUT_C, bazooka_blast_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): super().__init__(left_motor_port=left_foot_motor_port, right_motor_port=right_foot_motor_port, motor_class=LargeMotor, ir_sensor_port=ir_sensor_port, ir_beacon_channel=ir_beacon_channel) self.bazooka_blast_motor = MediumMotor( address=bazooka_blast_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.speaker = Sound()
def __init__(self, left_motor_port: str = OUTPUT_B, right_motor_port: str = OUTPUT_C, grip_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): super().__init__(left_motor_port=left_motor_port, right_motor_port=right_motor_port, motor_class=LargeMotor, ir_sensor_port=ir_sensor_port, ir_beacon_channel=ir_beacon_channel) self.grip_motor = MediumMotor(address=grip_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.speaker = Sound()
def __init__(self, left_foot_motor_port: str = OUTPUT_B, right_foot_motor_port: str = OUTPUT_C, bazooka_blast_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_beacon_channel: int = 1): super().__init__(left_motor_port=left_foot_motor_port, right_motor_port=right_foot_motor_port, polarity=Motor.POLARITY_NORMAL, speed=1000, channel=ir_beacon_channel) self.bazooka_blast_motor = MediumMotor( address=bazooka_blast_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.screen = Display() self.speaker = Sound()
def __init__(self, MotorPort, SensorPort): Logging.basicConfig(level = Logging.getLevelName(Config.LOGGING_LEVEL)) Logging.info('Init trunk motor') super().__init__(Motor = LargeMotor(address = MotorPort)) Logging.info('Init touch sensor') self.__Sensor = TouchSensor(address = SensorPort) self.__Sensor.mode = self.__Sensor.MODE_TOUCH Logging.info('Init sounds') self.__Speaker = Sound()
def __init__(self, left_motor_port: str = OUTPUT_B, right_motor_port: str = OUTPUT_C, grip_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): super().__init__(left_motor_port=left_motor_port, right_motor_port=right_motor_port, polarity=Motor.POLARITY_NORMAL, speed=1000, channel=ir_beacon_channel) self.grip_motor = MediumMotor(address=grip_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.speaker = Sound()
def __init__( self, lever_motor_port: str = OUTPUT_D, touch_sensor_port: str = INPUT_1, ir_sensor_port: str = INPUT_4): self.lever_motor = MediumMotor(address=lever_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.leds = Leds() self.speaker = Sound()
def test_touch(): ts = TouchSensor(INPUT_4) leds = Leds() print("Press the touch sensor to change the LED color!") while not button.any(): if ts.is_pressed: leds.set_color("LEFT", "GREEN") leds.set_color("RIGHT", "GREEN") else: leds.set_color("LEFT", "RED") leds.set_color("RIGHT", "RED")
def __init__(self, speed): self.button = TouchSensor() self.action = Actions(speed) # Get current time HH:MM:SS now = datetime.now() time = now.strftime("%H:%M:%S") print(str(time) + "\tExecuting Touch Sensor Thread\n") # Execute button thread buttonThread = Thread(target=self.isPressed, args=()) buttonThread.start()
def touchLeds(): ts = TouchSensor() leds = Leds() print("Press the touch sensor to change the LED color!") while True: if ts.is_pressed: leds.set_color("LEFT", "GREEN") leds.set_color("RIGHT", "GREEN") else: leds.set_color("LEFT", "RED") leds.set_color("RIGHT", "RED")
def main(): threadPool = [] actions = [] stopProcessing = False largeMotor_Left = LargeMotor(OUTPUT_B) largeMotor_Right = LargeMotor(OUTPUT_C) mediumMotor = MediumMotor() ts = TouchSensor() f = open("Program16_data.txt", "r") for aLineOfText in f: tokens = aLineOfText.split(",") # read the string values into local variables - make # the speed and seconds floating point numbers name = tokens[0] motor = tokens[1] speed = float(tokens[2]) seconds = float(tokens[3]) action = createAction(name, motor, speed, seconds) # launch the action thread = launchStep(lambda: stopProcessing, action) threadPool.append(thread) while not stopProcessing: # remove any completed threads from the pool for thread in threadPool: if not thread.isAlive(): threadPool.remove(thread) # if there are no threads running, exist the 'while' loop # and start the next action from the list if not threadPool: break # if the touch sensor is pressed then complete everything if ts.is_pressed: stopProcessing = True sleep(0.25) # if the 'stopProcessing' flag has been set then break out of the program altogether if stopProcessing: break
def __init__(self, left_foot_motor_port: str = OUTPUT_B, right_foot_motor_port: str = OUTPUT_C, bazooka_blast_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): self.tank_driver = MoveTank(left_motor_port=left_foot_motor_port, right_motor_port=right_foot_motor_port, motor_class=LargeMotor) self.bazooka_blast_motor = MediumMotor( address=bazooka_blast_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.screen = Display() self.speaker = Sound()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Gadget state self.patrol_mode = False # Ev3dev initialization self.leds = Leds() self.sound = Sound() self.tsVertical = TouchSensor(INPUT_4) self.tsHorizontal = TouchSensor(INPUT_1) self.mm = MediumMotor(OUTPUT_B) self.tank_pair = MoveTank(OUTPUT_A, OUTPUT_D) self.tank_pair.reset() self.lm = LargeMotor(OUTPUT_C) print("--------------------------------------------") print(" BATTLESHIP ") print("--------------------------------------------") self.sound.speak("BATTLESHIP")
def __init__(self): self.exit = True self.callback_exit = True # Connect sensors and buttons. self.btn = Button() self.ir = InfraredSensor() self.ts = TouchSensor() self.power = PowerSupply() self.tank_drive = MoveTank(OUTPUT_A, OUTPUT_B) print('EV3 Node init starting') rospy.init_node('ev3_robot', anonymous=True, log_level=rospy.DEBUG) print('EV3 Node init complete') rospy.Subscriber('ev3/active_mode', String, self.active_mode_callback, queue_size=1) self.power_init() print('READY!')
def main(): threadPool = [] actions = [] stopProcessing = False ts = TouchSensor() xmlDocument = ET.parse('Program21_data.xml') steps = xmlDocument.getroot() for step in steps: action = step.get('action') # are their multiple actions to execute in parallel? if action == 'launchInParallel': for subSteps in step: thread = launchStep(lambda: stopProcessing, subSteps) threadPool.append(thread) # is there a single action to execute? else: thread = launchStep(lambda: stopProcessing, step) threadPool.append(thread) while not stopProcessing: # remove any completed threads from the pool for thread in threadPool: if not thread.isAlive(): threadPool.remove(thread) # if there are no threads running, exist the 'while' loop # and start the next action from the list if not threadPool: break # if the touch sensor is pressed then complete everything if ts.is_pressed: stopProcessing = True break sleep(0.25) # if the 'stopProcessing' flag has been set then break out of the program altogether if stopProcessing: break
def play(self): delay = 0 step = [5, 10, 15, 20, 25, 30, 35, 40, 45, 55, 60, 65, 70] button = Button() button.on_up = self.volumeUp button.on_down = self.volumeDown button.on_left = self.multiplyUp button.on_right = self.multiplyDown button.on_enter = self.togglePause button.on_backspace = self.backButton ir = InfraredSensor() ts = TouchSensor() servo = MediumMotor() while True: self.volume = self.getVolume() button.process() if self.pause == True: continue distance = int(math.fabs(ir.value())) position = int(math.fabs(servo.position)) for x in step: if distance <= x: hertz = int(x * 15) # print("Hertz - " + str(hertz)) break for x in step: if position <= x: duration = int(x * 5 * self.multiply) # print("Duration - " + str(duration)) break if ts.is_pressed: if delay == 200: delay = 0 else: if delay == 0: delay = 200 # play sound self.sound.tone([(hertz, duration, delay)])
def __init__(self, left_motor_port=OUTPUT_B, right_motor_port=OUTPUT_C, medium_motor_port=OUTPUT_A): RemoteControlledTank.__init__(self, left_motor_port, right_motor_port) self.set_polarity(MediumMotor.POLARITY_NORMAL) self.medium_motor = MediumMotor(medium_motor_port) self.ts = TouchSensor() self.mts = MonitorTouchSensor(self) self.mrc = MonitorRemoteControl(self) self.shutdown_event = Event() # Register our signal_term_handler() to be called if the user sends # a 'kill' to this process or does a Ctrl-C from the command line signal.signal(signal.SIGTERM, self.signal_term_handler) signal.signal(signal.SIGINT, self.signal_int_handler) self.claw_open(True) self.remote.on_channel4_top_left = self.claw_close self.remote.on_channel4_bottom_left = self.claw_open
def __init__(self, claw_motor_port: str = OUTPUT_A, move_motor_port: str = OUTPUT_B, sting_motor_port: str = OUTPUT_D, touch_sensor_port: str = INPUT_1, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): self.claw_motor = MediumMotor(address=claw_motor_port) self.move_motor = LargeMotor(address=move_motor_port) self.sting_motor = LargeMotor(address=sting_motor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.touch_sensor = TouchSensor(address=touch_sensor_port) self.speaker = Sound()
def __init__( self, turn_motor_port: str = OUTPUT_A, move_motor_port: str = OUTPUT_B, scare_motor_port: str = OUTPUT_D, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): self.turn_motor = MediumMotor(address=turn_motor_port) self.move_motor = LargeMotor(address=move_motor_port) self.scare_motor = LargeMotor(address=scare_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.noise = Sound()
def sensors(): # Connect infrared and touch sensors to any sensor ports ir = InfraredSensor() ts = TouchSensor() leds = Leds() leds.all_off() # stop the LEDs flashing (as well as turn them off) # is_pressed and proximity are not functions and do not need parentheses while not ts.is_pressed: # Stop program by pressing the touch sensor button if ir.proximity < 40 * 1.4: # to detect objects closer than about 40cm leds.set_color('LEFT', 'RED') leds.set_color('RIGHT', 'RED') else: leds.set_color('LEFT', 'GREEN') leds.set_color('RIGHT', 'GREEN') sleep(0.01) # Give the CPU a rest
class RobotBehaviourThread(threading.Thread): move_steering = MoveSteering(OUTPUT_B, OUTPUT_C) color_sensor = ColorSensor() color_sensor.mode = ColorSensor.MODE_COL_REFLECT ultrasonic_sensor = UltrasonicSensor() gyroscope = GyroSensor() touch_sensor = TouchSensor() def __init__(self, callback=None): super().__init__() print("Initializing thread") self._stop_event = threading.Event() self.callback = callback def stop(self): self._stop_event.set() def stopped(self): return self._stop_event.is_set() def move(self, angle, speed): self.move_steering.on(angle, SpeedPercent(speed)) def turn_degrees(self, degrees, direction): initial_angle = self.gyroscope.angle direction_actual = -100 if direction <= 0 else 100 self.move(direction_actual, 25) print("rotating") print(initial_angle) while self.gyroscope.angle < initial_angle + degrees and self.gyroscope.angle > initial_angle - degrees: pass print("done rotating") self.stop_movement() def stop_movement(self): self.move_steering.off(brake=True) def get_color(self): self.color_sensor.mode = 'COL-COLOR' #print(self.color_sensor.value()) return self.color_sensor.value()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Robot state self.quiz_mode = False # Activate sensors and actuators self.fan = MediumMotor(OUTPUT_A) self.sound = Sound() self.leds = Leds() self.ts = TouchSensor() self.cl = ColorSensor() self.cl.mode = 'COL-COLOR' # Start threads threading.Thread(target=self._touch_thread, daemon=True).start()
def __init__( self, left_foot_motor_port: str = OUTPUT_B, right_foot_motor_port: str = OUTPUT_C, medium_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): super().__init__( left_motor_port=left_foot_motor_port, right_motor_port=right_foot_motor_port, ir_sensor_port=ir_sensor_port, ir_beacon_channel=ir_beacon_channel) self.medium_motor = MediumMotor(address=medium_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.speaker = Sound()
def setup(): global tank_drive, colorSensorLeft, colorSensorRight, ultra, sound, touchSensor, gyroSensor tank_drive = MoveTank(OUTPUT_A, OUTPUT_B) tank_drive.gyro = GyroSensor('in4') colorSensorLeft = ColorSensor('in1') colorSensorRight = ColorSensor('in2') colorSensorLeft.mode = 'COL-COLOR' colorSensorRight.mode = 'COL-COLOR' #ultra = UltrasonicSensor('in3') touchSensor = TouchSensor('in3') gyroSensor = GyroSensor('in4') gyroSensor.calibrate() sound = Sound()
def __init__(self, back_foot_motor_port: str = OUTPUT_B, front_foot_motor_port: str = OUTPUT_C, gear_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): self.tank_driver = MoveTank(left_motor_port=back_foot_motor_port, right_motor_port=front_foot_motor_port, motor_class=LargeMotor) self.gear_motor = MediumMotor(address=gear_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel
def __init__(self, left_leg_motor_port: str = OUTPUT_B, right_leg_motor_port: str = OUTPUT_C, shooting_motor_port: str = OUTPUT_A, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1, touch_sensor_port: str = INPUT_1): self.tank_driver = MoveTank(left_motor_port=left_leg_motor_port, right_motor_port=right_leg_motor_port, motor_class=LargeMotor) self.shooting_motor = MediumMotor(address=shooting_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.speaker = Sound()
def __init__(self): Config.update() self.sound = Sound() # sensor values self.sensLeft = ColorSensor(INPUT_1) self.sensRight = ColorSensor(INPUT_4) # TODO: Sensoren anschließen self.sensIR = InfraredSensor(INPUT_2) self.sensTouch = TouchSensor(INPUT_3) self.btn = Button() self.sensValues = {} # Classes for features self.drive = Drive() self.cross = Cross() # statemachine self.fsm = StateMachine() # adding States self.fsm.states["followLine"] = State("followLine") self.fsm.states["followLine"].addFunc(self.drive.followLine, self.sensValues) self.fsm.states["brake"] = State("brake") self.fsm.states["crossFirstTurn"] = State("crossFirstTurn") self.fsm.states["crossFirstTurn"].addFunc(self.cross.firstTurn, self.sensValues) self.fsm.states["checkNextExit"] = State("checkNextExit") self.fsm.states["checkNextExit"].addFunc(self.drive.followLine, self.sensValues) # adding Transitions self.fsm.transitions["toFollowLine"] = Transition("followLine") self.fsm.transitions["toBrake"] = Transition("brake") self.fsm.transitions["toBrake"].addFunc(self.drive.brake) self.fsm.transitions["toCrossFirstTurn"] = Transition("crossFirstTurn")
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # the default I2C address of the sensor self.I2C_ADDRESS = 0x21 # setup the buses self.airqualitybus = SMBus(3) self.temperaturebus = SMBus(4) #setup the moisbus and relaybus self.airqualitybus.write_byte_data(self.I2C_ADDRESS, 0x42, 0x01) self.temperaturebus.write_byte_data(self.I2C_ADDRESS, 0x42, 0x01) #setup the lastmois so we can track it well self.lastairquality = 0 self.lasttemperature = 0 self.count = 0 self.speed = 0 # Robot state self.auto_mode = False self.filterwarning = False self.sound = Sound() self.leds = Leds() self.color = ColorSensor() self.touch = TouchSensor() #Motor self.fan = MediumMotor(OUTPUT_A) #screen self.screen = ev3.Screen() # Start threads threading.Thread(target=self._autofan_thread, daemon=True).start() threading.Thread(target=self._manual_button_thread, daemon=True).start()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Gadget state self.heel_mode = False self.patrol_mode = False self.sitting = False # Ev3dev initialization self.leds = Leds() self.sound = Sound() # Connect infrared and touch sensors. self.ir = InfraredSensor() self.ts = TouchSensor() # Init display self.screen = Display() self.dance = False self.sound = Sound() self.drive = MoveTank(OUTPUT_B, OUTPUT_C) self.sound.speak('Hello, my name is Beipas!') # Connect medium motor on output port A: self.medium_motor = MediumMotor(OUTPUT_A) # Connect two large motors on output ports B and C: self.left_motor = LargeMotor(OUTPUT_B) self.right_motor = LargeMotor(OUTPUT_C) # Gadget states self.bpm = 0 self.trigger_bpm = "off" self.eyes = True # Start threads threading.Thread(target=self._dance_thread, daemon=True).start() threading.Thread(target=self._patrol_thread, daemon=True).start() threading.Thread(target=self._heel_thread, daemon=True).start() threading.Thread(target=self._touchsensor_thread, daemon=True).start() threading.Thread(target=self._eyes_thread, daemon=True).start()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Connect two large motors on output ports B and C self.drive = MoveTank(OUTPUT_B, OUTPUT_C) self.grip = MediumMotor(OUTPUT_A) self.sound = Sound() self.leds = Leds() self.ir = InfraredSensor() self.touch = TouchSensor() self.gyro = GyroSensor() self.isComing = False self.isTaking = False self.isBringing = False self.isTurning = False # Start threads threading.Thread(target=self._proximity_thread, daemon=True).start()
def __init__(self, sting_motor_port: str = OUTPUT_D, go_motor_port: str = OUTPUT_B, claw_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): self.sting_motor = LargeMotor(address=sting_motor_port) self.go_motor = LargeMotor(address=go_motor_port) self.claw_motor = MediumMotor(address=claw_motor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.dis = Display() self.speaker = Sound()