def __init__(self, parent): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=6) self.parent = parent try: current_locale, encoding = locale.getdefaultlocale() locale_path = os.path.join( os.path.abspath(os.path.dirname(__file__)), 'locale') translate = gettext.translation(cn.App.application_shortname, locale_path, [current_locale]) _ = translate.gettext except FileNotFoundError: _ = str self.stack = Gtk.Stack() self.stack.set_transition_type( Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) self.stack.set_transition_duration(1000) self.welcome = wl.Welcome(self) self.create = cr.Create(self) self.importer = im.Importer(self) self.detail = dt.Detail(self) self.list_all = ls.List(self) self.stack.add_titled(self.welcome, "welcome", _('Welcome')) self.stack.add_titled(self.create, "create", _('Create')) self.stack.add_titled(self.importer, "importer", _('Importer')) self.stack.add_titled(self.detail, "detail", _('Detail')) self.stack.add_titled(self.list_all, "list", _('List')) self.pack_start(self.stack, True, True, 0)
def __init__(self, port): self.create = create.Create(port, 3) self.create.playSong(((70, 8), (72, 8), (68, 8), (56, 8), (63, 8))) self.packetPub = rospy.Publisher('~sensorData', SensorPacket) self.odomPub = rospy.Publisher('/odom', Odometry) self.odomBroadcaster = TransformBroadcaster() self.fields = [ 'wheeldropCaster', 'wheeldropLeft', 'wheeldropRight', 'bumpLeft', 'bumpRight', 'wall', 'cliffLeft', 'cliffFronLeft', 'cliffFrontRight', 'cliffRight', 'virtualWall', 'infraredByte', 'advance', 'play', 'distance', 'angle', 'chargingState', 'voltage', 'current', 'batteryTemperature', 'batteryCharge', 'batteryCapacity', 'wallSignal', 'cliffLeftSignal', 'cliffFrontLeftSignal', 'cliffFrontRightSignal', 'cliffRightSignal', 'homeBase', 'internalCharger', 'songNumber', 'songPlaying', 'x', 'y', 'theta', 'chargeLevel' ] self.then = datetime.now() self.dist = 0 self.theta = 0 self.x = 0 self.y = 0 self.last = rospy.Time.now() self.baseFrame = rospy.get_param("~base_frame", "/base_link") self.odomFrame = rospy.get_param("~odom_frame", "/odom")
def checkCharge(): r = create.Create("/dev/ttyUSB0") charge = r.getSensor('BATTERY_CHARGE') capacity = r.getSensor('BATTERY_CAPACITY') print("BATTERY:", charge/capacity*100//1, "%") if((charge/capacity*100//1) <= 20 ): print("FINDING DOCK")
def auto_connect(self): #so far only compatible with windows, need to add code to handle linux port handling ## try: ## val = int(self.port) ## except ValueError: ## raise InputError('Port Argument is Invalid: ', self.port) ## else: ## port_name = "COM" + repr(val) #Allow create.py to determine if port_name is valid for either Linux or Windows return create.Create(self.port)
def initRobot(): #This opens the serial connection to the create #if this raises an error, try /dev/ttyUSB1 #if this is still an error try listing the ports in /dev/ try: r =create.Create('/dev/ttyUSB0') except serial.serialutil.SerialException: r = create.Create('/dev/ttyUSB1') #r.reset() sleep(2) #this is how you'd test sensors if you wanted #print(r.getSensor('ANGLE')) #print(r.getSensor('DISTANCE')) #this makes the input work by flushing the buffer r.ser.flush() #return the robot object to be used for turning return r
def aimain(): r = create.Create(4) r.toFullMode() deviation = 0 print 'to full mode' r.go(0, -90) time.sleep(1.05) r.go(20, 0) level1(r) deviation = transit1(r) level2(r, deviation) transit2(r) level3(r) transit3(r) level4(r) level5(r) r.stop() return
def aimain(): r = create.Create(4) r.toFullMode() deviation = 0 print 'to full mode' # r.go(0,-90) # time.sleep(1.05) # r.go(20,0) # level1(r) # deviation = transit1(r) deviation = 10150 + deviation # Total calculated distance for level 2 is 980 + 3300 + 1050 + 20 extra (5350) level3(r, deviation, 2) # Actual level 2 transit2(r) level3(r, 8200, 3) # Actual level 3 dist = 5700 prev = 6700 transit3(r) level3(r, 5500, 4) # Actual level 4 prev = 7500 level5(r) r.stop() return
def init( ): #Initialize variables and create staring node. Default direction is "North" global globalX, globalY, direction, roomList, currentNode, posX, posY, \ numNodes, maxX, maxY, turnCount, stop, TRIG, ECHO, TRIG_R, ECHO_R, TRIG_L, ECHO_L, \ threshold_Front, threshold_R, threshold_L, robot, turnAngle, moveDist, seperationWidth, hallwayWidth, \ dockPercent, battery robot = create.Create('/dev/ttyUSB0') turnAngle = -90 moveDist = 100 #GPIO Mapping for Front, Left and Right sonar sensors TRIG = 23 ECHO = 25 TRIG_R = 4 ECHO_R = 21 ECHO_L = 12 TRIG_L = 24 #Sensitivity Threshold for Obstacle distance in cm threshold_Front = 120 threshold_L = 150 threshold_R = 150 hallwayWidth = 250 seperationWidth = 32 globalX = globalY = 4 turnCount = 0 posX = posY = 0 maxX = maxY = 0 direction = "North" roomList = [[]] currentNode = Node(0, None, None, None, None, posX, posY) roomList[0].append(currentNode) numNodes = 0 stop = 0 dockPercent = 20 battery = 100 waitVal = checkCharge()
#!/usr/bin/python # This is server.py file import socket # Import socket module import create import task1 from task1 import * b = create.Create(4) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. BUFFER_SIZE = 1024 # Normally 1024, but we want fast response s.bind((host, port)) # Bind to the port while True: s.listen(5) conn, addr = s.accept() print 'Connection address:', addr while True: print "top" data = conn.recv(BUFFER_SIZE) print "bottom" conn.send(data) # echo if data == 'r': print "received data:", data quickright(b)
#!/usr/bin/python # This is server.py file import socket # Import socket module import create import task1 from task1 import * b = create.Create(7) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object host = socket.gethostname() # Get local machine name port = 12346 # Reserve a port for your service. BUFFER_SIZE = 1024 # Normally 1024, but we want fast response s.bind((host, port)) # Bind to the port while True: s.listen(5) conn, addr = s.accept() print 'Connection address:', addr while True: print "top" data = conn.recv(BUFFER_SIZE) print "bottom" conn.send(data) # echo if data == 'r': print "received data:", data quickright(b)
#!/usr/bin/python # This is server.py file import socket # Import socket module import create import task1 from task1 import * b = create.Create(3) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. BUFFER_SIZE = 1024 # Normally 1024, but we want fast response s.bind((host, port)) # Bind to the port while True: s.listen(5) conn, addr = s.accept() print 'Connection address:', addr while True: print "top" data = conn.recv(BUFFER_SIZE) print "bottom" conn.send(data) # echo if data == 'r': print "received data:", data quickright(b)
def main(): r = create.Create('/dev/ttyUSB0') r.toSafeMode() r.seekDock()
import create import time ROOMBA_PORT="/dev/ttyUSB0" robot = create.Create(ROOMBA_PORT) #robot.printSensors() # debug output wall_fun = robot.senseFunc(create.WALL_SIGNAL) # get a callback for a sensor. #print (wall_fun()) # print a sensor value. robot.toSafeMode() cnt = 0 while cnt < 10 : robot.go(0,1000) # spin cnt+=1 time.sleep(0.5) #time.sleep(2.0) robot.close()
keys.sort() for k in keys: print(k, ' = ', sensor_dict[k]) def sensor_print_file(sensor_dict): out_file = open('/tmp/sense.log', 'w') for k, v in sensor_dict.items(): out_file.write(k + "," + str(v) + "\n") out_file.close() def main(r): """Query the robot's sensors and print the result.""" sensor_dict = sensor_dict_int(r, SENSOR_KEYS) sensor_dict_add = sensor_dict_list(r, 'BUMPS_AND_WHEEL_DROPS', \ BUMP_AND_WHEEL_DROP_KEYS) sensor_dict.update(sensor_dict_add) sensor_dict_add = sensor_dict_list(r, 'BUTTONS', BUTTON_KEYS) sensor_dict.update(sensor_dict_add) sensor_dict_add = sensor_dict_list(r, 'OVERCURRENTS', OVERCURRENT_KEYS) sensor_dict.update(sensor_dict_add) sensor_print(sensor_dict) sensor_print_file(sensor_dict) if __name__ == '__main__': r = create.Create(SERIAL_PORT) main(r) r.shutdown()
def test_spin(self): r = create.Create(SERIAL_PORT) move.spin(r) time.sleep(2) r.shutdown()
def test_wiggle(self): r = create.Create(SERIAL_PORT) move.wiggle(r) time.sleep(2) r.shutdown()
def test_twist(self): r = create.Create(SERIAL_PORT) move.twist(r) time.sleep(2) r.shutdown()
def test_side_step(self): r = create.Create(SERIAL_PORT) move.side_step(r) time.sleep(2) r.shutdown()
def test_main(self): r = create.Create(SERIAL_PORT) sense.main(r) r.shutdown()
def __init__(self, port): self._port = port self.bot = create.Create(port) self.degree = 5 self.distance = 5
from create import * from time import * import create robot = create.Create(3) def wait(): sleep(.5) def die(): robot.turn(1024,180) ##def song(): ## wait() def main(): y = 0 ## song() while y != 2: robot.go(1000) right = robot.sensors([101]) left = robot.sensors([102]) left_bumper = left[101] right_bumper = right[102] if left_bumper == 1 and right_bumper == 1: robot.stop() wait() robot.turn(180,180) wait() y = y+1 elif left_bumper == 1:
def test_look_around(self): r = create.Create(SERIAL_PORT) light.look_around(r) r.shutdown()
import create import serial from time import sleep import sys robot = create.Create("/dev/ttyUSB0") COM = "/dev/ttyUSB1" BAUD = 115200 montior = False ser = serial.Serial(COM, BAUD, timeout=.1) print('Waiting for device') sleep(3) print(ser.name) if ("-m" in sys.argv): monitor = True else: monitor = False # Roomba control input design inspired by: # https://github.com/martinschaef/roomba/blob/master/game.py MAX_FORWARD = 40 # in cm per second MAX_ROTATION = 50 # in cm per second SPEED_INC = 5 # increment in percent # start 50% speed FWD_SPEED = MAX_FORWARD / 8 ROT_SPEED = MAX_ROTATION / 8 # at rest
# by this program was not closed properly. To fix, you'll have to end # your ssh session and sign back in or restart the program and use # the spacebar to quit the program correctly. import os, sys import create import time import curses # Change the roomba port to whatever is on your # machine. On a Mac it's something like this. # On Linux it's usually tty.USB0 and on Win # its to serial port. ROOMBA_PORT = "/dev/ttyUSB0" robot = create.Create(ROOMBA_PORT, BAUD_RATE=115200) robot.toSafeMode() FWD_CMPS = 20 # forward speed in cm per second ROT_CMPS = 60 # rotation speed in cm per second TURN_DELAY = 6.55 / 6 # in seconds 90 degree turns dependent on ROT_CMPS == 60 FWD_DELAY = 34 / FWD_CMPS # roomba's diameter is 34 cm and adjusting based on FWD_CMPS def move_roomba(mult, robot_dir, robot_rot): robot.go(FWD_CMPS * robot_dir * mult, ROT_CMPS * robot_rot * mult) if robot_dir == 0: time.sleep(TURN_DELAY) else: time.sleep(FWD_DELAY) robot.go(0, 0)
# MAIN import numpy as np import create import simplex import gomory import output # Вариант 18 c = np.array([7, 7, 6]) b = np.array([8, 2, 6]) A = np.array([[2, 1, 1], [1, 2, 0], [0, 0.5, 4]]) print("\nИсходная simplex-таблица\n") obj = create.Create(c, b, A) output.show(obj) while (obj.gomory): print("\nПреобразованная simplex-таблица\n") simplex.Simplex(obj) output.show(obj) print("\nВызываем метод Гомори\n") gomory.Gomory(obj) output.show(obj) pass print("\nЦелосчисленное решение") output.result(obj)
import create import pygame, time, sys from pygame.locals import * import CreateRobot as robFuncs import threading as thread robot = create.Create('COM3') robot.toSafeMode() # DriveDirect(robot,-50,50,5) robo_active = True def start_thread(): # print(i) t = thread.Timer(0.5, print_my_name) t.start() def print_my_name(): # with lock: robot.toSafeMode() asen = robFuncs.get_analog_sensor(robot) # dsen = funcs.get_digital_sensor(robot) print(asen, sep='\n') # print(robo_active) # global i global robo_active if robo_active is True: start_thread()
def aimain(): r = create.Create(10) r.toFullMode() print 'to full mode' r.go(30, 0) stopfbump(r) r.go(0, 90) time.sleep(1.05) r.go() #turn 90 degrees left rundist1(r, 800) # Wall to Turn rundist2(r, 7750) #Turn to Rsolyn r.go(-30, 0) time.sleep(4) r.go(0, -90) time.sleep(1.05) r.go() #turn 90 degrees right r.go(0, -90) time.sleep(1.05) r.go() #turn 90 degrees right r.go(30, 0) stopfbump(r) r.go(0, 90) time.sleep(1.05) r.go() #turn 90 degrees left rundist3(r, 7700) #Roslyn to Dr Kaner r.go(0, 90) time.sleep(1.08) r.go() #turn 90 degrees left rundist4(r, 19450) #Dr Kaner to Dr Shoaff r.playSong([(55, 16), (55, 16), (55, 16), (51, 64)]) #Play Tone #function to run create robot till the distance mentioned correcting left and right bump r.go(10, 0) distance = 0 while (distance < limit): door = 0 flag = 0 d = r.sensors() distance += d[create.DISTANCE] left = d[create.LEFT_BUMP] right = d[create.RIGHT_BUMP] wals = d[create.WALL_SIGNAL] if left == 1 and right == 0: r.go(20, -30) elif left == 0 and right == 1: r.go(20, 30) elif left == 1 and right == 1: r.go(-5, 10) time.sleep(2) r.go(20, 5) elif left == 0 and right == 0: if wals >= 59: r.go(30, 15) if wals <= 40: r.go(30, -15) if wals == 0: r.go(20, 0) if wals >= 100: print 'greate than 100' flag = 1 if wals < 100: print 'less than 100' if flag == 1: print 'less than 100 with flag' door += 1 flag = 0 time.sleep(0.015) print door r.go()
def test_kitt(self): r = create.Create(SERIAL_PORT) light.kitt(r) r.shutdown()
machine.parse(value, counter) for counter, value in enumerate(d) ] testData = list(gen(5)) pdb.set_trace() results = transform(transform(testData)) if (False not in [item[0] == item[1] for item in zip(testData, results)]): print("This is a valid cypher") else: print("This is NOT a valid cypher") if (args.subroutine == 'create'): file = create.Create() with open(args.file.name, mode='wb+') as output: pickle.dump(file, output) if (args.subroutine == 'encrypt'): machine = None if (args.codex): with open(args.codex, 'rb') as file: machine = Machine(pickle.load(file)) if (args.random): CYPHER = create.random(create.genPreset(args.random[0]), args.random[1], args.random[2]) machine = Machine(abc=CYPHER[0].getABC()) with open(args.in_file.name, 'rb') as input, open(args.out_file.name,
def handle_request(self, data, sender, socket, client_address): if data.find('GET /setup.xml HTTP/1.1') == 0: dbg("Responding to setup.xml for %s" % self.name) xml = SETUP_XML % { 'device_name': self.name, 'device_serial': self.serial } date_str = email.utils.formatdate(timeval=None, localtime=False, usegmt=True) message = ("HTTP/1.1 200 OK\r\n" "CONTENT-LENGTH: %d\r\n" "CONTENT-TYPE: text/xml\r\n" "DATE: %s\r\n" "LAST-MODIFIED: Sat, 01 Jan 2000 00:01:15 GMT\r\n" "SERVER: Unspecified, UPnP/1.0, Unspecified\r\n" "X-User-Agent: redsonic\r\n" "CONNECTION: close\r\n" "\r\n" "%s" % (len(xml), date_str, xml)) socket.send(message) elif data.find( 'SOAPACTION: "urn:Belkin:service:basicevent:1#SetBinaryState"' ) != -1: success = False if data.find('<BinaryState>1</BinaryState>') != -1: # on dbg("Responding to ON for %s" % self.name) print "echo test123 on!" ### ROOMBA_PORT = "/dev/ttyUSB0" robot = create.Create(ROOMBA_PORT) robot.toSafeMode() robot.play_starwars() robot.close() ser = serial.Serial('/dev/ttyUSB0', 115200) ser.close() time.sleep(0.03) ser.open() ser.write(chr(128)) # 128: start command time.sleep(0.03) ser.write(chr(131)) # 131: safe command time.sleep(0.03) ser.write(chr(135)) # 135: clean command ser.close() ### success = self.action_handler.on(client_address[0], self.name) elif data.find('<BinaryState>0</BinaryState>') != -1: # off dbg("Responding to OFF for %s" % self.name) print "echo test123 off!" ### ser = serial.Serial('/dev/ttyUSB0', 115200) ser.close() ser.open() ser.write(chr(128)) # 128: start command ser.write(chr(131)) # 131: safe command ser.write(chr(133)) # 135: power off command ser.close() ### success = self.action_handler.off(client_address[0], self.name) else: dbg("Unknown Binary State request:") dbg(data) if success: # The echo is happy with the 200 status code and doesn't # appear to care about the SOAP response body soap = "" date_str = email.utils.formatdate(timeval=None, localtime=False, usegmt=True) message = ("HTTP/1.1 200 OK\r\n" "CONTENT-LENGTH: %d\r\n" "CONTENT-TYPE: text/xml charset=\"utf-8\"\r\n" "DATE: %s\r\n" "EXT:\r\n" "SERVER: Unspecified, UPnP/1.0, Unspecified\r\n" "X-User-Agent: redsonic\r\n" "CONNECTION: close\r\n" "\r\n" "%s" % (len(soap), date_str, soap)) socket.send(message) else: dbg(data)