예제 #1
0
    def testunplugged(self):
        raw_input("Unplug the boards.")

        [smnr, mtrn] = prop.serialcomm()

        self.assertEqual(smnr, None)
        self.assertEqual(mtrn, None)
예제 #2
0
    def testtxrx(self):
        [smnr, mtrn] = prop.serialcomm()

        print 'Testing serial comm'
        mtrn.write('D')
        smnr.write('D')

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port

        print "Tilt down"
        smnr.write('T')
        time.sleep(3)
        print "Go back"
        smnr.write('G')
        time.sleep(3)
        print "Pan Left"
        smnr.write('H')
        time.sleep(3)
        print "Pan Right"
        smnr.write('F')
        time.sleep(3)
        print "Go back"
        smnr.write('G')

        for i in range(1, 10000):
            mtrn.write('A1200')
            smnr.write('S')

            rsp = mtrn.read(250)
            rsp = smnr.read(250)

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port
        print "Done"
예제 #3
0
    def testunplugged(self):
        raw_input("Unplug the boards.")

        [smnr, mtrn] = prop.serialcomm()

        self.assertEqual(smnr,None)
        self.assertEqual(mtrn,None)
예제 #4
0
def doserial():
    retries = 1
    ssmr = None
    mtrn = None
    while (retries < 5):
        try:
            if system_platform == "Darwin":
                [ssmr, mtrn] = prop.serialcomm('/dev/cu.usbmodem14101')
            else:
                [ssmr, mtrn] = prop.serialcomm()
            print 'Connection established'
            return [ssmr, mtrn]
        except Exception as e:
            print 'Error while establishing serial connection.'
            retries = retries + 1

    return [ssmr, mtrn]
예제 #5
0
    def test(self):
        [smnr, mtrn] = prop.serialcomm()
        print smnr.read(250)
        print mtrn.read(250)

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port

        self.assertEqual(whoisthis(smnr)[0:4], 'SSMR')
        self.assertEqual(whoisthis(mtrn)[0:4], 'MTRN')

        smnr.close()
        mtrn.close()
예제 #6
0
    def test(self):
        [smnr, mtrn] = prop.serialcomm()
        print smnr.read(250)
        print mtrn.read(250)


        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port

        self.assertEqual(whoisthis(smnr)[0:4],'SSMR')
        self.assertEqual(whoisthis(mtrn)[0:4],'MTRN')

        smnr.close()
        mtrn.close()
예제 #7
0
def doserial():
    retries = 1
    ssmr = None
    mtrn = None
    while (retries < 5):
        try:
            [ssmr, mtrn] = prop.serialcomm()
            print 'Connection established'
            return [ssmr, mtrn]
        except Exception as e:
            print 'Error while establishing serial connection.'
            retries = retries + 1

    return [ssmr, mtrn]
예제 #8
0
    def testtxrx(self):
        [smnr, mtrn] = prop.serialcomm()

        print 'Testing serial comm'
        mtrn.write('D')
        smnr.write('D')

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port

        for i in range(1, 10000):
            mtrn.write('A1200')
            smnr.write('S')

            rsp = mtrn.read(250)
            rsp = smnr.read(250)

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port
        print "Done"
예제 #9
0
    def testtxrx(self):
        [smnr, mtrn] = prop.serialcomm()
        
        print 'Testing serial comm'
        mtrn.write('D')
        smnr.write('D')

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port

        for i in range(1,10000):
            mtrn.write('A1200')
            smnr.write('S')

            rsp = mtrn.read(250)
            rsp = smnr.read(250)
            
        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port
        print "Done"
예제 #10
0
    def testtxrx(self):
        [smnr, mtrn] = prop.serialcomm()
        
        print 'Testing serial comm'
        mtrn.write('D')
        smnr.write('D')

        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port

        print "Tilt down"
        smnr.write('T')
        time.sleep(3)
        print "Go back"
        smnr.write('G')
        time.sleep(3)
        print "Pan Left"
        smnr.write('H')
        time.sleep(3)
        print "Pan Right"
        smnr.write('F')
        time.sleep(3)
        print "Go back"
        smnr.write('G')
        

        for i in range(1,10000):
            mtrn.write('A1200')
            smnr.write('S')

            rsp = mtrn.read(250)
            rsp = smnr.read(250)
            
        print "SMNR Serial Port:", smnr.port
        print "MTRN Serial Port:", mtrn.port
        print "Done"
예제 #11
0
import cv2

import serial

import time
from struct import *

import sys, os, select

import socket

import thread
import Proprioceptive as prop

# Open connection to tilt sensor.
hidraw = prop.setupsensor()
# Open serial connection to MotorUnit and Sensorimotor Arduinos.
#[ssmr, mtrn] = prop.serialcomm()

mtrn = serial.Serial(port='/dev/cu.usbmodem1421', timeout=0, baudrate=9600)

mtrn.read(250)

time.sleep(2)
mtrn.read(250)

#mtrn.write('A3250')
time.sleep(0.2)  # This time depends on the weight
#mtrn.write('A3000')
mtrn.write('A6090')
time.sleep(0.5)
예제 #12
0
    def sendsensorsample(self, smnr, mtrn):
        # read  Embed this in a loop.
        self.counter=self.counter+1
        if (self.counter>500):
            smnr.write('P')
            smnr.write('S')
            self.counter=0
        myByte = smnr.read(1)
        if myByte == 'S':
          data = smnr.read(38)
          myByte = smnr.read(1)
          if myByte == 'E':
              # is  a valid message struct
              new_values = unpack('ffffffhhhhhhh', data)
              print new_values
              sent = self.sock.sendto(data, self.server_address)
              self.f.write( str(new_values[6]) + ' ' + str(new_values[7]) + ' ' + str(new_values[8]) + '\n')

    def close(self):
        self.f.close()

