def main(): # use your own robot to run a simulation! sim = Sim2d(SIM, ROBOT) # create a simulator according to specification patch_robot(sim) robot = Robot() # choose from one of the robot's algorithms: # sim.update = robot.simple_algorithm # sim.update = robot.p_algorithm # sim.update = robot.pd_algorithm sim.update = robot.pid_algorithm(SIM['velocity'], ROBOT['PID']) sim.run()
def run_laptime(params): """build a robot from parameters and run simulation, optimize for laptime.""" # robot specification # positions are relative to the upper left corner ROBOT = { "ls": [(int(params[0] / 2.0), 3)], "ls_radius": 3, "lwheel": (0, int(params[1]) + 3), "rwheel": (int(params[0]), int(params[1]) + 3), "tire": 56, # tire diameter in mm } sim = Sim2d(SIM, ROBOT) # create a simulator according to specification patch_robot(sim) robot = Robot() sim.update = robot.pid_algorithm(SIM["velocity"], params[2:]) # PID parameters are used in algorithm lap = sim.measure_laptime(20.0) print "[A,L,P,I,D]: %s, laptime: %03.3f" % (params, lap) return lap