示例#1
0
#!/usr/bin/env python2

import ev3
import wiiMote
from time import sleep
import thread
import socket
import cwiid

lift = ev3.motor("A")
rightMotor = ev3.motor("B")
leftMotor = ev3.motor("C")
claw = ev3.motor("D")

liftHomePos = lift.getPos()

mote = wiiMote.wiiMote()
mote.setMode(cwiid.RPT_BTN | cwiid.RPT_CLASSIC)
sleep(2)

wasPushed = False
isReversed = False

liftAuto = False


def hatThread():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('', 8000))
    s.listen(1)
    while True:
示例#2
0
#!/usr/bin/env python2

import ev3
import cwiid
from time import sleep
import socket

lift = ev3.motor("A")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
oldCommand = ''

liftHomePos = lift.getPos()
liftAuto = False

try:
    s.connect(('192.168.43.236', 8000))
except:
    print("Incorect Base IP")

try:
    while True:
        command = int(s.recv(1024))
        print(command)
        # Lift
        if (bool(command & cwiid.BTN_A)):
            liftAuto = False
            lift.move(-50)
        elif (bool(command & cwiid.BTN_B)):
            liftAuto = True
            lift.moveAbs(liftHomePos, 100)
示例#3
0
#!/usr/bin/env python2

import ev3
import cwiid
from time import sleep
import socket

ArmMotor = ev3.motor("A")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
oldCommand = ''

try:
    s.connect(('192.168.43.153', 8000))
except:
    print("Incorect Base IP")

try:
    while True:
        command = int(s.recv(1024))
        print(command)
        if (bool(command & cwiid.BTN_A)):
            ArmMotor.move(-50)
        elif (bool(command & cwiid.BTN_B)):
            ArmMotor.move(20)
        elif (command == 0):
            ArmMotor.move(0)
            ArmMotor.braking(True)
finally:
    ArmMotor.reset()
示例#4
0
#!/usr/bin/env python2

import ev3
from time import sleep
import thread

sorterMotor = ev3.motor("A")
shortConveyorMotor = ev3.motor("B")
conveyorMotor = ev3.motor("C")

colorSensor = ev3.sensor(2)
colorSensor.colorColor()
ev3Button = ev3.buttons()

upPushed = False
downPushed = False
conveyor = 0
shortConveyor = 0

def sort():
    sortColor = 6
    print(colorSensor.getValue())
    if (colorSensor.getValue() == sortColor):
            sleep(0.1)
            sorterMotor.moveRel(500, 1500)
            sleep(0.5)
            sorterMotor.moveRel(-500, 1500)
            sleep(0.2)

        # print(ultrasonicSensor.getValue())
        # if (colorSensor.getValue() == sortColor):
示例#5
0
#!/usr/bin/env python2

import ev3
import wiiMote
from time import sleep
import thread
import socket
import cwiid

turnTable = ev3.motor("A")
claw = ev3.motor("B")
lift = ev3.motor("C")

mote = wiiMote.wiiMote()
mote.setMode(cwiid.RPT_BTN | cwiid.RPT_CLASSIC)
sleep(2)

wasPushed = False
isReversed = False

clawHomePos = claw.getPos()
clawAuto = False


def hatThread():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('', 8000))
    s.listen(1)
    while True:
        client, addr = s.accept()
        lastCommand = ''
        shoulder.moveAbs(int(8.33 * (90 - q1)) - 16, 100)
    else:
        elbow.move(-50)
        shoulder.move(-50)
        if elbowLimit.getValue() == 1 and shoulderLimit.getValue() == 1:
            elbow.reset()
            shoulder.reset()
            elbow.braking(True)
            shoulder.braking(True)
            armZeroed = True


# --- Main Code ---
if __name__ == '__main__':
    print('Initializing motors')
    claw = ev3.motor('A')
    claw.reset()
    claw.braking(True)
    elbow = ev3.motor('B')
    shoulder = ev3.motor('C')
    turret = ev3.motor('D')
    elbowLimit = ev3.sensor('1')
    elbowLimit.touch()
    shoulderLimit = ev3.sensor('2')
    shoulderLimit.touch()
    print('Discovering joystick')

    # 'Wireless Controller' for PS4

    find_joystick('Wireless Controller')
    joystick_thread = threading.Thread(target=watch_joystick)
