Esempio n. 1
0
class EV3Motors:
    def __init__(self, left=0, right=1):
        self.left = LargeMotor('outA')
        self.right = LargeMotor('outB')
        self.pos = 0.0
        self.speed = 0.0
        self.diff = 0
        self.target_diff = 0
        self.drive = 0
        self.steer = 0
        self.prev_sum = 0
        self.prev_deltas = [0, 0, 0]

    def get_data(self, interval):
        left_pos = self.left.position
        right_pos = self.right.position

        pos_sum = right_pos + left_pos
        self.diff = left_pos - right_pos

        delta = pos_sum - self.prev_sum
        self.pos += delta

        self.speed = (delta + sum(self.prev_deltas)) / (4 * interval)

        self.prev_sum = pos_sum
        self.prev_deltas = [delta] + self.prev_deltas[0:2]

        return self.speed, self.pos

    def go(self):
        self.left.run_direct()
        self.right.run_direct()

    def stop(self):
        self.left.stop()
        self.right.stop()

    def set_power(self, power):
        self.left.duty_cycle_sp = -power
        self.right.duty_cycle_sp = power
Esempio n. 2
0
# import nxt
#
# # brick = nxt.locator.find_one_brick(name = 'Hooper')
# b = nxt.locator.find_one_brick(
#     name="NXT", strict=True,
#     method=nxt.locator.Method(
#         bluetooth=False, fantomusb=True, fantombt=False, usb=False))

from ev3dev.auto import OUTPUT_D, LargeMotor
import time

m = LargeMotor(OUTPUT_D)
print(m)
m.run_forever(speed_sp=360)
time.sleep(1)
m.stop()
print('Hooray')
Esempio n. 3
0
# import nxt
#
# # brick = nxt.locator.find_one_brick(name = 'Hooper')
# b = nxt.locator.find_one_brick(
#     name="NXT", strict=True,
#     method=nxt.locator.Method(
#         bluetooth=False, fantomusb=True, fantombt=False, usb=False))

from ev3dev.auto import OUTPUT_D, LargeMotor
import time

m = LargeMotor(OUTPUT_D)
print(m)
m.run_forever(speed_sp = 360)
time.sleep(1)
m.stop()
print('Hooray')
Esempio n. 4
0
colorSensor = ColorSensor(INPUT_3)
clawMotor = MediumMotor(OUTPUT_A)
armMotor = LargeMotor(OUTPUT_B)
baseMotor = LargeMotor(OUTPUT_C)

# Claw Opening
ev3.Sound.speak("Now opening claw.").wait()
clawMotor.run_forever(speed_sp=100)
time.sleep(.5)
clawMotor.stop()

# Arm Moving to down position
ev3.Sound.speak("Now moving arm down.").wait()
armMotor.run_forever(speed_sp=120)
time.sleep(2.5)
armMotor.stop()

# Claw closing on object to pick up
ev3.Sound.speak("Now closing claw.").wait()
clawMotor.run_forever(speed_sp=-100)
time.sleep(2)

# Arm moving to the up position
ev3.Sound.speak("Now moving arm up.").wait()
armMotor.run_forever(speed_sp=-360)
time.sleep(.85)
armMotor.stop()

# Base moving to center position
ev3.Sound.speak("Now moving base.").wait()
baseMotor.run_forever(speed_sp=-130)