Пример #1
0
 def __init__(self):
     self.b = nxt.locator.find_one_brick()
     self.motor_c = Motor(self.b, PORT_C)
     self.motor_a = Motor(self.b, PORT_A)
     self.two_motors = nxt.SynchronizedMotors(self.motor_c, self.motor_a, 0)
     self.two_motors_c = nxt.SynchronizedMotors(self.motor_c, self.motor_a,
                                                100)
     self.two_motors_a = nxt.SynchronizedMotors(self.motor_a, self.motor_c,
                                                100)
Пример #2
0
def callback(cmd):
    l = nxt.Motor(b, nxt.PORT_A)
    r = nxt.Motor(b, nxt.PORT_B)
    if cmd.linear.x != 0.0:
        m = nxt.SynchronizedMotors(l, r, 0)  #the last arg is turn ratio
        m.turn(90, (cmd.linear.x * 10))  #forward
        m.idle()
    elif cmd.angular.z > 0.0:
        m = nxt.SynchronizedMotors(r, l, 127)
        m.turn(90, (cmd.angular.z * 10))
        m.idle()
    elif cmd.angular.z < 0.0:
        m = nxt.SynchronizedMotors(l, r, 127)
        m.turn(90, abs(cmd.angular.z * 10))
        m.idle()
Пример #3
0
 def __init__(self,
              turn_ratio=0,
              power_up=10,
              power_down=-10,
              power_left=20,
              tacho_left=30,
              power_right=20,
              tacho_right=30,
              bluetooth=False):
     if bluetooth:
         self.sock, self.brick = nxt_bluetooth.connectCar(
         )  # noqa PKSM '00:16:53:17:B4:04'
     else:
         self.brick = nxt.locator.find_one_brick()
     self.leftMotor = nxt.Motor(self.brick, nxt.PORT_B)
     self.rightMotor = nxt.Motor(self.brick, nxt.PORT_A)
     self.both = nxt.SynchronizedMotors(self.leftMotor, self.rightMotor,
                                        turn_ratio)
     self.power_up = power_up
     self.power_down = power_down
     self.power_left = power_left
     self.tacho_left = tacho_left
     self.power_right = power_right
     self.tacho_right = tacho_right
     self.btCon = bluetooth
Пример #4
0
def main():

    start = timeit.default_timer()
    print "Looking for brick"
    b = nxt.find_one_brick()
    print "found it"
    l = nxt.Motor(b, nxt.PORT_B)
    r = nxt.Motor(b, nxt.PORT_C)
    m = nxt.SynchronizedMotors(l, r, 0)

    #move forward
    for i in range(3):
        print "image:", i
        m.turn(100, 14400)
        #take_img()
        time.sleep(2)

    for i in range(3):
        print "image:", i
        m.turn(-100, 14400)
        #take_img()
        time.sleep(2)

    stop = timeit.default_timer()
    print "time taken:", stop - start
Пример #5
0
def main():
    if len(sys.argv) < 2:
        print "usage: python rotate2.py foldername"
        exit()

    foldername = sys.argv[1]
    start = timeit.default_timer()
    print "Looking for brick"
    b = nxt.find_one_brick()
    print "found it"
    l = nxt.Motor(b, nxt.PORT_B)
    r = nxt.Motor(b, nxt.PORT_C)
    m = nxt.SynchronizedMotors(l, r, 0)

    for i in range(100):
        print "image:",i
        m.turn(80,75)
        time.sleep(2)
        take_img()

    stop = timeit.default_timer()
    print "time taken:", stop - start
    execute_command("mkdir " + foldername)
    execute_command("mv *.jpg " + foldername)
Пример #6
0
light_a = 0
light_b = 0
light_c = 0

lab = 0
lbc = 0
lca = 0

stop = 0

cap = cv2.VideoCapture(1)

a = nxt.locator.find_one_brick(host='00:16:53:11:5A:F8')
left_a = Motor(a, PORT_C)
right_a = Motor(a, PORT_A)
both_a = nxt.SynchronizedMotors(left_a, right_a, 0)
rightboth_a = nxt.SynchronizedMotors(left_a, right_a, 100)
leftboth_a = nxt.SynchronizedMotors(right_a, left_a, 100)
light_sensor_a = Light(a, PORT_1, False)

b = nxt.locator.find_one_brick(host='00:16:53:0F:0F:D8')
left_b = Motor(b, PORT_C)
right_b = Motor(b, PORT_A)
both_b = nxt.SynchronizedMotors(left_b, right_b, 0)
rightboth_b = nxt.SynchronizedMotors(left_b, right_b, 100)
leftboth_b = nxt.SynchronizedMotors(right_b, left_b, 100)
light_sensor_b = Light(b, PORT_1, False)

c = nxt.locator.find_one_brick(host='00:16:53:0C:1D:29')
left_c = Motor(c, PORT_C)
right_c = Motor(c, PORT_A)
Пример #7
0
LEFT_SLOPE = 0.0093

