def start_test(self, challenge): vals = self.parseChallenge(challenge) if 'v' not in vals or 'x_g' not in vals or 'y_g' not in vals or 's_hz' not in vals: raise CourseraException( "Unknown challenge format. Please contact developers for assistance." ) self.cdist = 100 self.switches = 0 self.max_shz = vals['s_hz'] self.v = vals['v'] self.goal = (vals['x_g'], vals['y_g']) self.p = helpers.Struct() self.p.velocity = helpers.Struct({'v': vals['v']}) self.p.goal = helpers.Struct({'x': vals['x_g'], 'y': vals['y_g']}) self.p.gains = helpers.Struct({'kp': 4, 'ki': 0.1, 'kd': 0}) # FIXME What follows is a hack, that will only work # in the current GUI implementation. # For a better solution we need to change the API again docks = self.testsuite.gui.dockmanager.docks if len(docks): dock = docks[list(docks.keys())[0]] self.p.gains = dock.widget().contents.get_struct().gains self.testsuite.gui.start_testing() self.testsuite.gui.register_event_handler(self) self.testsuite.gui.load_world('week5_switching.xml') self.testsuite.gui.run_simulator_command('add_plotable', self.dst2goal) self.testsuite.gui.run_simulation()
def start_test(self, challenge): vals = self.parseChallenge(challenge) if 'v' not in vals or 'x_g' not in vals or 'y_g' not in vals: raise CourseraException( "Unknown challenge format. Please contact developers for assistance." ) self.p = helpers.Struct() self.p.goal = helpers.Struct() self.p.goal.x = vals['x_g'] self.p.goal.y = vals['y_g'] self.p.velocity = helpers.Struct() self.p.velocity.v = vals['v'] self.p.gains = helpers.Struct() self.p.gains.kp = 3 self.p.gains.ki = 6 self.p.gains.kd = 0.01 docks = self.testsuite.gui.dockmanager.docks if len(docks): dock = docks[list(docks.keys())[0]] self.p.gains = dock.widget().contents.get_struct().gains self.testsuite.gui.start_testing() self.testsuite.gui.register_event_handler(self) self.testsuite.gui.load_world('week3.xml') self.testsuite.gui.run_simulator_command('add_plotable', self.dst2goal) #self.testsuite.gui.dockmanager.docks[self.dockname].widget().apply_click() self.testsuite.gui.run_simulation()
def start_test(self, challenge): vals = self.parseChallenge(challenge) if 'v' not in vals: raise CourseraException( "Unknown challenge format. Please contact developers for assistance." ) self.p = helpers.Struct() self.p.velocity = helpers.Struct() self.p.velocity.v = vals['v'] self.p.gains = helpers.Struct() self.p.gains.kp = 4 self.p.gains.ki = 0.1 self.p.gains.kd = 0 self.max_dr = 0.0 # FIXME What follows is a hack, that will only work # in the current GUI implementation. # For a better solution we need to change the API again docks = self.testsuite.gui.dockmanager.docks if len(docks): dock = docks[list(docks.keys())[0]] self.p.gains = dock.widget().contents.get_struct().gains self.testsuite.gui.start_testing() self.testsuite.gui.register_event_handler(self) self.testsuite.gui.load_world('week4.xml') # We have to check the robot actually moved self.testsuite.gui.run_simulator_command('add_plotable', self.dr) self.testsuite.gui.run_simulation()
def start_test(self, challenge): print(challenge) vals = self.parseChallenge(challenge) print(vals) if 'dist_1' not in vals or 'x' not in vals or 'y' not in vals or 'theta' not in vals: raise CourseraException( "Unknown challenge format. Please contact developers for assistance." ) rpose = Pose(vals['x'], vals['y'], vals['theta']) ir_sensor_poses = [ Pose(-0.0474, 0.0534, np.radians(90)), Pose(0.0613, 0.0244, np.radians(45)), Pose(0.0636, 0.0, np.radians(0)), Pose(0.0461, -0.0396, np.radians(-45)), Pose(-0.0690, -0.0534, np.radians(-90)) ] params = helpers.Struct() params.sensor_poses = [p >> rpose for p in ir_sensor_poses] params.gains = helpers.Struct({'kp': 0, 'ki': 0, 'kd': 0}) state = helpers.Struct() state.sensor_distances = [ vals['dist_1'], 0.3, 0.3, vals['dist_1'], 0.3 ] AvoidObstacles = helpers.load_by_name('week4_solved.AvoidObstacles', 'controllers') testAO = AvoidObstacles(params) testAO.get_heading(state) vs = testAO.vectors error_1 = math.sqrt((vs[0][0] - 0.3637)**2 + (vs[0][1] + 0.0545)**2) error_2 = math.sqrt((vs[3][0] + 0.0895)**2 + (vs[3][1] + 0.2932)**2) self.testsuite.respond("{:0.3f},{:0.3f}".format(error_1, error_2))
def __call__(self, event, args): if self.testsuite.gui.simulator_thread.get_time() > 30: self.stop_test() self.testsuite.respond("0") if event == "plot_update": # get distance to goal from the simulator dst = args[0][self.dst2goal] if dst < 0.05: self.stop_test() self.testsuite.respond("1") elif event == "log": # watch for collisions message, objclass, objcolor = args if message.startswith("Collision with"): self.stop_test() self.testsuite.respond("0") elif event == "make_param_window": # in the beginning rewrite parameters robot_id, name, params = args # FIXME What follows is a hack, that will only work # in the current GUI implementation. # For a better solution we need to change the API again params[0][1][0] = ('x', self.goal[0]) params[0][1][1] = ('y', self.goal[1]) params[1][1][0] = ('v', self.v) p = helpers.Struct() p.goal = helpers.Struct() p.goal.x = self.goal[0] p.goal.y = self.goal[1] p.velocity = helpers.Struct() p.velocity.v = self.v p.gains = helpers.Struct() p.gains.kp = params[2][1][0][1] p.gains.ki = params[2][1][1][1] p.gains.kd = params[2][1][2][1] self.testsuite.gui.run_simulator_command('apply_parameters', robot_id, p) #elif event == 'reset' # World constructed, safe return False
def start_test(self, challenge): vals = self.parseChallenge(challenge) if 'v' not in vals or 'x_g' not in vals or 'y_g' not in vals: raise CourseraException( "Unknown challenge format. Please contact developers for assistance." ) self.p = helpers.Struct() self.p.goal = helpers.Struct() self.p.goal.x = vals['x_g'] self.p.goal.y = vals['y_g'] self.p.velocity = helpers.Struct() self.p.velocity.v = vals['v'] self.p.gains = helpers.Struct() self.p.gains.kp = 3 self.p.gains.ki = 6 self.p.gains.kd = 0.01 # FIXME What follows is a hack, that will only work # in the current GUI implementation. # For a better solution we need to change the API again docks = self.testsuite.gui.dockmanager.docks if len(docks): dock = docks[list(docks.keys())[0]] self.p.gains = dock.widget().contents.get_struct().gains self.dtheta_min = math.pi self.dthetas = [] self.testsuite.gui.start_testing() self.testsuite.gui.register_event_handler(self) self.testsuite.gui.load_world('week3.xml') self.testsuite.gui.run_simulator_command('add_plotable', self.dtheta) self.testsuite.gui.run_simulator_command('add_plotable', self.dst2goal) #self.testsuite.gui.dockmanager.docks[self.dockname].widget().apply_click() self.testsuite.gui.run_simulation()
def __construct_world(self): """Creates objects previously loaded from the world xml file. This function uses the world in ``self.__world``. All the objects will be created anew, including robots and supervisors. All of the user's code is reloaded. """ if self.__world is None: return helpers.unload_user_modules() self.__state = DRAW_ONCE self.__robots = [] self.__obstacles = [] self.__supervisors = [] self.__background = [] self.__trackers = [] self.__qtree = None for thing in self.__world: thing_type = thing[0] if thing_type == 'robot': robot_type, supervisor_type, robot_pose, robot_color = thing[ 1:5] try: # Get options if len(thing) > 5: robot_options = thing[5] if robot_options is not None: robot_options = helpers.Struct(robot_options) super_options = thing[6] if super_options is not None: super_options = helpers.Struct(super_options) # Create robot robot_class = helpers.load_by_name(robot_type, 'robots') if robot_options is not None: robot = robot_class(pose.Pose(robot_pose), options=robot_options) else: robot = robot_class(pose.Pose(robot_pose)) robot.set_logqueue(self.__log_queue) if robot_color is not None: robot.set_color(robot_color) elif len(self.__robots) < 8: robot.set_color(self.__nice_colors[len(self.__robots)]) # Create supervisor sup_class = helpers.load_by_name(supervisor_type, 'supervisors') info = robot.get_info() info.color = robot.get_color() if super_options is not None: supervisor = sup_class(robot.get_pose(), info, options=super_options) else: supervisor = sup_class(robot.get_pose(), info) supervisor.set_logqueue(self.__log_queue) name = "Robot {}: {}".format( len(self.__robots) + 1, sup_class.__name__) if self.__supervisor_param_cache is not None and \ len(self.__supervisor_param_cache) > len(self.__supervisors): supervisor.set_parameters( self.__supervisor_param_cache[len( self.__supervisors)]) self._out_queue.put( ("make_param_window", (robot, name, supervisor.get_ui_description()))) self.__supervisors.append(supervisor) # append robot after supervisor for the case of exceptions self.__robots.append(robot) # Create trackers self.__trackers.append( simobject.Path(robot.get_pose(), robot.get_color())) except: self.log( "[Simulator.construct_world] Robot creation failed!") raise #raise Exception('[Simulator.construct_world] Unknown robot type!') elif thing_type == 'obstacle': obstacle_pose, obstacle_coords, obstacle_color = thing[1:4] if obstacle_color is None: obstacle_color = 0xFF0000 self.__obstacles.append( simobject.Polygon(pose.Pose(obstacle_pose), obstacle_coords, obstacle_color)) elif thing_type == 'marker': obj_pose, obj_coords, obj_color = thing[1:4] if obj_color is None: obj_color = 0x00FF00 self.__background.append( simobject.Polygon(pose.Pose(obj_pose), obj_coords, obj_color)) else: raise Exception( '[Simulator.construct_world] Unknown object: ' + str(thing_type)) self.__time = 0.0 if not self.__robots: raise Exception('[Simulator.construct_world] No robot specified!') else: self.__recalculate_default_zoom() if not self.__center_on_robot: self.focus_on_world() self.__supervisor_param_cache = None self.step_simulation() self._out_queue.put(('reset', ()))
from flask import Flask, jsonify from flask.ext.sqlalchemy import SQLAlchemy import helpers import yaml import os from werkzeug.exceptions import default_exceptions app = Flask(__name__) config_path = os.environ.get('CONFIG', "config.yaml") config_obj = yaml.safe_load(open(config_path)) app.config.from_object(helpers.Struct(**config_obj)) app.debug = app.config.get('DEBUG', False) db = SQLAlchemy(app) for code in default_exceptions.iterkeys(): app.error_handler_spec[None][code] = helpers.make_json_error class ApiError(Exception): status_code = 400 def __init__(self, message, status_code=None, payload=None): Exception.__init__(self) self.message = message if status_code is not None: self.status_code = status_code self.payload = payload