def make_data(N, num_landmarks, world_size, measurement_range, motion_noise, measurement_noise, distance): # check if data has been made complete = False while not complete: data = [] # make robot and landmarks r = Robot(world_size, measurement_range, motion_noise, measurement_noise) r.make_landmarks(num_landmarks) seen = [False for row in range(num_landmarks)] # guess an initial motion orientation = random.random() * 2.0 * pi dx = cos(orientation) * distance dy = sin(orientation) * distance for k in range(N - 1): # collect sensor measurements in a list, Z Z = r.sense() # check off all landmarks that were observed for i in range(len(Z)): seen[Z[i][0]] = True # move while not r.move(dx, dy): # if we'd be leaving the robot world, pick instead a new direction orientation = random.random() * 2.0 * pi dx = cos(orientation) * distance dy = sin(orientation) * distance # collect/memorize all sensor and motion data data.append([Z, [dx, dy]]) # we are done when all landmarks were observed; otherwise re-run complete = (sum(seen) == num_landmarks) print(' ') print('Landmarks: ', r.landmarks) print(r) return data
def test_sense(): world_size = 10.0 # size of world (square) measurement_range = 5.0 # range at which we can sense landmarks motion_noise = 0.2 # noise in robot motion measurement_noise = 0.2 # noise in the measurements # instantiate a robot, r rob = Robot(world_size, measurement_range, motion_noise, measurement_noise) num_landmarks = 3 rob.make_landmarks(num_landmarks) # print out our robot's exact location print(rob) # display the world including these landmarks display_world(int(world_size), [rob.x, rob.y], rob.landmarks) # print the locations of the landmarks print('Landmark locations [x,y]: ', rob.landmarks) measurements = rob.sense() assert len(measurements) == 3, "rob did not sense all 3 landmarks" print(measurements)