def __init__(self, sprite_params): wt = sprite_params.wheel_thickness st = sprite_params.sensor_thickness r = sprite_params.wheel_radius d = sprite_params.wheels_distance o = sprite_params.sensor_offset sw = sprite_params.array_width self.body = DrawingUtils.rectangle_to_polygon((-r, -d / 2.0 + wt / 2.0, r + o, d - wt)) self.right_wheel = DrawingUtils.rectangle_to_polygon((-r, -d / 2.0 - wt / 2.0, 2 * r, wt)) self.left_wheel = DrawingUtils.rectangle_to_polygon((-r, d / 2.0 - wt / 2.0, 2 * r, wt)) self.line_sensor = DrawingUtils.rectangle_to_polygon((o - st / 2.0, -sw / 2.0, st, sw)) self.wheel_color = (0, 0, 0) self.robot_color = (153, 153, 0)
def draw(self, window): """ Draws the simulation (line follower robot and track). :param window: pygame's window where the drawing will occur. :type window: pygame's window. """ self.track.draw(window) if len(self.point_list) >= 2: pygame.draw.lines(window, (255, 0, 0), False, self.point_list, 4) self.sprite.draw(window, self.line_follower.pose) sensor_positions = self.line_follower.get_sensors_global_positions() for sensor_position in sensor_positions: DrawingUtils.draw_circle_on_screen(window, (sensor_position.x, sensor_position.y), 0.01, (255, 0, 0), 0)
def draw(self, window): """ Draws the track. :param window: pygame's window where the drawing will occur. :type window: pygame's window. """ for piece in self.pieces: if isinstance(piece, LineSegment): DrawingUtils.draw_line_on_screen(window, piece.start.to_tuple(), piece.end.to_tuple(), (0, 0, 0), 2) elif isinstance(piece, Arc): DrawingUtils.draw_arc_on_screen(window, piece.center.to_tuple(), piece.radius, piece.start_angle, piece.stop_angle, (0, 0, 0), 2)
def draw(self, window, pose): """ Draws the robot sprite on the screen. :param window: pygame's window where the drawing will occur. :type window: pygame's window. :param pose: current pose of the robot. :type pose: Pose. """ DrawingUtils.draw_polygon_on_screen(window, RobotSprite.transform(pose, self.left_wheel), self.wheel_color, 0) DrawingUtils.draw_polygon_on_screen(window, RobotSprite.transform(pose, self.right_wheel), self.wheel_color, 0) DrawingUtils.draw_polygon_on_screen(window, RobotSprite.transform(pose, self.body), self.robot_color, 0) DrawingUtils.draw_polygon_on_screen(window, RobotSprite.transform(pose, self.line_sensor), self.robot_color, 0)