示例#7
0
#!/usr/bin/env python2

import ev3
import wiiMote
from time import sleep
import thread
import socket
import cwiid

outLeftMotor = ev3.motor("A")
inLeftMotor = ev3.motor("B")
inRightMotor = ev3.motor("C")
outRightMotor = ev3.motor("D")

mote = wiiMote.wiiMote()
mote.setMode(cwiid.RPT_BTN | cwiid.RPT_CLASSIC)
sleep(2)

wasPushed = False
isReversed = False


def hatThread():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('', 8000))
    s.listen(1)
    while True:
        client, addr = s.accept()
        lastCommand = ''
        try:
            while True:
#!/usr/bin/env python2

import ev3
import wiiMote

bMotor = ev3.motor('B')
cMotor = ev3.motor('C')

controller = wiiMote.wiiMote()
controller.setClassic()
controller.setLed(1)

try:
    while True:
        if (controller.getClassicButton("A")):
            bMotor.run(50)
            cMotor.run(-50)
        else:
            speed = controller.getClassicJoistics()["leftY"] * 100
            bMotor.run(speed + controller.getClassicJoistics()["rightX"] * 50)
            cMotor.run(speed - controller.getClassicJoistics()["rightX"] * 50)
finally:
    bMotor.sendCommand("stop")
    cMotor.sendCommand("stop")
示例#9
0
#!/usr/bin/env python2

import ev3
import wiiMote
from time import sleep
import thread
import socket
import cwiid

inLeftMotor = ev3.motor("B")
inRightMotor = ev3.motor("C")

mote = wiiMote.wiiMote()
mote.setMode(cwiid.RPT_BTN | cwiid.RPT_CLASSIC)
sleep(2)

wasPushed = False
isReversed = False


def hatThread():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('', 8000))
    s.listen(1)
    while True:
        client, addr = s.accept()
        lastCommand = ''
        try:
            while True:
                sleep(0.1)
                if (lastCommand != mote.getMoteButton('')):
示例#10
0
def watch_joystick():
    for event in JOYSTICK.read_loop():
        print(event.code)
        if event.type != ecodes.EV_ABS: continue
        caps = JOYSTICK_CAPS[event.code]
        JOYSTICK_STATE[event.code] = map_range(caps.min, caps.max, -1.0, 1.0, event.value)


# --- Main Code ---

if __name__ == '__main__':

    print('Initializing motors')

    arm = ev3.motor('C')
    turn = ev3.motor('B')
    grabber = ev3.motor('D')
    print('Discovering joystick')

    # 'Wireless Controller' for DS4
    find_joystick('Wireless Controller')
    joystick_thread = threading.Thread(target=watch_joystick)
    joystick_thread.daemon = True
    joystick_thread.start()

    print('Starting drive loop')
    armspeed = 0
    armMode='move'
    armpos =0
    p=1
示例#11
0
        JOYSTICK_STATE[abs_id] = JOYSTICK_DEFAULT_STATE

def watch_joystick():
    for event in JOYSTICK.read_loop():
        if event.type != ecodes.EV_ABS: continue
        caps = JOYSTICK_CAPS[event.code]
        JOYSTICK_STATE[event.code] = map_range(caps.min, caps.max, -1.0, 1.0, event.value)


# --- Main Code ---

if __name__ == '__main__':

    print('Initializing motors')

    left = ev3.motor('B')
    right = ev3.motor('C')

    print('Discovering joystick')

    # 'Wireless Controller' for DS4
    find_joystick('Wireless Controller')
    joystick_thread = threading.Thread(target=watch_joystick)
    joystick_thread.daemon = True
    joystick_thread.start()

    print('Starting drive loop')

    try:
        while True:
            ls_y = -JOYSTICK_STATE[ecodes.ABS_Y]