Пример #1
0
def main():
	""" メイン関数 """
	# 接続ピン
	PIN_AIN1 = 6
	PIN_AIN2 = 5
	PIN_BIN1 = 26
	PIN_BIN2 = 27
	# 左右モーター設定(PWM)
	motors = Robot(left=(PIN_AIN1,PIN_AIN2),right=(PIN_BIN1,PIN_BIN2),pwm=True)
	
	# 0.1秒毎周期30(約3秒)のSIN値の信号源
	srcleft = post_delayed(sin_values(period=30),0.1)
	# 0.1秒毎周期30(約3秒)のCOS値の信号源
	srcright = post_delayed(cos_values(period=30),0.1)
	
	# 左右モータに信号源を接続
	motors.source = zip(srcleft,srcright)
	
	# 停止(Ctr+c)まで待機
	pause()
Пример #2
0
def main():
    """ メイン関数 """
    # 接続ピン
    PIN_AIN1 = 6
    PIN_AIN2 = 5
    PIN_BIN1 = 26
    PIN_BIN2 = 27
    # 左右モーター設定(PWM)
    motors = Robot(left=(PIN_AIN1, PIN_AIN2),
                   right=(PIN_BIN1, PIN_BIN2),
                   pwm=True)

    # 1秒毎の正負パルス値の信号源
    dirleft = post_delayed(scaled(alternating_values(True), -1, 1), 1)
    dirright = post_delayed(scaled(alternating_values(False), -1, 1), 1)

    # 左右モーターに信号源を接続
    motors.source = zip(dirleft, dirright)

    # 停止(Ctrl+c)まで待機
    pause()
Пример #3
0
def main():
    """ メイン関数 """
    # モータードライバ接続ピン
    PIN_AIN1 = 6
    PIN_AIN2 = 5
    PIN_BIN1 = 26
    PIN_BIN2 = 27

    # A/D変換チャネル数
    NUM_CH = 4

    # 左右モーター設定(PWM)
    motors = Robot(left=(PIN_AIN1,PIN_AIN2), \
                   right=(PIN_BIN1,PIN_BIN2), \
                   pwm=True)
    # フォトリフレクタ(複数)設定(A/D変換)
    photorefs = [MCP3004(channel=idx) for idx in range(NUM_CH)]

    # ライントレース処理
    motors.source = line_follow(photorefs)

    # 停止(Ctr+c)まで待機
    pause()
Пример #4
0
from gpiozero import Robot, MCP3008
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left = MCP3008(0)
right = MCP3008(1)

robot.source = zip(left.values, right.values)

pause()
Пример #5
0
l_sensor = LineSensor(LS)
r_sensor = LineSensor(RS)

speed = 0.68


def motor_speed():
    while True:
        l_detect = int(l_sensor.value)
        r_detect = int(r_sensor.value)
        ## Stage 1
        if l_detect == 0 and r_detect == 0:
            l_motor = 1
            r_motor = 1
        ## Stage 2
        if l_detect == 0 and r_detect == 1:
            l_motor = -1
        if l_detect == 1 and r_detect == 0:
            r_motor = -1
        #print(r, l)
        yield (r_motor * speed, l_motor * speed)


robot.source = motor_speed()

sleep(60)
robot.stop()
robot.source = None
robot.close()
l_sensor.close()
r_sensor.close()
Пример #6
0
from gpiozero import Robot, MotionSensor
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))
pir = MotionSensor(5)

robot.source = zip(pir.values, pir.values)

pause()
Пример #7
0
from gpiozero import Robot
from bluedot import BlueDot
from signal import pause


def pos_to_values(x, y):
    left = y if x > 0 else y + x
    right = y if x < 0 else y - x
    return (clamped(left), clamped(right))


def clamped(v):
    return max(-1, min(1, v))


def drive():
    while True:
        if bd.is_pressed:
            x, y = bd.position.x, bd.position.y
            yield pos_to_values(x, y)
        else:
            yield (0, 0)


robot = Robot(left=(4, 14), right=(17, 18))
bd = BlueDot()
robot.source = drive()
pause()
Пример #8
0
from guizero import *
from gpiozero import Robot

robot = Robot((2, 3), (4, 5))

app = App("Robot controller", layout="grid")

Text(app, "Left", grid=[0, 0])
left = Slider(app, start=100, end=-100, grid=[1, 0], horizontal=False)
right = Slider(app, start=100, end=-100, grid=[2, 0], horizontal=False)
Text(app, "Right", grid=[3, 0])


def scaled(slider):
    while True:
        yield slider.value / 100


robot.source = zip(scaled(left), scaled(right))

app.display()
Пример #9
0
from gpiozero import Robot, Motor, MotionSensor
from gpiozero.tools import zip_values
from signal import pause

robot = Robot(left=Motor(4, 14), right=Motor(17, 18))
pir = MotionSensor(5)

robot.source = zip_values(pir, pir)

pause()
Пример #10
0
from gpiozero import Robot, MCP3008
from gpiozero.tools import scaled
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left_pot = MCP3008(0)
right_pot = MCP3008(1)

robot.source = zip(scaled(left_pot, -1, 1), scaled(right_pot, -1, 1))

pause()
Пример #11
0
from gpiozero import Robot, Motor, MCP3008
from gpiozero.tools import zip_values
from signal import pause

robot = Robot(left=Motor(4, 14), right=Motor(17, 18))

left_pot = MCP3008(0)
right_pot = MCP3008(1)

robot.source = zip_values(left_pot, right_pot)

pause()
Пример #12
0
from gpiozero import Robot
from bluedot import BlueDot
from signal import pause

def pos_to_values(x, y):
    left = y if x > 0 else y + x
    right = y if x < 0 else y - x
    return (clamped(left), clamped(right))

def clamped(v):
    return max(-1, min(1, v))

def drive():
    while True:
        if bd.is_pressed:
            x, y = bd.position.x, bd.position.y
            yield pos_to_values(x, y)
        else:
            yield (0, 0)

robot = Robot(left=(4, 14), right=(17, 18))
bd = BlueDot()

robot.source = drive()

pause()
Пример #13
0
from gpiozero import Robot, MCP3008
from gpiozero.tools import scaled
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left = MCP3008(0)
right = MCP3008(1)

robot.source = zip(scaled(left.values, -1, 1), scaled(right.values, -1, 1))

pause()