from math import * import random landmarks = [[0.0, 100.0], [0.0, 0.0], [100.0, 0.0],[100.0, 100.0]] world_size = 100.0 max_steering_angle = pi/4 class robot: def __init__(self, length = 100.0): self.x = random.random() * world_size self.y = random.random() * world_size self.orientation = random.random() * 2.0 * pi self.length = length self.bearing_noise = 0.0 self.steering_noise = 0.0 self.distance_noise = 0.0 def __repr__(self): return '[x=%.6s y=%.6s orient=%.6s]' % (str(self.x), str(self.y), str(self.orientation)) def set(self, new_x, new_y, new_orientation): if new_orientation < 0 or new_orientation >= 2 * pi: raise ValueError, 'Orientation must be in [0..2pi]' self.x = float(new_x) self.y = float(new_y) self.orientation = float(new_orientation) def set_noise(self, new_b_noise, new_s_noise, new_d_noise): self.bearing_noise = float(new_b_noise) self.steering_noise = float(new_s_noise) self.distance_noise = float(new_d_noise) def move(self, motion, tolerance = 0.001): steering = motion[0] distance = motion[1] if abs(steering) > max_steering_angle: raise ValueError, 'Exceeding max steering angle' if distance < 0.0: raise ValueError, 'Moving backwards is not valid' return result