def get_actual(guess): """ Returns the object the human player was thinking of """ global _objects yn = interface.ask("My guess is %s. Was I right? " % guess.name) if yn == "yes": obj_name = guess.name obj_id = guess.id else: if robot(): obj_name = robot().ask_object() else: print "\nObject names:\n" for j in range(len(_objects)): print _objects[j].name obj_name = raw_input("\nWhat was your object? Remember to type it exactly as you saw above. ") while True: check = False for i in range(len(_objects)): if _objects[i].name == obj_name: check = True obj_id = _objects[i].id break if check == True: break obj_name = raw_input("It seems as though you mistyped. Please try typing the name of your object again. ") return obj_id, obj_name
def simulate_with_hunter(self, next_move, params): """Run simulation to locate lost bot and catch with hunter. Args: next_move(func): Student submission function for hunters next move. params(dict): Test parameters. Raises: Exception if error running submission. """ self._reset() target = robot.robot(params['target_x'], params['target_y'], params['target_heading'], 2.0 * PI / params['target_period'], params['target_speed']) target.set_noise(0.0, 0.0, params['noise_ratio'] * params['target_speed']) hunter = robot.robot(params['hunter_x'], params['hunter_y'], params['hunter_heading']) tolerance = params['tolerance_ratio'] * target.distance max_speed = params['speed_ratio'] * params['target_speed'] other_info = None steps = 0 random.seed(GLOBAL_SEEDS[params['part']]) try: while steps < params['max_steps']: hunter_pos = (hunter.x, hunter.y) target_pos = (target.x, target.y) separation = self.distance(hunter_pos, target_pos) if separation < tolerance: self.robot_found.put(True) self.robot_steps.put(steps) return target_meas = target.sense() turn, dist, other_info = next_move(hunter_pos, hunter.heading, target_meas, max_speed, other_info) dist = min(dist, max_speed) dist = max(dist, 0) turn = self.truncate_angle(turn) hunter.move(turn, dist) target.move_in_circle() steps += 1 self.robot_found.put(False) self.robot_steps.put(steps) except Exception as exp: self.robot_error.put(exp.message)
def __init__(self): self.data_dict = None self.psm1 = robot.robot("PSM1") self.psm2 = robot.robot("PSM2") self.tissue_pose = None self.tissue_length = None self.tissue_width = None self.probe_offset = 0.030 #32 gives interesting readings? og 0.038 # probe offset and pitch and speed should automatically be in filename self.probe_data = [] self.probe_data_desired_pose = [] self.record_data = False self.speed = 0.02 self.curr_probe_value = None self.insert_probe_angle = 10 self.lock_probe_angle = 36 self.record_point_palpation_data = False self.locations = [] self.baseline = float("-inf") self.num_points = 0 self.cooldown = 0 # subscribe to probe data rospy.Subscriber("/probe/measurement", Float64, self.probe_callback) rospy.Subscriber("/gaussian_process/pts_to_probe", Points, self.probe_points_scan_callback) self.measurements_pub = rospy.Publisher("/palpation/measurements", FloatList)
def get_actual(guess): """ Returns the object the human player was thinking of """ global _objects answer = interface.ask("My guess is %s. Was I right? " % guess.name) if answer: obj_name = guess.name obj_id = guess.id else: if robot(): obj_name = robot().ask_object() else: print "\nObject names:\n" for j in range(len(_objects)): print _objects[j].name obj_name = raw_input("\nWhat was your object? Remember to type it exactly as you saw above. ") while True: check = False for i in range(len(_objects)): if _objects[i].name == obj_name: check = True obj_id = _objects[i].id break if check == True: break obj_name = raw_input("It seems as though you mistyped. Please try typing the name of your object again. ") return obj_id, obj_name
def ask(question): if robot(): return robot().ask(question) else: while True: response = raw_input(question).lower()[0] if response == "y": return "yes" elif response == "n": return "no"
def ask(question): if robot(): return robot().ask(question) else: while True: response = raw_input(question).lower()[0] if response == "y": return True elif response == "n": return False
def simulate_without_hunter(params): estimate_next_pos = params['student_method'] target = robot.robot(params['target_x'], params['target_y'], params['target_heading'], 2.0 * PI / params['target_period'], params['target_speed']) target.set_noise(0.0, 0.0, params['noise_ratio'] * params['target_speed']) tolerance = params['tolerance_ratio'] * target.distance other_info = None steps = 0 random.seed(GLOBAL_SEEDS[params['part']]) while steps < params['max_steps']: target_pos = (target.x, target.y) target_meas = target.sense() estimate, other_info = estimate_next_pos(target_meas, other_info) target.move_in_circle() target_pos = (target.x, target.y) separation = distance(estimate, target_pos) if separation < tolerance: return True, steps steps += 1 return False, steps
def setUpClass(cls): cls.motor_names = [ 'Omnirob_FLwheel_motor', 'Omnirob_FRwheel_motor', 'Omnirob_RRwheel_motor', 'Omnirob_RLwheel_motor' ] cls.r = robot('Omnirob', cls.motor_names) # Create an instance of our robot
def Interpolate(robotname): r = robot.robot(robotname) # Open and close gripper print("Starting gripper opening and closing") r.open_gripper(80) time.sleep(0.1) r.close_gripper() # Using move_cartesian_linear_interpolate # Move to a different cartesian and rotation pose start_pose = r.get_current_cartesian_position() pose1 = r.get_current_cartesian_position() pose1.position.y -= 0.03 end_pose = tfx.pose(pose1.as_tf()*tfx.transform(tfx.rotation_tb(30, -60, 30))) print("Starting move_cartesian_frame_linear_interpolation") r.move_cartesian_frame_linear_interpolation(start_pose, 0.01) time.sleep(2) r.move_cartesian_frame_linear_interpolation(end_pose, 0.01) time.sleep(2) r.move_cartesian_frame_linear_interpolation(start_pose, 0.01) # Using move_cartesian_frame print("Starting move_cartesian_frame") r.move_cartesian_frame(start_pose, interpolate=True) time.sleep(2) r.move_cartesian_frame(end_pose, interpolate=True) time.sleep(2) r.move_cartesian_frame(start_pose, interpolate=True) print start_pose print end_pose
def run(params, printflag = False): myrobot = robot() myrobot.set(0.0, 1.0, 0.0) speed = 1.0 err = 0.0 int_crosstrack_error = 0.0 N = 100 # myrobot.set_noise(0.1, 0.0) myrobot.set_steering_drift(10.0 / 180.0 * pi) # 10 degree steering error crosstrack_error = myrobot.y for i in range(N * 2): diff_crosstrack_error = myrobot.y - crosstrack_error crosstrack_error = myrobot.y int_crosstrack_error += crosstrack_error steer = - params[0] * crosstrack_error \ - params[1] * diff_crosstrack_error \ - int_crosstrack_error * params[2] myrobot = myrobot.move(steer, speed) if i >= N: err += (crosstrack_error ** 2) if printflag: print myrobot, steer return err / float(N)
def __init__(self): self.xid = self.getBovoId() # init window self.win = gdk.window_foreign_new(self.xid) if self.win==None: print 'can not find window:',self.xid return self.win.set_keep_above(True) # keep the window always above sz = self.win.get_size() self.width = sz[0]-110-9 self.height = sz[1]-80-8 print "screenshot shape: ",(self.width,self.height) if self.width > 300 or self.height>300: print "WARN: the screenshot is too large, may take too much time in anlysis the pictures" if self.height!=222: print "ERROR: not correct window height, please keep minimizing the Bovo's window" return (self.win_x, self.win_y) = self.win.get_root_origin() # print "window locate at",(self.win_x, self.win_y) # for ubuntu14.10 result is (65, 52) # init Pixbuf to store the colormap of bovo chessboard self.pbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, self.width, self.height) self.pixnum = self.pbuf.get_pixels_array() # set the bufffer queue of chessboards self.queuelen = 2; self.chessboards = np.zeros((self.queuelen, 22,22)) self.chbptr = 0 # chessboard pointer 0 or 1 # init mouse device self.mouse = mouse.mouse() # init robot self.rob = robot.robot(mode = robot.ROBOT_LEARNING)
def playObject(self, game, Pi, number_of_objects): """ Play this object """ log.info('Playing object %d in game %d', self.id, game.id) objects = self.gen_init_prob(number_of_objects) folder = os.getcwd() answer_data = get_all_answers(number_of_objects) NoOfQuestions = 0 # at the very beginning of a round, each object has an equal chance of getting picked pO = np.array([1/float(number_of_objects)] * number_of_objects) askedQuestions = [] answers = [] split = 0 difference_threshold = 0.15 # while the best guess is less than 15% probability away from the 2nd-best guess and we've asked fewer than 15 questions while np.sort(pO)[pO.size - 1] - np.sort(pO)[pO.size - 2] < difference_threshold and len(askedQuestions) < 15: # Find best question (aka gives most info) best_question = questions.get_best(game, objects, askedQuestions, pO, Pi, split, number_of_objects) # Save under questions already asked askedQuestions.append(best_question) # Ask question and update probabilies based on the answer pO, answers = questions.ask(best_question, self, game, answers, pO, Pi, objects, number_of_objects, answer_data) if config.args.gaze: gaze_confidences = robot().gazeConfidences() gaze_weight = 0.7 print "pO:", for p in pO: print round(p, 2) * 100, ' ', print pO = np.array([(question_prob * (1 - gaze_weight)) + (question_prob * gaze_prob * gaze_weight) for question_prob, gaze_prob in zip(pO, gaze_confidences)]) print "Gp:", for p in pO: print round(p, 2) * 100, ' ', print # Split the current subset into two more subsets split = questions.get_subset_split(pO, number_of_objects) log.info('Finished asking %d questions', len(askedQuestions)) # Get most likely object minimum=np.max(pO) itemindexes = [i for i,x in enumerate(pO) if x==minimum] objects = np.asarray([[obj] for obj in get_all()]) guess = objects[itemindexes][0][0] # Guess object (Compare what the system thinks is most likely to object currenly in play) result = self._guess_object(guess) # Save results self._record_results(game, answers, askedQuestions, guess, result, number_of_objects) return result, len(askedQuestions), answers, askedQuestions
def main(): ''' Server ''' print('Initiating Warehouse Server...') while True: try: host = input('Enter server address: ') port = input('Enter port nr: ') if host is '': host = DEFAULT_IP if port is '': port = DEFAULT_PORT port = int(port) break except ValueError('Value error: setting default'): pass #socket config sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((host, port)) print('Server IP: ', host) print('Server port: ', port) print('Connecting to robots') robots = [] with open("robot.conf") as file: for line in file: robot_adr, server_adr, bluetooth_port = line.split(",") robots.append( robot.robot(robot_adr, int(bluetooth_port), server_adr, int(bluetooth_port))) listen_for_incoming_connections(sock, robots)
def __init__(self): self.str_res = json.load( open(os.path.join("string_res", "cz.json"), "r", encoding="utf-8")) self.main = tk.Tk() self.main.title(self.str_res["window_title"]) self.main.iconbitmap(os.path.join("img", "karel.ico")) menubar = tk.Menu(self.main) menubar.add_command(label=self.str_res["menu_choose_level"], command=self.choose_level) self.main.config(menu=menubar) self.edit_code = tk.Text(self.main, width=50) self.canvas = tk.Canvas(self.main, background="white") self.canvas.grid(row=0, column=3, rowspan=2) self.karel = robot(self) # self.choose_level() self.load(os.path.abspath("levels/basic.map")) self.edit_code.grid(row=0, column=0, columnspan=3) self.edit_code.insert("end", self.str_res["edit_code_messagge"]) self.run_button = tk.Button(self.main, text=self.str_res["run_button_label"], command=self.run) self.run_button.grid(row=1, column=1, sticky="we") self.comp = Compiler(self.karel, self.main) self.reset_button = tk.Button(self.main, text=self.str_res["reset_button_label"], command=self.karel.reset_place) self.reset_button.grid(row=1, column=0, sticky="we") self.stop_button = tk.Button(self.main, text=self.str_res["stop_button_label"], command=self.comp.stop) self.stop_button.grid(row=1, column=2, sticky="we")
def test_go_to_4_4_NORTH(self): commands = [ 'PLACE 4,4,NORTH' ] output_table = get_clear_table() output_table[4][4] = 'NORTH' self.assertEqual(robot(commands), output_table)
def test(self): data_list = [] dic_position_start = set() dic_position_end = set() start_pos = (1, 1) end_pos = (29, 29) for i in range(self.no_of_robots): while (start_pos in dic_position_start): start_pos = (random.randint(2, ARENA_DIM - 2), random.randint(2, ARENA_DIM - 2)) while (end_pos in dic_position_end): end_pos = (random.randint(2, ARENA_DIM - 2), random.randint(2, ARENA_DIM - 2)) data_list.append(robot(start_pos, 0, end_pos, 0)) dic_position_start.add(start_pos) dic_position_end.add(end_pos) Test(data_list, self) try: assert (self.no_of_collisions <= 1) assert (self.unstable_destinations <= 1) assert (self.out_of_the_board <= 1) self.passed = True except AssertionError: self.passed = False
def piSetUp(): GPIO.setmode(GPIO.BOARD) TIC1 = TIC() TIC1.TICstart() motorL = motor("left", [32, 31, 33]) encoderA = encoder("left", [26, 29], 50, motorL) motorR = motor("right", [35, 36, 37]) encoderB = encoder("left", [38, 40], 50, motorR) proxSensA= psensor("Front",[16,18], 50) proxSensB= psensor("Left",[12,22], 35) proxSensC= psensor("Right",[7,13], 35) rob = robot(motorL, motorR, encoderA, encoderB, proxSensA, proxSensB, proxSensC) rob.pinSetup() tnow = time.time() rob.obsDetect() while(1): rob.run() TIC1.run()
def test_go_to_4_4(self): commands = [ 'PLACE 0,0,NORTH', 'MOVE', 'MOVE', 'MOVE', 'MOVE', 'MOVE', 'RIGHT', 'MOVE', 'MOVE', 'MOVE', 'MOVE' ] output_table = get_clear_table() # output_table[0][0] = 'NORTH' # output_table[0][1] = 'NORTH' move1 # output_table[0][2] = 'NORTH' move2 # output_table[0][3] = 'NORTH' move3 # output_table[0][4] = 'NORTH' # move4 stops on y = 4 # output_table[0][5] = 'NORTH' move5 IGNORED # output_table[0][4] = 'EAST' # output_table[1][4] = 'EAST' move1 # output_table[2][4] = 'EAST' move2 # output_table[3][4] = 'EAST' move3 output_table[4][4] = 'EAST'# move4 self.assertEqual(robot(commands), output_table)
def __init__(self): self.radio = radio.radio([0xa7, 0xa7, 0xa7, 0xa7, 0xaa]) self.swarm = [ #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x01]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x02]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x03]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x04]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x05]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x06]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x07]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x08]), robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x09]) ] self.bpm = 150 self.beat = 0 self.beats_per_cycle = 1 self.ms_per_beat = self.bpm_to_mspb(self.bpm) self.last_sync = time.time() self.weft_swarm = [0, 1, 2, 3] self.warp_swarm = [4, 5, 6, 7] self.state = "weft-walking" self.compiler = yarn.compiler() self.osc_server = OSCServer(("0.0.0.0", 8000)) self.osc_server.timeout = 0 self.osc_server.addMsgHandler("/sync", sync_callback) self.sync_pos = 0 # load code here self.swarm[0].load_asm("../asm/led_flash.asm", self.compiler, self.radio)
def populate(): for x in range(constants.NUM_BOTS): bot = robot.robot() bot_list.append(bot) bot_list[0].set_state(flag.GREEN) bot_list[1].set_state(flag.RED)
def simulate_with_hunter(params): next_move = params['student_method'] target = robot.robot(params['target_x'], params['target_y'], params['target_heading'], 2.0 * PI / params['target_period'], params['target_speed'], params['target_line_length']) target.set_noise(0.0, 0.0, params['noise_ratio'] * params['target_speed']) hunter = robot.robot(params['hunter_x'], params['hunter_y'], params['hunter_heading']) tolerance = params['tolerance_ratio'] * target.distance max_speed = params['speed_ratio'] * params['target_speed'] other_info = None steps = 0 random.seed(GLOBAL_SEEDS[params['part']]) while steps < params['max_steps']: hunter_pos = (hunter.x, hunter.y) target_pos = (target.x, target.y) separation = distance(hunter_pos, target_pos) if separation < tolerance: return True, steps target_meas = target.sense() turn, dist, other_info = next_move(hunter_pos, hunter.heading, target_meas, max_speed, other_info) dist = min(dist, max_speed) dist = max(dist, 0) turn = truncate_angle(turn) hunter.move(turn, dist) target.move_in_polygon() steps += 1 return False, steps
def guess(self): print "Object confidences:", [[round(angle, 3), round(self.confidences[angle] * 100)] for angle in self.confidences] max_confidence = max(self.confidences.values()) # or set this to some threshold # tilt head slightly down so it appears we're looking at the objects robot().turnHead(pitch = math.radians(15)) for object_angle, confidence in self.confidences.iteritems(): # if we're most confident about that object if confidence == max_confidence: print "Are you thinking of the object at", object_angle, "radians?" print "I'm", round(confidence * 100), "% confident about this." robot().turnHead(yaw = object_angle) time.sleep(3)
def test_rotate_WEST_RIGHT(self): commands = [ 'PLACE 0,0,WEST', 'RIGHT' ] output_table = get_clear_table() output_table[0][0] = 'NORTH' self.assertEqual(robot(commands), output_table)
def test_rotate_EAST_LEFT(self): commands = [ 'PLACE 0,0,EAST', 'LEFT' ] output_table = get_clear_table() output_table[0][0] = 'NORTH' self.assertEqual(robot(commands), output_table)
def __init__(self): # read object angles from file object_yaws = [] object_pitches = [] object_angle_file = open("object_angles.txt") for object_angle in object_angle_file: yaw, pitch = object_angle.split(', ') object_yaws.append(float(yaw)) object_pitches.append(float(pitch)) self.confidences = dict.fromkeys(object_yaws, 0) self.angle_error = math.radians(15) # start writing gaze data to robot memory robot().subscribeGaze()
def test_MOVE_WEST(self): commands = [ 'PLACE 0,0,WEST', 'MOVE' ] output_table = get_clear_table() output_table[0][0] = 'WEST' #output_table[-1][0] = 'WEST' FALL self.assertEqual(robot(commands), output_table)
def test_MOVE_NORTH(self): commands = [ 'PLACE 0,0,NORTH', 'MOVE' ] output_table = get_clear_table() output_table[0][0] = '' output_table[0][1] = 'NORTH' self.assertEqual(robot(commands), output_table)
def test_MOVE_EAST(self): commands = [ 'PLACE 0,0,EAST', 'MOVE' ] output_table = get_clear_table() output_table[0][0] = '' output_table[1][0] = 'EAST' self.assertEqual(robot(commands), output_table)
def test_MOVE_SOUTH(self): commands = [ 'PLACE 0,0,SOUTH', 'MOVE' ] output_table = get_clear_table() output_table[0][0] = 'SOUTH' #output_table[0][-1] = 'SOUTH' FALL self.assertEqual(robot(commands), output_table)
def generate_path(L, start, motions): rob = robot(L) rob.set_coordinate(*start) rob.set_noise() Z = [] for motion in motions: rob.move(*motion) Z.append(rob.sense()) return rob, Z
def findPersonPitchAdjustment(self, person_name = "Person", style = "normal"): """ Stores the adjustment needed to be made to measured gaze pitch values, which it calculates based on the difference between 90 deg and an average measurement of the person's gaze when looking at the robot's eyes. Robot speaks to get straight-on gaze to measure, then filters measurements with personLookingAtRobot(). """ self.pitch_sum = 0 self.pitch_count = 0 self.updatePersonID() eye_contact = False time.sleep(3) robot().colorEyes("blue") # repeatedly try get person's attention until they reply robot().say("Hey " + person_name + "?", block = False) self.updateRawPersonGaze() while not self.personLookingAtRobot(): self.updateRawPersonGaze() time.sleep(0.2) self.pitchSumOverTime(1) # finish talking and add to pitch sum while talking robot().say("Are you ready to play?", block = False) self.pitchSumOverTime(1) robot().colorEyes("purple") control_pitch = self.pitch_sum / self.pitch_count # the pitch adjustment we need to make is the difference between (the measured value at 90 degrees) and (90 degrees) self.person_pitch_adjustment = control_pitch - math.radians(90) print "person_pitch_adjustment:", self.person_pitch_adjustment # finish talking time.sleep(2) robot().say("Okay, let's play!")
def __init__(self, L, start, N=100): assert N > 0 self.N = N x, y, orient = start self.robs = [] for i in range(N): r = robot(L) r.set_coordinate(x, y, orient) r.set_noise() self.robs.append(r)
def create_our_bots(self, n): for i in range(n): x = np.random.uniform(field.leftx, field.rightx) y = np.random.uniform(field.boty, field.topy) vel = np.random.uniform(0, 10) circle = Circle([x, y], 0.3, fc="purple", alpha=0.7) bot = robot(x, y, vel, circle) self.robots.append(bot) self.our_bots.append(bot)
def main(): w = world() r = robot() moves = [[45, 2], [-45, -1]] for i in range(2): r.move(w, moves[i][0], moves[i][1]) pf = particleFilter(w, r) p = pf.initParticles(10) p = pf.localize(p, 10)
def main(): Robot=robot('irb120') Robot.BuildKineModules() #jts=[30,0,0,0,10+time.time()-t0,0] #a=Robot.GetEffectorPosition(jts) #print(a) #print(t.SetEffectorPosition(a[0,0:6])) act=rosact() act.write(Robot) print('this shouldnt be displayed')
def create_their_bots(self, n): for i in range(n): x = np.random.uniform(field.leftx, field.rightx) y = np.random.uniform(field.boty, field.topy) vel = np.random.uniform(0, 10) circle = Circle([x, y], 0.3, fc="aqua") bot = robot(x, y, vel, circle) self.robots.append(bot) self.their_bots.append(bot)
def __init__( self, L, start, N=100): assert N>0 self.N = N x,y,orient = start self.robs = [] for i in range(N): r = robot(L) r.set_coordinate(x, y, orient) r.set_noise() self.robs.append(r)
def userInput(): myLoc = np.array([0, 0, 0]) r = robot(myLoc) while True: x = float(input("Enter a x coordinate (in cm): ")) y = float(input("Enter a y coordinate (in cm): ")) dest = np.array([x, y, 0]) myLoc = navigateToWaypoint(myLoc, dest) print(myLoc)
def __init__(self,address,handler, camProperty): HTTPServer.__init__(self,address,handler) self.run = False self.timeout = 1 #XXX sec timeout self.socket.settimeout(1) self.capture = None self.font = None self.camNum, self.camMode, self.camFps, self.camQlt = camProperty #robot #self.robot = robot(0, 0x04) self.robot = robot(1,0)
def updatePersonID(self, debug = False): """ Tries to get people IDs, then if none are retrieved, tries again every 0.5 seconds until it gets some. Stores the first person ID in the list as self.person_id. """ # try to get list of IDs of people looking at robot people_ids = robot().getPeopleIDs() # if robot hasn't gotten any people IDs while people_ids is None: # wait a little bit, then try again time.sleep(0.5) people_ids = robot().getPeopleIDs() if debug: print "Done! About to save the first of these people IDs:", people_ids self.person_id = people_ids[0]
def test_sequence_of_3_commands(self): commands = [ 'PLACE 0,0,NORTH', 'MOVE', 'MOVE' ] output_table = get_clear_table() # output_table[0][0] = 'NORTH' # output_table[0][1] = 'NORTH' output_table[0][2] = 'NORTH' self.assertEqual(robot(commands), output_table)
def test_sequence_PLACE_LEFT_MOVE(self): commands = [ 'PLACE 0,0,NORTH', 'LEFT', 'MOVE' ] output_table = get_clear_table() # output_table[0][0] = 'NORTH' # output_table[0][0] = 'WEST' output_table[0][0] = 'WEST' #can't do MOVE it self.assertEqual(robot(commands), output_table)
def test_PLACE_0_0_SOUTH(self): commands = [ 'PLACE 0,0,SOUTH' ] output_table = [ ['SOUTH','','','',''], ['','','','',''], ['','','','',''], ['','','','',''], ['','','','',''], ] self.assertEqual(robot(commands), output_table)
def test_PLACE_0_0_NABOO(self): commands = [ 'PLACE 0,0,NABOO' ] output_table = [ ['','','','',''], ['','','','',''], ['','','','',''], ['','','','',''], ['','','','',''], ] self.assertEqual(robot(commands), output_table)
def run(param): myrobot = robot() myrobot.set(0.0, 1.0, 0.0) speed = 1.0 # motion distance is equal to speed (we assume time = 1) N = 100 setpoint = 0.0 for _ in range(N): P = (myrobot.y - setpoint) steer = -param * P myrobot = myrobot.move(steer, speed) print myrobot, steer
def addRobot(self): rCol = 'r%d' % self.numRobots rParams = {'base': self.parameters.base, 'DH': self.parameters.DH, 'ID': self.numRobots} self.robots.append(rb.robot(rCol, self.NrkSDK, self.parameters.param('robotType').value(), *self.parameters.pose, **rParams)) self.robotIDs.append(self.numRobots) with self.parameters.treeChangeBlocker(): self.activeRobot = self.numRobots self.parameters.removeChild(self.parameters.param('activeRobot')) child = {'name': 'activeRobot', 'type': 'list', 'values': self.robotIDs, 'value': self.activeRobot} self.parameters.addChild(child) #self.parameters.param('activeRobot').setLimits(self.robotIDs) self.numRobots = len(self.robots) self.parameters.param('numRobots').setValue(self.numRobots)
def test_initial_command_wrong_then_PLACE(self): commands = [ 'LEFT', 'PLACE 0,0,NORTH' ] output_table = [ ['NORTH','','','',''], ['','','','',''], ['','','','',''], ['','','','',''], ['','','','',''], ] self.assertEqual(robot(commands), output_table)
def updateRawPersonGaze(self): """ Stores person's gaze as a list of yaw (left -, right +) and pitch (up pi, down 0) in radians, respectively. Bases gaze on both eye and head angles. Does not compensate for variable robot head position. """ self.raw_person_gaze = robot().getRawPersonGaze(self.person_id) if self.raw_person_gaze is None: self.updatePersonID() else: self.raw_person_gaze_yaw, self.raw_person_gaze_pitch = self.raw_person_gaze
def updatePersonLocation(self): """ Stores person's head location as a list of x, y (right of robot -, left of robot +), and z coordinates in meters relative to spot between robot's feet. """ self.person_location = robot().getPersonLocation(self.person_id) if self.person_location is None: self.updatePersonID() else: self.robot_person_x, self.robot_person_y, self.robot_person_z = self.person_location
def __init__(self): self.radio = radio.radio([0xa7, 0xa7, 0xa7, 0xa7, 0xaa]) self.swarm = [ #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x01]), robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x02]), robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x03]), robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x04]), robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x05]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x06]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x07]), #robot.robot([0xa7, 0xa7, 0xa7, 0xa7, 0x08]) ] self.bpm = 150 self.beat = 0 self.beats_per_cycle = 1 self.ms_per_beat = self.bpm_to_mspb(self.bpm) self.last_sync = time.time() self.last = "" self.compiler = yarn.compiler() self.osc_server = OSCServer(("0.0.0.0", 8000)) self.osc_server.timeout = 0 self.osc_server.addMsgHandler("/sync", sync_callback) self.sync_pos = 0 self.ms_per_step = (frequency * len(i2c_addrs)) * 1000 self.ms_per_step /= 8 print(self.ms_per_step) # load code here #for r in self.swarm: # r.load_asm("../asm/pm.asm",self.compiler,self.radio) # r.write(13,self.ms_per_step,self.radio) self.grid = tangible.sensor_grid(16, layout, tokens) self.last = "" self.next_address = 0 self.seq = 0
def simulate_without_hunter(self, estimate_next_pos, params): """Run simulation only to locate lost bot. Args: estimate_next_pos(func): Student submission function to estimate next robot position. params(dict): Test parameters. Raises: Exception if error running submission. """ self._reset() target = robot.robot(params['target_x'], params['target_y'], params['target_heading'], 2.0 * PI / params['target_period'], params['target_speed']) target.set_noise(0.0, 0.0, params['noise_ratio'] * params['target_speed']) tolerance = params['tolerance_ratio'] * target.distance other_info = None steps = 0 random.seed(GLOBAL_SEEDS[params['part']]) try: while steps < params['max_steps']: target_meas = target.sense() estimate, other_info = estimate_next_pos(target_meas, other_info) target.move_in_circle() target_pos = (target.x, target.y) separation = self.distance(estimate, target_pos) if separation < tolerance: self.robot_found.put(True) self.robot_steps.put(steps) return steps += 1 self.robot_found.put(False) self.robot_steps.put(steps) except Exception as exp: self.robot_error.put(exp.message)
def initialize(): global robots_data destX = set() destY = set() for i in range(BOT_COUNT): robots_data.append( robot( (random.randint(5, ARENA_DIM-5 ),random.randint(5, ARENA_DIM-5 )), #TODO the corner bug should be resolved at the client 0, (random.randint(5, ARENA_DIM-5 ),random.randint(5, ARENA_DIM-5 )), 0 ) ) arrageBot(robots_data, [])
def add_robot(self, robot): ''' Метод принимает ссылку на объект robot ''' trobo = robot(self.field) #~ print self.robots if not self.robots: print 'ok' trobo.set_position(6,6) # стартовая координата робота, заменить на функцию else: x,y = self.robots[-1].position trobo.set_position(x+20,y+20) self.robots.append(trobo) print self.robots[0].position
def test_sequence_of_MOVEs(self): commands = [ 'PLACE 0,0,NORTH', 'MOVE', 'MOVE', 'MOVE', 'MOVE', 'MOVE' ] output_table = get_clear_table() # output_table[0][0] = 'NORTH' # output_table[0][1] = 'NORTH' move1 # output_table[0][2] = 'NORTH' move2 # output_table[0][3] = 'NORTH' move3 output_table[0][4] = 'NORTH' # move4 stops on y = 4 # output_table[0][5] = 'NORTH' move5 self.assertEqual(robot(commands), output_table)
def insert(self, n, t, i, p): """ Insert item to the db. """ self.open() # add the real object to the database o = None if t == self.TREASURES: o = Treasure() if t == self.LANDMARKS: o = Landmark() if t == self.ROBOTS: o = robot() # insert the query into the db self.cursor.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?)", (n, t, i, p, str(o))) self.connection.commit() self.close()
def navigateThroughWaypoints(wpts): # myLoc = wpts[0] canvas = Canvas() r = robot(wpts, canvas) startingLoc = r.getStartingLocation() n_wpts = len(wpts) for wp in wpts: canvas.drawWaypoint(wp) for i in range(n_wpts): myLoc = r.navigateToWaypoint(wpts[(i + 1 + startingLoc) % n_wpts]) # myLoc = r.navigateToWaypoint_rt(wpts[(i + 1 + startingLoc) % n_wpts]) print("At location: {0}".format(myLoc)) time.sleep(1) print '\a'