def __init__(self):
     self.grabber = Motor(OUTPUT_C)
     self.arm = Motor(OUTPUT_B)
     self.left_colour_sensor = ColorSensor(address='3')
     self.right_colour_sensor = ColorSensor(address='4')
     self.inner_colour_sensor = ColorSensor(address='1')
     self.outer_colour_sensor = ColorSensor(address='2')
     self.left_wheel = Motor(OUTPUT_A)
     self.right_wheel = Motor(OUTPUT_D)
Exemplo n.º 2
0
    def __init__(self):
        self.grabber = Motor(OUTPUT_C)
        self.arm = Motor(OUTPUT_B)
        self.left_colour_sensor = ColorSensor(address='3')
        self.right_colour_sensor = ColorSensor(address='4')
        self.inner_colour_sensor = ColorSensor(address='1')
        self.outer_colour_sensor = ColorSensor(address='2')
        self.left_wheel = Motor(OUTPUT_A)
        self.right_wheel = Motor(OUTPUT_D)
        self.stop_action = "coast"

        self.current_node = A1
def main():
    print("Start")
    color = ColorSensor()
    color.mode = color.MODE_REF_RAW  #raw値
    color_reflection_fd = open(color._path + "/value0", "rb")

    # touchSensorの読み込み
    touch = TouchSensor()
    touch_sensor_devfd = open(touch._path + "/value0", "rb")
    touch_sensor_pressed = False
    interval = 0.2

    while not touch_sensor_pressed:
        touch_sensor_pressed = read_device(touch_sensor_devfd)

        color_val = read_device(color_reflection_fd)
        print("color:{}", color_val)
        sleep(interval)
Exemplo n.º 4
0
    def __init__(self, setting):
        # target_v 目標値
        # delta_t 周回時間
        self.refrection_target = 0.0
        self.delta_t = 0.025  # 10msec
        # TODO: P係数(要調整)
        # 8.5V - 0.31
        # 8.2V - 0.30
        # 7.5V - 0.26
        self.k_p = 0.26  #0.26
        # TODO: I係数(要調整)
        self.k_i = 0.1
        # TODO: D係数(要調整)
        self.k_d = 0.05
        # 前回偏差
        self.e_b = 0.0
        # 前回までの偏差値
        self.p_b = 0.0
        # 前回までの積分値
        self.i_b = 0.0
        # 前回までの微分値
        self.d_b = 0.0
        # 前回値
        #self.previous_refrection_raw = [0 for _ in range(5) ]
        self.previous_refrection_raw = 0

        self.color = ColorSensor()
        self.color.mode = self.color.MODE_REF_RAW  #raw値
        self.color_reflection_fd = open(self.color._path + "/value0", "rb")

        white_target = setting['lineWhiteLuminance']
        black_target = setting['lineBlackLuminance']
        target_white_rate = setting['lineLuminanceRate']

        self.refrection_target = (white_target * target_white_rate) + (
            black_target * (1.0 - target_white_rate))
        self.previous_refrection_raw = self.refrection_target
Exemplo n.º 5
0
    return test_bit(globals()['KEY_ENTER'], buf)


motor_a = LargeMotor('outA')
motor_b = LargeMotor('outB')
motor_c = LargeMotor('outC')
motor_d = LargeMotor('outD')
motor_c.polarity = 'inversed'
motor_d.polarity = 'inversed'

motor_a.stop_action = 'brake'
motor_b.stop_action = 'brake'
motor_c.stop_action = 'brake'
motor_d.stop_action = 'brake'

color_sensor = ColorSensor()
color_sensor.mode = 'COL-REFLECT'

sonar_sensor = UltrasonicSensor()
sonar_sensor.mode = 'US-DIST-CM'

lights = Led()
Led.delay_on = 500
Led.delay_off = 1500
lights.trigger = 'none'

time_since_escline = 0

is_esc_line = False
is_searching = False
Exemplo n.º 6
0
from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_D, LargeMotor, MediumMotor, InfraredSensor
from ev3dev.auto import INPUT_1, INPUT_2, ColorSensor, UltrasonicSensor
import time
import ev3dev.auto as auto
import ev3dev.ev3 as ev3

uss = UltrasonicSensor(INPUT_1)
colorSensor = ColorSensor(INPUT_2)
clawMotor = MediumMotor(OUTPUT_B)
leftTire = LargeMotor(OUTPUT_A)  # and LargeMotor(OUTPUT_D)
rightTire = LargeMotor(OUTPUT_D)

clawMotor.run_timed(speed_sp=720, time_sp=500)
time.sleep(1)
Exemplo n.º 7
0
#!/usr/bin/python
from ev3dev.auto import ColorSensor, Screen, Sound, INPUT_1
from time import sleep, time

color = ColorSensor(INPUT_1)
color.mode = color.MODE_COL_REFLECT

lcd = Screen()
Sound().beep()

fout = open("data.txt", "w")
start_time = time()
for i in range(0, 100):
    t = time() - start_time
    light = color.value()
    lcd.clear()
    lcd.draw.text((0, 10), "light is " + str(light))
    lcd.update()
    s = "%f\t%d\n" % (t, light)
    fout.write(s)
    sleep(0.05)
fout.close()
Exemplo n.º 8
0
    return test_bit(globals()['KEY_ENTER'], buf)


motor_a = LargeMotor('outA')
motor_b = LargeMotor('outB')
motor_c = LargeMotor('outC')
motor_d = LargeMotor('outD')
motor_c.polarity = 'inversed'
motor_d.polarity = 'inversed'

motor_a.stop_action = 'brake'
motor_b.stop_action = 'brake'
motor_c.stop_action = 'brake'
motor_d.stop_action = 'brake'

color_sensor = ColorSensor()
color_sensor.mode = 'COL-REFLECT'

sonar_sensor = UltrasonicSensor()
sonar_sensor.mode = 'US-DIST-CM'

lights = Led()
Led.delay_on = 500
Led.delay_off = 1500
lights.trigger = 'none'

time_since_escline = 0

is_esc_line = False
is_searching = False