Skip to content

Instantly share code, notes, and snippets.

@Noob-can-Compile
Created March 31, 2020 12:30
Show Gist options
  • Save Noob-can-Compile/f94f520619def1040d8ff4ab15e26ce8 to your computer and use it in GitHub Desktop.
Save Noob-can-Compile/f94f520619def1040d8ff4ab15e26ce8 to your computer and use it in GitHub Desktop.
class robot:
#move function
def move(self, dx, dy):
x = self.x + dx + self.rand() * self.motion_noise
y = self.y + dy + self.rand() * self.motion_noise
if x < 0.0 or x > self.world_size or y < 0.0 or y > self.world_size:
return False
else:
self.x = x
self.y = y
return True
#sense function
def sense(self):
measurements = []
for landmark_index, landmark in enumerate(self.landmarks):
landmark_distance_x = landmark[0]
landmark_distance_y = landmark[1]
random_noise = self.rand()
cal_dx = self.x - landmark_distance_x + random_noise * self.measurement_noise
cal_dy = self.y - landmark_distance_y + random_noise * self.measurement_noise
is_not_in_measurement_range = self.measurement_range == -1
if(is_not_in_measurement_range) or ((abs(cal_dx) <= self.measurement_range) and (abs(cal_dy) <= self.measurement_range)):
measurements.append([landmark_index, cal_dx, cal_dy])
return measurements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment