import pyev3

led_green_left = pyev3.LED('ev3:green:left')
led_green_right = pyev3.LED('ev3:green:right')
led_red_left = pyev3.LED('ev3:red:left')
led_red_right = pyev3.LED('ev3:red:right')

max_brightness = led_green_left.max_brightness

led_green_left.brightness = max_brightness
led_green_right.brightness = max_brightness

tacho = pyev3.Motor()
print "Using motor {}".format(tacho.port_name)

tacho.reset()

tacho.position = 90
adjusted = tacho.position
last_position = adjusted

while True:
    while adjusted == last_position:
        position = tacho.position
        adjusted = max(0, min(position, 180))
        if adjusted != position:
            tacho.position = adjusted
    brightness = max_brightness * adjusted / 180
    print adjusted, brightness
    led_red_left.brightness = brightness
    led_red_right.brightness = brightness
Esempio n. 2
0
import time

import cwiid
import pyev3

def clamp(value, lower, upper):
	return min(upper, max(value, lower))

print 'press 1+2 on the wiimote now'
time.sleep(1)
w = cwiid.Wiimote()
print 'connected?'
w.led = 6
w.rpt_mode = cwiid.RPT_ACC | cwiid.RPT_BTN

left_motor = pyev3.Motor(pyev3.OUTPUT_B)
left_motor.reset()
left_motor.run_mode = 'forever'
left_motor.regulation_mode = 'on'

right_motor = pyev3.Motor(pyev3.OUTPUT_C)
right_motor.reset()
right_motor.run_mode = 'forever'
right_motor.regulation_mode = 'on'

arm = pyev3.Motor(pyev3.OUTPUT_D)
arm.reset()
arm.run_mode = 'forever'
arm.regulation_mode = 'off'

target_distance = 8
Esempio n. 3
0
        self.left_motor.__setattr__(attr, value)
        self.right_motor.__setattr__(attr, value)

    def reset(self):
        self.left_motor.reset()
        self.right_motor.reset()


motors = Motors(pyev3.OUTPUT_B, pyev3.OUTPUT_C)

motors.reset()
motors.regulation_mode = "on"
motors.pulses_per_second_sp = 0
motors.run = 1

arm = pyev3.Motor(pyev3.OUTPUT_A)
arm.reset()
arm.run_mode = "position"
arm.position_sp = 0
arm.duty_cycle_sp = 100
arm.stop_mode = 'hold'

HOST = ''  # Symbolic name meaning all available interfaces
PORT = 50008  # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)

try:
    while True:
        conn, addr = s.accept()
Esempio n. 4
0
 def __init__(self, left_motor_port, right_motor_port):
     object.__setattr__(self, 'left_motor', pyev3.Motor(left_motor_port))
     object.__setattr__(self, 'right_motor', pyev3.Motor(right_motor_port))
import pyev3

my_motor = pyev3.Motor(pyev3.OUTPUT_B)
my_motor.position = 0
my_motor.run_mode = 'position'
my_motor.stop_mode = 'hold'
my_motor.regulation_mode = 'on'
my_motor.pulses_per_second_sp = 360
my_motor.position_sp = 360
my_motor.run = 1

while True:
    print my_motor.position