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
def connect(self): self.log.info("Connecting ...") try: if self.address == None: self.brick = nxt.find_one_brick().connect() else: self.brick = BlueSock(self.address).connect() except nxt.locator.BrickNotFoundError: raise RobotNotFoundError except Exception as error: raise RobotConnectionError(error) self.leftWhell = Motor(self.brick, self.LEFT_WHEEL) self.rightWhell = Motor(self.brick, self.RIGHT_WHEEL) self.kicker = Motor(self.brick, self.KICKER) self.log.info("Set up Motors") try: # self.kicker.turn(100, 100, brake=True) self.log.debug(self.__read_motor_state(self.KICKER)) except Exception as error: self.log.error("kicker reset error: " + str(error)) self.state = self.STATE_IDLE self.__get_info() self.log.info("Conected to {name}".format(name=self.name)) self.buzz()
def connect(self): self.log.info("Connecting ...") try: if self.address == None: self.brick = nxt.find_one_brick().connect() else: self.brick = BlueSock(self.address).connect() except nxt.locator.BrickNotFoundError: raise RobotNotFoundError except Exception as error: raise RobotConnectionError(error) self.leftWhell = Motor(self.brick, self.LEFT_WHEEL) self.rightWhell = Motor(self.brick, self.RIGHT_WHEEL) self.kicker = Motor(self.brick, self.KICKER) self.log.info("Set up Motors") try: #self.kicker.turn(100, 100, brake=True) self.log.debug(self.__read_motor_state(self.KICKER)) except Exception as error: self.log.error("kicker reset error: " + str(error)) self.state = self.STATE_IDLE self.__get_info() self.log.info("Conected to {name}".format(name=self.name)) self.buzz()
def main(): print "[+] Looking for joystick" while True: pygame.init() pygame.display.init() pygame.display.set_mode((1, 1)) if pygame.joystick.get_count() < 1: time.sleep(1) continue break js = pygame.joystick.Joystick(0) js.init() print "[+] Looking for nxt" while True: try: n = nxt.find_one_brick(host="00:16:53:07:5D:9E") except nxt.locator.BrickNotFoundError: continue break n.play_tone(400, 345) lmotor = nxt.motor.Motor(n, nxt.motor.PORT_A) rmotor = nxt.motor.Motor(n, nxt.motor.PORT_C) print "[+] Got it!" l, r = 0, 0 while True: for event in pygame.event.get(): l = js.get_axis(1) r = js.get_axis(5) update(lmotor, rmotor, -l, r)
def _run_find_brick(self): try: self.brick = nxt.find_one_brick(debug=True) finally: # kivy/android will crash here if we don't detach print('detaching thread') detach()
def initBrick(): global b global right global left b = nxt.find_one_brick() right = nxt.Motor(b, nxt.PORT_C) left = nxt.Motor(b, nxt.PORT_B)
def __init__(self, node_name="nxt_motion_control"): self.node_name = node_name rospy.init_node(self.node_name) rospy.Subscriber('/cmd', Command, self.new_cmd_callback) self.current_cmd = Command(0, 0) self.brick = nxt.find_one_brick(debug = True) self.motor_a = nxt.Motor(self.brick, nxt.PORT_A) self.motor_b = nxt.Motor(self.brick, nxt.PORT_B)
def __init__(self, node_name="nxt_motion_control"): self.node_name = node_name rospy.init_node(self.node_name) rospy.Subscriber('/cmd', Command, self.new_cmd_callback) self.current_cmd = Command(0, 0) self.brick = nxt.find_one_brick() self.motor_a = nxt.Motor(self.brick, nxt.PORT_A) self.motor_b = nxt.Motor(self.brick, nxt.PORT_B)
def __init__(self): threading.Thread.__init__(self) self.stopping = False self.powerLeft = 0.0 self.powerRight = 0.0 self.miniTick = 0 self.motorPlan = [] self.brick = nxt.find_one_brick(method=nxt.locator.Method(bluetooth=False)) self.leftMotor=nxt.Motor(self.brick, nxt.PORT_C) self.rightMotor=nxt.Motor(self.brick, nxt.PORT_A)
def __init__(self): self.b = nxt.find_one_brick() self.leftWheel = drive.Drive(self.b, nxt.PORT_B) self.rightWheel = drive.Drive(self.b, nxt.PORT_C) self.leftWheel.SetParam(1, 1, 1) self.rightWheel.SetParam(1, 1, 1) self.leftWheel.start() self.rightWheel.start()
def initBrick(): global b global r global l global m global mls global mrs b = nxt.find_one_brick() r = nxt.Motor(b, nxt.PORT_A) l = nxt.Motor(b, nxt.PORT_B) # create synchronized motors m = nxt.SynchronizedMotors(r, l, 0) mls = nxt.SynchronizedMotors(l, r, 20) mrs = nxt.SynchronizedMotors(r, l, 20)
def connect(self): print "Connecting ..." try: if self.address == None: self.brick = nxt.find_one_brick().connect() else: self.brick = BlueSock(self.address).connect() except nxt.locator.BrickNotFoundError: raise RobotNotFoundError except BluetoothError as error: raise RobotConnectionError(error) self.__get_info() print "Conected to {name}".format(name=self.name)
def __init__(self, brick_host=None): self.cmd = Commander(brick_finder=lambda: nxt.find_one_brick(host=brick_host)) brick = self.cmd.brick self.platform_motor = nxt.Motor(brick, self.PLATFORM_MOTOR_PORT) self.hand_motor = nxt.Motor(brick, self.HAND_MOTOR_PORT) self.color_sensor_motor = nxt.Motor(brick, self.COLOR_SENSOR_MOTOR_PORT) self.color_sensor = nxt.Color20(brick, self.COLOR_SENSOR_PORT) self.sonar = nxt.Ultrasonic(brick, self.SONAR_PORT) self.motors = [self.hand_motor, self.platform_motor, self.color_sensor_motor] self.idle_all() self.reset_rotation_counts()
def __init__(self): self.brick = nxt.find_one_brick() #set up sensors for p in range(4): try: s = self.brick.get_sensor(p) if isinstance(s, nxt.sensor.hitechnic.Compass): self.compass = s elif isinstance(s, nxt.sensor.hitechnic.Accelerometer): self.accel = s elif isinstance(s, nxt.sensor.generic.Ultrasonic): self.us = s except: # we assume the only other thing connected is a color sensor self.color = nxt.sensor.Color20(self.brick, p) #set up motors self.m_left = nxt.Motor(self.brick, nxt.PORT_C) self.m_right = nxt.Motor(self.brick, nxt.PORT_B)
def main(): # find a brick brick = nxt.find_one_brick() odometer = od.Odometry(brick, 100, 4) # start thread odometer.start() time.sleep(1) turn_right = lambda brick, power, distance: rotate(brick, LEFT_WHEEL, power, distance) turn_left = lambda brick, power, distance: rotate(brick, RIGHT_WHEEL, power, distance) #### Forward(brick, motorspeed, degree_amount) Rotate(brick, speed) #### If rotate speed is positive than robot will turn left else robot will ####turn right lijst = [Forward(brick, 65, 360), Rotate(brick, 65, 90)] position = path(lijst) odometer.join()
def main(): # find a brick brick = nxt.find_one_brick() # start thread time.sleep(1) turn_right = lambda brick, power, distance: rotate(brick, LEFT_WHEEL, power, distance) turn_left = lambda brick, power, distance: rotate(brick, RIGHT_WHEEL, power, distance) #### Forward(brick, motorspeed, degree_amount) Rotate(brick, speed) #### If rotate speed is positive than robot will turn left else robot will ####turn right #lijst = [Forward(brick, 100, 720), Rotate(brick, 100, 90), Forward(brick, # 100, 720), Rotate(brick, -100, 90), Forward(brick, 100, 720)] lijst = [Forward(brick, 100, 360)] position = path(lijst, brick)
def init_nxt(): global nxt_b,nxt_mT,nxt_mG,nxt_mD,nxt_ultrason,nxt_both,nxt_leftboth,nxt_rightboth # was 'find_one_brick' already called and stored in 'nxt_b' ? if 'nxt_b' not in globals(): try: nxt_b = nxt.find_one_brick() except nxt.locator.BrickNotFoundError: print("Attention: la brique du NxT n'a pas ete trouvee") return False nxt_mT = nxt.Motor(nxt_b, nxt_port_tourelle) nxt_mG = nxt.Motor(nxt_b, nxt_port_moteur_gauche) nxt_mD = nxt.Motor(nxt_b, nxt_port_moteur_droit) nxt_ultrason = nxt.sensor.Ultrasonic(nxt_b,nxt_port_ultrason) nxt_both = nxt.SynchronizedMotors(nxt_mG, nxt_mD, 0) nxt_leftboth = nxt.SynchronizedMotors(nxt_mG, nxt_mD, 100) nxt_rightboth = nxt.SynchronizedMotors(nxt_mD, nxt_mG, 100) return True
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)
import nxt import nxtConnect # has to be in search path import time brickName = "Team60" useUSB = False if useUSB: brick = nxt.find_one_brick(name=brickName, strict=True, method=nxt.locator.Method(usb=True, bluetooth=True)) else: # the bluetooth function of the nxt library works too, but "wastes" # time searching for devices. brick = nxtConnect.btConnect(brickName) print(brick.get_device_info()) # check what brick you connected to from time import sleep from nxt.motor import Motor, PORT_A, PORT_B, PORT_C from nxt.sensor import Touch, PORT_4, PORT_3, PORT_2, Light, PORT_1, Ultrasonic turningMotor = Motor(brick, PORT_B) walkingMotor = Motor(brick, PORT_C) armMotor = Motor(brick, PORT_A) legPosition = Touch(brick, PORT_3) touch = Touch(brick, PORT_1) while True: print(touch.get_input_values().calibrated_value)
# -*- coding: utf-8 -*- """ Telemetry """ import random import nxt, thread, time from math import * import numpy as np import matplotlib.pyplot as plt robot = nxt.find_one_brick() mA = nxt.Motor(robot, nxt.PORT_B) mB = nxt.Motor(robot, nxt.PORT_C) sonar = nxt.sensor.Ultrasonic(robot,nxt.PORT_1) """def new_box(x,y,c): V = turtle.Turtle() V.hideturtle(); V.penup() V.setpos(x-c/2,y-c/2); V.setheading(0) ; V.pendown() for i in range(4): V.fd(c) V.left(90) return Polygon(Point(x-c/2,y-c/2),Point(x-c/2,y+c/2),Point(x+c/2,y+c/2),Point(x+c/2,y-c/2)) """ def telemetry(T,boxelist): a = radians(T.heading()) P1,P2 = Point(T.xcor(),T.ycor()) , Point(T.xcor()+cos(a),T.ycor()+sin(a)) P12 = P2 - P1 intr = [N(P12.dot(p-P1)) for r in boxelist for p in intersection(Line(P1,P2),r) ]
import nxt, thread, time b = nxt.find_one_brick() mx = nxt.Motor(b, nxt.PORT_B) my = nxt.Motor(b, nxt.PORT_C) motors = [mx, my] def turnmotor(m, power, degrees): m.turn(power, degrees) instructions = ( [0, 0, 80, 1080], [0, 1, 80, 1080], [3, 0, 100, 1080], [3, 1, 100, 1080], [6, 0, 100, 1080], [6, 1, -100, 1080], [9, 0, 100, 2000], [9, 1, 100, 2000], ) length = 5 def runinstruction(i): motorid, speed, degrees = i #THIS IS THE IMPORTANT PART! thread.start_new_thread( turnmotor, (motors[motorid], speed, degrees)) seconds = 0 while 1:
def __enter__(self): self.brick = nxt.find_one_brick(method=nxt.locator.Method(bluetooth=False)) self.leftMotor=nxt.Motor(self.brick, nxt.PORT_C) self.rightMotor=nxt.Motor(self.brick, nxt.PORT_A) return self
def init_nxt(): return nxt.find_one_brick(name='NXT')
def __init__(self): self.brick = find_one_brick() self.motors = PortMap(self.motorPorts.keys(), self._motor_factory()) self.sensors = {}
import time import nxt FORWARD_SPEED = 50 TURN_SPEED = 50 LEFT = -1 RIGHT = 1 brick = nxt.find_one_brick() motors = [nxt.Motor(brick, nxt.PORT_B), nxt.Motor(brick, nxt.PORT_C)] def stop(secs=0.2): for motor in motors: motor.idle() if secs: time.sleep(secs) def forward(secs=0.2): for motor in motors: motor.run(FORWARD_SPEED, regulated=True) if secs: time.sleep(secs) stop(0)
# -*- coding=utf8 -*- ''' Created on 14.04.2011 @author: jskonst ''' import thread, drive, time, nxt b = nxt.find_one_brick()#name = 'MyNXT',debug=True) drive1=drive.Drive(b, nxt.PORT_B) drive2=drive.Drive(b, nxt.PORT_C) drive1.SetParam(1,1,1) drive2.SetParam(1,1,1) drive1.start() drive2.start() drive1.stop() drive2.stop() while 1: a=raw_input() if a=="q": drive1.stop() drive2.stop() drive1.join() drive2.join() break else: if a=="w": print "Вперед" drive1.stop() drive2.stop() drive1.join()
# -*- coding:utf8 -*- import socket import drive import nxt import json import requests import time import test_sensors host = "localhost" port = 5678 b = nxt.find_one_brick(name='MyNXT') drive1 = drive.Drive(b, nxt.PORT_B) drive2 = drive.Drive(b, nxt.PORT_C) drive1.SetParam(1, 1, 1) drive2.SetParam(1, 1, 1) drive1.start() drive2.start() drive1.stop() drive2.stop() def action(a, drive1, drive2): StatusOfButton = nxt.Touch(b, nxt.PORT_3).get_sample() if a == "q": drive1.stop() drive2.stop() drive1.join() drive2.join() else:
# -*- coding=utf8 -*- ''' Created on 14.04.2011 @author: jskonst ''' import drive import nxt while 1: b = nxt.find_one_brick(name='MyNXT') drive1 = drive.Drive(b, nxt.PORT_B) drive2 = drive.Drive(b, nxt.PORT_C) drive1.SetParam(1, 1, 1) drive2.SetParam(1, 1, 1) drive1.start() drive2.start() drive1.stop() drive2.stop() a = raw_input() if a == "q": drive1.stop() drive2.stop() drive1.join() drive2.join() break else: if a == "w": print "Вперед" drive1.stop() drive2.stop()