Example #1
0
                        if cmd == 4:
                            #                             print data
                            in_dir = (data[2] << 8) | data[1]
                            listed = data[3]
                            if self.dir_start == 0:
                                print "listing dir '%s'" % self.dir_path
                                print "total", in_dir

                            for i in range(listed):
                                index = 4 + i * 12
                                fname = "".join(
                                    map(chr, data[index:index + 12]))
                                print "\t", i + self.dir_start, "\t", fname

                            if in_dir > self.dir_start + listed:
                                self.list_dir(self.dir_path,
                                              self.dir_start + listed)


if __name__ == "__main__":
    from_ui = CommandQuee()
    to_ui = CommandQuee()

    stream = SerialStream(from_ui, to_ui)
    stream.open("/dev/rfcomm1", 115200)
    stream.start()

    ui = Interface(to_ui, from_ui)
    ui.start()
Example #2
0
    def initServos(self):
        # Set your serial port accordingly.
        if os.name == "posix":
            possibilities = ['dev/ttyACM'
                             ] + ['/dev/ttyACM' + str(i) for i in range(25)]
            portName = None
            for pos in possibilities:
                if os.path.exists(pos):
                    portName = pos
            if portName is None:
                raise Exception('Could not find any of %s' %
                                repr(possibilities))
        else:
            portName = "COM9"

        serial = SerialStream(port=portName, baudrate=self.baudRate, timeout=1)
        self.net = DynamixelNetwork(serial)

        #print 'Prescan...'
        #print self.net.get_dynamixels()

        print "Scanning for Dynamixels...",
        self.net.scan(min(self.expectedIds), max(self.expectedIds))

        self.actuators = []
        self.actuatorIds = []

        for dyn in self.net.get_dynamixels():
            print dyn.id,
            self.actuatorIds.append(dyn.id)
            self.actuators.append(self.net[dyn.id])
        print "...Done"

        if len(self.actuators) != self.nServos and not self.silentNetFail:
            raise RobotFailure(
                'Expected to find %d servos on network, but only got %d (%s)' %
                (self.nServos, len(self.actuators), repr(self.actuatorIds)))

        for actuator in self.actuators:
            #actuator.moving_speed = 90
            #actuator.synchronized = True
            #actuator.torque_enable = True
            #actuator.torque_limit = 1000
            #actuator.max_torque = 1000

            actuator.moving_speed = 250
            actuator.synchronized = True
            actuator.torque_enable = True
            actuator.torque_limit = 1000
            actuator.max_torque = 1000
            actuator.ccw_compliance_margin = 3
            actuator.cw_compliance_margin = 3

        self.net.synchronize()

        #print 'options are:'
        #for op in dir(self.actuators[0]):
        #    print '  ', op
        #for ac in self.actuators:
        #    print 'Voltage at', ac, 'is', ac.current_voltage, 'load is', ac.current_load
        #    ac.read_all()

        self.currentPos = None
        self.resetClock()
Example #3
0
def startUsbStream():
    messageid = 0
    return SerialStream(port='/dev/ttyUSB1', baudrate=57600)
from serial import *
from threading import Thread
from time import sleep
from serial_stream import SerialStream

ser = SerialStream(
    port='/dev/ttyUSB1',
    baudrate=57600,
    # baudrate=111200,
    # baudrate=96600,
    # bytesize=EIGHTBITS,
    # parity=PARITY_NONE,
    # stopbits=STOPBITS_ONE,
    timeout=0.1,
    xonxoff=0,
    rtscts=0,
    interCharTimeout=None,
    bytesize=8,
    parity=PARITY_EVEN,
    stopbits=STOPBITS_ONE)

while True:
    s = ser.read(100)
    if (s):
        print s
Example #5
0
#                         print "RX data", data
                        
                        op_hi = data[0]
                        op_lo = data[1]
                        print "op_high %02X" % op_hi
                        print "op_low  %02X" % op_lo
                        
                        if op_lo == 0xFF:
                            print "Unknown command"
                            print "Enter high op code to begin in hex"
                            self.get_modules()                            
                            continue
                        
                        data = data[2:]
                        print data
                        
                        self.get_meaning(op_hi, op_lo, data)

   
if __name__ == "__main__":
    from_ui = CommandQuee()
    to_ui = CommandQuee()

    stream = SerialStream(from_ui, to_ui)
    stream.open("/dev/rfcomm0", 115200)
    stream.start()
    
    ui = Interface(to_ui, from_ui)
    ui.start()
    
from serial import *
from threading import Thread
from time import sleep
from serial_stream import SerialStream

ser = SerialStream(
    port="/dev/ttyUSB1",
    baudrate=57600,
    # baudrate=111200,
    # baudrate=96600,
    # bytesize=EIGHTBITS,
    # parity=PARITY_NONE,
    # stopbits=STOPBITS_ONE,
    timeout=0.1,
    xonxoff=0,
    rtscts=0,
    interCharTimeout=None,
    bytesize=8,
    parity=PARITY_EVEN,
    stopbits=STOPBITS_ONE,
)


while True:
    s = ser.read(100)
    if s:
        print s