示例#1
0
    def setup_hardware(self):
        # setup I/O connecting to EV3
        self.motorR = ev3.LargeMotor('outA')
        self.motorL = ev3.LargeMotor('outD')
        self.csR = ev3.ColorSensor('in2')
        self.csM = ev3.ColorSensor('in3')
        self.csL = ev3.ColorSensor('in4')

        # mode set up (right and left senor only used for light intensity)
        self.csR.reflected_light_intensity
        self.csL.reflected_light_intensity

        self.port = ev3.LegoPort('outB')
        assert self.port.connected
        self.port.mode = 'dc-motor'
        time.sleep(5)
        self.grabberArms = ev3.DcMotor("outB")
        print("DcMotor connected")

        self.grabberLift = ev3.MediumMotor('outC')
        self.grabberLift.stop_action = 'brake'
        self.grabber_initialise()
        self.gy = ev3.GyroSensor('in1')
        self.reset_gyro()
        self.up_pos = self.grabberLift.position
示例#2
0
    def setup_hardware(self):
        # setup I/O connecting to EV3
        self.motorR = ev3.LargeMotor('outA')
        self.motorL = ev3.LargeMotor('outD')
        self.csR = ev3.ColorSensor('in2')
        self.csM = ev3.ColorSensor('in3')
        self.csL = ev3.ColorSensor('in4')

        #TODO: implement using the DC motor if need
        #self.grabberArms = ev3.MediumMotor('outC')
        self.port = ev3.LegoPort('outB')
        assert self.port.connected
        self.port.mode = 'dc-motor'
        time.sleep(5)
        self.grabberArms = ev3.DcMotor("outB")
        print("DcMotor connected")

        self.grabberLift = ev3.MediumMotor('outC')
        self.gy = ev3.GyroSensor('in1')
        self.reset_gyro()
        self.base_pos = self.grabberLift.position
示例#3
0
print("Cup dispenser server starting...")

import socketserver
import ev3dev.ev3 as ev3
import time

# DC motor
p = ev3.LegoPort('outB')
assert p.connected
p.mode = 'dc-motor'
time.sleep(1)

# motors and sensors
lift_motor = ev3.LargeMotor('outD')
grab_motor = ev3.DcMotor('outB')
lift_sensor = ev3.TouchSensor('in1')
grab_sensor = ev3.TouchSensor('in2')

lift_motor.stop_action = 'brake'


class cup_dispenser:
    '''def __init__(self):
        self.initialise()'''

    # go to the initialisation spot
    def initialise(self):
        self.lift_down()
        self.grab_reset()
        self.grab_open()
        self.lift_up()
示例#4
0
 def __init__(self):
     # setup the sensors
     self.touch = ev3.TouchSensor()
     self.smallMotor = ev3.DcMotor()
示例#5
0
#vars:
liftspeed = 300
lifttimemax = 2000  #ms
grabtime = 500  #ms

import ev3dev.ev3 as ev3
import time

p = ev3.LegoPort('outB')
assert p.connected
p.mode = 'dc-motor'

time.sleep(1)

lift = ev3.LargeMotor("outD")
grab = ev3.DcMotor("outB")
touch = ev3.TouchSensor("in1")

lift.stop_action = "brake"  #Stop the lift as fast as possible

print("started")

while True:
    cmd = input()
    if (cmd == "up"):
        #lift until overloaded
        lift.run_timed(speed_sp=-liftspeed, time_sp=lifttimemax)
        time.sleep(0.1)  #Motor is overloaded while ramping
        lift.wait_until("overloaded", timeout=lifttimemax)
        lift.stop()