Example #1
0
def main():
    # Coonecting with server
    host,port = "127.0.0.1" , 10160
    # Connecting with Robot via Bluetooth
    sock =  BlueSock(ID)
    b = sock.connect()
    clientSocket = socket.socket()
    clientSocket.connect((host,port))
    clientSocket.send('bluetooth '+'#')
    flag=0

    Chartext = clientSocket.recv(1024)
    print Chartext
    # Always listening for command
    while Chartext != "Exit":
        try:
            Chartext = clientSocket.recv(1024)
            if Chartext=='a':
                left(b)
            elif Chartext=='d':
                right(b)
            elif Chartext=='e':
                off(b)
            elif Chartext=='x':
                on(b)
            if flag==1:
                b = sock.connect()
                flag=0
        # Exception Handling
        except:
            sock.close()
            clientSocket.send('Exit')
            clientSocket.close()
            break
Example #2
0
class BrickGetter:

	def __init__(self):
	    self.sock = None

	def getBrick(self):
		# Create socket to NXT brick
		self.sock = BlueSock(ID)

		# On success, socket is non-empty
		if self.sock:

		   print('Connecting...');
		   # Connect to brick
		   brick = self.sock.connect()
		   print('Connected!');
		   return brick

		   # Play tone A above middle C for 1000 msec
		   # brick.play_tone_and_wait(440, 500)

		# Failure
		else:
		   print('No NXT bricks found')

    #not neccessary since when brick is garabage collected
    #brick automatically closes
	def close(self):

	    self.sock.close()
Example #3
0
class NXTReceiver(object):
    "Slave to the NXT"
    bs = None
    sock = None

    def __init__(self):
        self.bs = BlueSock("00:16:53:12:C0:CA:00")
        self.bs.debug = True
        self.bs.connect()
        self.sock = self.bs.sock

    def recv(self, len):
        "Iteratively waits for input until the desired size is achieved"
        received = 0
        payload = ""
        while received < len:
            t = self.sock.recv(len - received)
            received += t.__len__()
            payload += t
        return payload
Example #4
0
from __future__ import print_function
from nxt.bluesock import BlueSock
from struct import unpack

bs = BlueSock("00:16:53:12:C0:CA:00")
bs.debug = True
bs.connect()
sock = bs.sock

for i in range(0, 2):
    for j in range(0, 128):
        try:
            t = sock.recv(2)
            (val,) = unpack("H", t)
            print(val, end=",")
        except Exception:
            pass
Example #5
0
import nxt, thread, time

import numpy as np

import drive
import arm

# this find_one_brick method is unreliable
#b = nxt.find_one_brick(host=ID)

from nxt.bluesock import BlueSock

# connection to first brick "JAWS"
ID1 = '00:16:53:17:52:EE' # MAC address
sock1 = BlueSock(ID1)
b1 = sock1.connect()

# connection to 2nd brick "pie" 
#ID2 = '00:16:53:0A:4B:2B' # MAC address
#sock2 = BlueSock(ID2)
#b2 = sock2.connect()

mx = nxt.Motor(b1, nxt.PORT_A) # left-side
my = nxt.Motor(b1, nxt.PORT_B) # right-side

d = drive.Drive(mx,my)


marm = nxt.Motor(b1, nxt.PORT_C) # arm motor

a = arm.Arm(marm)
# Program to make NXT brick beep using NXT Python with Bluetooth socket
#
# Simon D. Levy  CSCI 250   Washington and Lee University    April 2011

# Change this ID to match the one on your brick.  You can find the ID by doing Settings / NXT Version.
# You will have to put a colon between each pair of digits.
ID = '00:16:53:11:3D:03'

# This is all we need to import for the beep, but you'll need more for motors, sensors, etc.
from nxt.bluesock import BlueSock

# Create socket to NXT brick
sock = 	BlueSock(ID)

# On success, socket is non-empty
if sock:

   # Connect to brick
   brick = sock.connect()

   # Play tone A above middle C for 1000 msec
   brick.play_tone_and_wait(440, 1000)

   # Close socket
   sock.close()

# Failure
else:
   print ('No NXT bricks found')
Example #7
0
#!/usr/bin/env python
#
# Converted from mary.rb found in ruby_nxt package
# Plays "Mary Had A Little Lamb"
# Author: Christopher Continanza <*****@*****.**>

from time import sleep
import nxt

ID = '00:16:53:17:41:FE'
IDD = '00:16:53:17:47:6F'
from nxt.bluesock import BlueSock



sock = 	BlueSock(ID)
b = sock.connect()

#b.stop_program()
b.start_program('hanse.rxe')
#b.StartProgram("kostwein.rxe")

sock.close;
Example #8
0
# Program to make NXT brick beep using NXT Python with Bluetooth socket
#
# Simon D. Levy  CSCI 250   Washington and Lee University    April 2011

# Change this ID to match the one on your brick.  You can find the ID by doing Settings / NXT Version.
# You will have to put a colon between each pair of digits.
ID = '00:16:53:05:15:50'

# This is all we need to import for the beep, but you'll need more for motors, sensors, etc.
from nxt.bluesock import BlueSock

# Create socket to NXT brick
sock = BlueSock(ID)

# Connect to brick
brick = sock.connect()

# Play tone A above middle C for 1000 msec
brick.play_tone_and_wait(440, 1000)

# Close socket
sock.close()

# EOF