Permalink
Browse files

Added seed parameter

  • Loading branch information...
kudkudak committed Mar 21, 2016
1 parent 135413c commit 02a03caa0cfb5a041bcae7fde261a0f28c8785d6
Showing with 27 additions and 5 deletions.
  1. +1 −0 README.md
  2. +10 −1 simulator/gui.py
  3. +10 −1 simulator/main.py
  4. +2 −2 simulator/robot.py
  5. +4 −1 simulator/simulator.py
View
@@ -83,6 +83,7 @@ Poniżej znajduje się spis wszystkich opcji dostępnych w symulatorze. Każda z
* ``-r`` / ``--robot`` - komenda uruchomienia programu z botem, np. `` -r "python3 examples/python3/template_bot.py"``
#### Parametry symulacji (dokładny opis w rozdziale **Bot**):
* ``-s`` / ``--seed`` - seed, który jest używany podczas generowania szumu
* ``--steering_noise``
* ``--distance_noise``
* ``--forward_steering_drift``
View
@@ -276,6 +276,12 @@ def _init_ui(self):
params_toolbar.addWidget(self.steering_noise_edit)
self.steering_noise_edit.textChanged.connect(self._update_steering_noise)
seed_label = QtGui.QLabel('seed: ')
params_toolbar.addWidget(seed_label)
self.seed_edit = QtGui.QLineEdit(str(self.simulator_params['seed']))
params_toolbar.addWidget(self.seed_edit)
self.seed_edit.textChanged.connect(self._update_seed)
fsteering_noise_label = QtGui.QLabel('forward_steering_drift: ')
params_toolbar.addWidget(fsteering_noise_label)
self.fsteering_noise_edit = QtGui.QLineEdit(str(self.simulator_params['forward_steering_drift']))
@@ -663,6 +669,10 @@ def _update_sonar_noise(self):
self.simulator_params['sonar_noise'] = \
float(self.sonar_noise_edit.text())
def _update_seed(self):
self.simulator_params['seed'] = \
int(self.seed_edit.text())
def _update_distance_noise(self):
self.simulator_params['distance_noise'] = \
float(self.distance_noise_edit.text())
@@ -715,7 +725,6 @@ def __init__(self, argv, simulator, simulator_params, output=None):
"""
self.simulator = simulator
# TODO(kudkudak): remove simulator_params
self.simulator_params = simulator_params
self.qt_app = QtGui.QApplication(argv)
self.main_window = None
View
@@ -43,6 +43,14 @@ def create_parser():
help="Map that will be run after hitting Start Simulation button, "
"or in command_line mode after running the program"
)
parser.add_option(
"-s",
"--seed",
dest="seed",
type="int",
default=777,
help="Seed used during robot noise generation"
)
parser.add_option(
"-o",
"--output",
@@ -55,7 +63,7 @@ def create_parser():
"-r",
"--robot",
dest="robot",
default="python2.7 " + os.path.join(os.path.dirname(__file__), "../examples/python/run.py"),
default="python2.7 " + os.path.join(os.path.dirname(__file__), "../examples/python/template_bot.py"),
help="Robot that will be compiled and run"
)
parser.add_option(
@@ -128,6 +136,7 @@ def create_parser():
(options, args) = parser.parse_args()
simulator_params = {
"seed": options.seed,
# Robot parameters
"speed": options.speed,
"distance_noise": options.distance_noise,
View
@@ -13,12 +13,12 @@ class Robot:
""" The main class representing robot that can sense and move """
def __init__(self, speed, turning_speed, gps_time, sonar_time, tick_move, tick_rotate,
color_sensor_displacement=SQUARE_SIDE/2.0):
color_sensor_displacement=SQUARE_SIDE/2.0, seed=777):
"""
Initialize robot
"""
self.speed = speed
self.rng = np.random.RandomState(777)
self.rng = np.random.RandomState(seed)
self.tick_move = tick_move
self.tick_rotate = tick_rotate
self.color_sensor_displacement = color_sensor_displacement
View
@@ -52,6 +52,7 @@ def __init__(self,
iteration_write_frequency=1000,
command_line=True,
print_robot=True,
seed=777,
print_logger=False,
accepted_commands=[TURN, MOVE, BEEP, FINISH, SENSE_COLOR]
):
@@ -91,6 +92,7 @@ def __init__(self,
self.init_position = (i + 0.5, j + 0.5, 0)
self.speed = speed
self.seed = seed
self.turning_speed = turning_speed
self.simulation_dt = simulation_dt
self.frame_dt = frame_dt
@@ -170,7 +172,7 @@ def run(self):
self.reset()
# Initialize robot object
robot = Robot(self.speed, self.turning_speed, self.gps_delay, self.sonar_time, TICK_MOVE, TICK_ROTATE)
robot = Robot(self.speed, self.turning_speed, self.gps_delay, self.sonar_time, TICK_MOVE, TICK_ROTATE, seed=self.seed)
robot.set(self.init_position[0], self.init_position[1], self.init_position[2])
robot.set_noise(new_s_noise=self.steering_noise,
new_d_noise=self.distance_noise,
@@ -348,6 +350,7 @@ def run(self):
map_to_save = dict(self.map)
del map_to_save['color_bitmap']
self.results = {
"final_position": (robot.x, robot.y),
"sim_time": robot.time_elapsed,
"cpu_time": robot_controller.time_consumed.total_seconds(),
"error": self.error or False,

0 comments on commit 02a03ca

Please sign in to comment.