Пример #1
0
from ev3dev.ev3 import LargeMotor, \
    OUTPUT_A, Sound, Screen
from time import time, sleep

N = 3000
file_name = "data_gyro.txt"

pwr = 100

motor = LargeMotor(OUTPUT_A)
lcd = Screen()
Sound().beep()
fout = open(file_name, "w")
sleep(0.05)
rotation = motor.position
motor.run_direct(duty_cycle_sp=pwr)
start_time = time()
for i in range(0, N):
    lcd.clear()
    t = time() - start_time
    if rotation < 354: pwr = 100
    if rotation >= 354 and rotation <= 366: pwr = 0
    if rotation > 366: pwr = -100
    motor.duty_cycle_sp = pwr
    rotation = motor.position
    line = "%f\t%d\n" % (t, rotation)
    fout.write(line)
    lcd.draw.text((0, 10), str(rotation))
    lcd.update()
fout.close()
Пример #2
0
run_time = 3

motor_b = LargeMotor(address='outB')
motor_c = LargeMotor(address='outC')

motor_b.reset()
motor_c.reset()

motor_b.command = 'run-direct'
motor_c.command = 'run-direct'

trigger = TouchSensor()

print("Fire when ready!")

while True:
    if trigger.value() == True:
        break
    else:
        sleep(.01)

motor_b.duty_cycle_sp = power
motor_c.duty_cycle_sp = power

sleep(run_time)

motor_b.duty_cycle_sp = 0
motor_c.duty_cycle_sp = 0

sleep(1)
Пример #3
0
#!/usr/bin/python

from ev3dev.ev3 import MediumMotor as MediumMotor
from ev3dev.ev3 import LargeMotor as LargeMotor
from time import sleep

a = MediumMotor(address='outA')
b = LargeMotor(address='outB')
c = LargeMotor(address='outC')

a.reset()
b.reset()
c.reset()

a.position_sp = 50
a.duty_cycle_sp = 50
a.command = 'run-to-abs-pos'

b.position_sp = -450
b.duty_cycle_sp = 50
b.command = 'run-to-abs-pos'

c.position_sp = -450
b.duty_cycle_sp = 50
b.command = 'run-to-abs-pos'

sleep(5)
Пример #4
0
motor_c = LargeMotor(address='outC')

motor_b.reset()
motor_c.reset()

motor_b.command = 'run-direct'
motor_c.command = 'run-direct'



trigger = TouchSensor()

print("Fire when ready!")

while True:
    if trigger.value() == True:
        break
    else:
        sleep(.01)


motor_b.duty_cycle_sp = power
motor_c.duty_cycle_sp = power

sleep(run_time)

motor_b.duty_cycle_sp = 0
motor_c.duty_cycle_sp = 0

sleep(1)