MIN_DIST_REQUIRED_MOVE = 1  #CM
MAX_CM_MOVMENT = 56
# the system is being dragd up when moving left by this ratio
UP_DRAG_LEFT_SLOPE = 0.0017  # DRAG_UP = cm_left/UP_DRAG_LEFT_SLOPE
# endregion ---CONSTANST---

# region ---INITIALIZE---
"""initialize the program variabels"""
brick = blue.BlueSock(BLUETOOTH_ADDRESS).connect()
print("connected")

m_left = Motor(brick, PORT_A)
m_right = Motor(brick, PORT_C)
both_same = nxt.SynchronizedMotors(m_left, m_right, 0)
both_oposite_A = nxt.SynchronizedMotors(m_right, m_left, MAX_POWER)
both_oposite_B = nxt.SynchronizedMotors(m_left, m_right, MAX_POWER)

# endregion ---INITIALIZE---


def move_XY(y, x):
    if x > 0:
        left(x)
    else:
        right(-x)
    if y > 0:
        up(y)
    else:
        down(-y)
Пример #8
0
#!/usr/bin/env python
#

import nxt
import sys
import tty, termios
import nxt.locator
from nxt.sensor import *
from nxt.motor import *

brick = nxt.locator.find_one_brick()
left = nxt.Motor(brick, PORT_B)
right = nxt.Motor(brick, PORT_C)
both = nxt.SynchronizedMotors(left, right, 0)
camera = nxt.Motor(brick, PORT_A)
leftboth = nxt.SynchronizedMotors(left, right, 100)
rightboth = nxt.SynchronizedMotors(right, left, 100)
guideLight = nxt.Color20(brick, PORT_4)
backSense = nxt.Ultrasonic(brick, PORT_1)
sens = 360
sensTurn = 90
curSens = 5
power = 100
blue = Type.COLORBLUE
green = Type.COLORGREEN
red = Type.COLORRED
off = Type.COLORNONE
curCol = off
guideLight.set_light_color(curCol)
curCol = green
camDeg = 0
Пример #9
0
import os
import time
import nxt
import neuralNetworkPred as nn
from nxt.sensor import *
from nxt.motor import *

print('looking for NXT ... could take 15 seconds')
b = nxt.find_one_brick()

m_left = Motor(b, PORT_B)
m_right = Motor(b, PORT_A)

both = nxt.SynchronizedMotors(m_left, m_right, 0)
rightboth = nxt.SynchronizedMotors(m_left, m_right, 100)
leftboth = nxt.SynchronizedMotors(m_right, m_left, 100)

filecnt = 0
lastAction = ''
while True:
    distance = Ultrasonic(b, PORT_4, check_compatible=False).get_sample()
    state = [0]
    if distance < 50:
        state[0] = 1

    action = nn.nextChoice(state)

    if action == 'forward' and lastAction != 'forward':
        both.run(100)
    elif action == 'left':
        both.brake()
Пример #10
0
def reverse(b, power, time):
    left  = Motor(b, lmotport) 
    right = Motor(b, rmotport)
    both = nxt.SynchronizedMotors(left, right, 0)
    both.turn(-power, time, brake=False)
Пример #11
0
def init_drive_motors(brick):
    ma = nxt.Motor(brick, nxt.PORT_A)
    mb = nxt.Motor(brick, nxt.PORT_B)
    bm = nxt.SynchronizedMotors(ma, mb, 0)
    return ma, mb, bm
Пример #12
0
brick = nxtConnect.btConnect(brickName)

from time import sleep
from nxt.motor import SynchronizedMotors

# see files in library ( /usr/local/lib/python2.7/dist-packages/nxt )
# for a more comprehensive list of ports / commands available
from nxt.motor import Motor, PORT_A, PORT_B, PORT_C
from nxt.sensor import Light, Sound, Touch, Ultrasonic
from nxt.sensor import PORT_1, PORT_2, PORT_3, PORT_4

try:
    motorLeft = Motor(brick, PORT_A)  # plug motor into Port A
    motorRight = Motor(brick, PORT_B)  # plug motor into Port B
    motorBoth = nxt.SynchronizedMotors(motorRight, motorLeft, 0)
    ultraSensor = Ultrasonic(brick,
                             PORT_1)  # plug ultrasonic sensor into Port 1

    #motorSync = SynchronizedMotors(motorA, motorB, 10000)
    #motorSync.idle()
    while ultraSensor.get_sample() > 10:
        print("Current ultrasonic sensor state: {}".format(
            ultraSensor.get_sample()))
        motorBoth.run(power=-120)
        '''motorA.run(power = -128) #go forward
        motorB.run(power = -128) #go forward'''

finally:
    Motor(brick, PORT_A).idle()  # otherwise motor keeps running
    Motor(brick, PORT_B).idle()  # otherwise motor keeps running