if __name__ == "__main__":
    [smnr, mtrn] = prop.serialcomm()

    sensorimotor = Sensorimotor()
    sensorimotor.start()
    sensorimotor.cleanbuffer(smnr,mtrn)

    while True:
        sensorimotor.sendsensorsample(smnr,mtrn)
예제 #13
0
import serial

import time
from struct import *

import sys, os, select

import socket

import thread
import Proprioceptive as prop


# Open connection to tilt sensor.
hidraw = prop.setupsensor()
# Open serial connection to MotorUnit and Sensorimotor Arduinos.
#[ssmr, mtrn] = prop.serialcomm()

mtrn = serial.Serial(port='/dev/cu.usbmodem1421',timeout=0, baudrate=9600);

mtrn.read(250);

time.sleep(2)
mtrn.read(250)

#mtrn.write('A3250')
time.sleep(0.2) # This time depends on the weight
#mtrn.write('A3000')
mtrn.write('A6090')
time.sleep(0.5)
예제 #14
0
myip = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1]
myip = myip[0]

# Shinkeybot truly does nothing until it gets the remote controlling connection
print 'Multicasting my own IP address:' + myip
while True:
    noticer.send()
    try:
        data, address = sock.recvfrom(1)
        if (len(data)>0):
            break
    except:
        data = None

# Open connection to tilt sensor.
hidraw = prop.setupsensor()
# Open serial connection to MotorUnit and Sensorimotor Arduinos.
[ssmr, mtrn] = prop.serialcomm()

# Instruct the Sensorimotor Cortex to stop wandering.
ssmr.write('C')

tgt = -300
wristpos=48

elbowpos = 150

# Pan and tilt
visualpos = [90,95]

sensesensor = 0
예제 #15
0
from struct import *
import os

import socket
import sys

import Proprioceptive as prop

import Configuration

from Fps import Fps

import SensorimotorLogger as Senso

if __name__ == "__main__":
    [ssmr, mtrn] = prop.serialcomm()

    # Weird, long values (4) should go first.
    #sensorimotor = Sensorimotor('motorneuron',26,'hhffffhhh')
    sensorimotor = Senso.Sensorimotor('sensorimotor',16,'fffhh')
    sensorimotor.sensorlocalburst=100
    sensorimotor.sensorburst=10
    sensorimotor.updatefreq=10
    sensorimotor.ip = sys.argv[1]
    sensorimotor.start()
    sensorimotor.init(ssmr)
    print (sensorimotor.mapping)
    print (sensorimotor.length)
    sensorimotor.cleanbuffer(ssmr)

    fps = Fps()
예제 #16
0
                self.sensors = new_values
                #self.f.write( str(new_values[0]) + ' ' + str(new_values[1]) + ' ' + str(new_values[2]) + ' ' + str(new_values[3]) + ' ' + str(new_values[4]) + ' ' + str(new_values[5]) + ' ' + str(new_values[6]) + ' ' + str(new_values[7]) + ' ' + str(new_values[8]) + ' ' + str(new_values[9]) + ' ' + str(new_values[10]) + ' ' + str(new_values[11]) + ' ' + str(new_values[12]) + ' ' +  str(new_values[13]) + ' ' + str(new_values[14]) + '\n')
                self.f.write(' '.join(map(str, new_values)) + '\n')
                return new_values

    def close(self):
        self.f.close()
        self.sock.close()

    def restart(self):
        self.close()
        self.start()


if __name__ == "__main__":
    [ssmr, mtrn] = prop.serialcomm('/dev/cu.usbmodem1421')

    # Weird, long values (4) should go first.
    #sensorimotor = Sensorimotor('motorneuron',26,'hhffffhhh')
    sensorimotor = Sensorimotor('sensorimotor', 52, 'ffffffhhhhhhhhhhhhhh')
    sensorimotor.ip = sys.argv[1]
    sensorimotor.start()
    sensorimotor.cleanbuffer(ssmr)

    while True:
        sens = sensorimotor.picksensorsample(ssmr)
        mots = None
        sensorimotor.sensorlocalburst = 10000
        sensorimotor.sensorburst = 10
        if (sens != None):
            sensorimotor.send(sensorimotor.data)
예제 #17
0
            self.data = readsomething(ser, self.length)
            myByte = readsomething(ser, 1)
            if len(myByte) >= 1 and myByte == 'E':
                # is  a valid message struct
                #new_values = unpack('ffffffhhhhhhhhhh', data)
                new_values = unpack(self.mapping, self.data)
                #print new_values
                self.sensors = new_values
                #self.f.write( str(new_values[0]) + ' ' + str(new_values[1]) + ' ' + str(new_values[2]) + ' ' + str(new_values[3]) + ' ' + str(new_values[4]) + ' ' + str(new_values[5]) + ' ' + str(new_values[6]) + ' ' + str(new_values[7]) + ' ' + str(new_values[8]) + ' ' + str(new_values[9]) + ' ' + str(new_values[10]) + ' ' + str(new_values[11]) + ' ' + str(new_values[12]) + ' ' +  str(new_values[13]) + ' ' + str(new_values[14]) + '\n')
                self.f.write(' '.join(map(str, new_values)) + '\n')
                return new_values

    def close(self):
        self.f.close()
        self.sock.close()

    def restart(self):
        self.close()
        self.start()


if __name__ == "__main__":
    [smnr, mtrn] = prop.serialcomm()

    sensorimotor = Sensorimotor()
    sensorimotor.start()
    sensorimotor.cleanbuffer(smnr)

    while True:
        sensorimotor.sendsensorsample(smnr)