def reset(self): self.elev1 = elev.elevator(self.maxfloor) self.elev2 = elev.elevator(self.maxfloor) for i in range(self.maxfloor - 1): self.upbtn[i] = False self.downbtn[i] = False for i in range(self.maxfloor): self.waitpeo[i] = [] self.finishtime = [] self.passenger_list.reset() return self._step(0, 0)[0]
def main(): lift = elevator.elevator("Ascensor") try: state_machine(lift) finally: print("Destroy") lift.destroy()
def test_rand(self): from random import randrange def solution(left, right, call): return "left" if abs(call - left) < abs(call - right) else "right" for _ in range(100): left, right, call = randrange(0, 3), randrange(0, 3), randrange(0, 3) print("Testing for: left = %d, right = %d, call = %d" % (left, right, call)) self.assertEqual(elevator(left, right, call), solution(left, right, call))
def test_when_passenger_arrives_should_transport_it(self): with mock.patch("elevator.transport") as transport: chan = csp.Channel() proc = elevator.elevator(chan) proc.start() chan.write("Francisco") chan.poison() transport.assert_called_with("Francisco")
def test_elevator_runs_in_a_loop(self): with mock.patch("elevator.transport") as transport: chan = csp.Channel() proc = elevator.elevator(chan) proc.start() chan.write("Francisco") chan.write("Chico") chan.write("Xikin") chan.poison() self.assertEqual(3, transport.call_count)
def __init__(self, filename=None, oddeven=False, maxFloor=10, num=0, freq=60, appnum=12): self.maxfloor = maxFloor #B1~9F self.elev1 = elev.elevator(self.maxfloor) self.elev2 = elev.elevator(self.maxfloor) self.upbtn = [False] * (self.maxfloor - 1) self.downbtn = [False] * (self.maxfloor - 1) self.waitpeo = [[] for i in range(self.maxfloor)] self.finishtime = [] self.passenger_list = passenger_generator(filename=filename, oddeven=oddeven, maxFloor=self.maxfloor, num=num, appear_freq=freq, appear_max_num=appnum)
def main(): wrist = arm(0.005, "wrist", 8.0, 1.0, 134.0, 0.7, 0.71, 18730.0 * 2.0 * math.pi / 60.0, 1.0 / 3.0 * 10.0 * 0.454 * ((17.0 * 0.0254)**2), 833.33) """q_1 = 1.0/((math.pi / 90.0)**2) q_2 = 1.0/((math.pi / 90.0)**2) Q_c = numpy.matrix([[q_1, 0], [0, q_2]]) r_1 = 1.0 / (0.1**2) R_c = numpy.matrix([[r_1]]) A_d, B_d, Q_d, R_d = controls.c2d(numpy.asmatrix(wrist.A_c), numpy.asmatrix(wrist.B_c),0.005, Q_c, R_c) K = controls.place(A_d, B_d, (0.9, 0.003)) L = controls.dkalman(A_d, wrist.C, Q_d, R_d) wrist.set_K(K) wrist.set_L(L)""" #wrist.run_test(numpy.matrix([[0.0],[0]]), numpy.matrix([[90.0],[0.0]]), True, False, True, 400) #wrist.run_pid_test([5.23, 0.0,0.0],numpy.matrix([[0.0],[0]]), numpy.matrix([[90.0],[0]]), True, True, 400) #wrist.run_custom_test(numpy.matrix([[0.0],[0]]), numpy.matrix([[90.0],[0]]), max_func, True, False, True, 400) wrist.get_stats() elev = elevator(0.005, "elev", 4.0, 4.0, 134.0, 0.7, 0.71, 18730.0 * 2.0 * math.pi / 60.0, 40.62, 1.751 * 0.0254, 10.0 * 0.454 + 2.5) #11.59) #elev.run_pid_test([1.2, 0.0,0.0],numpy.matrix([[0.0],[0]]), numpy.matrix([[60.0],[0]]), True, True, 400) #elev.run_custom_test(numpy.matrix([[0.0],[0]]), numpy.matrix([[60.0],[0]]), max_func, True, False, True, 400) elev.get_stats() drive_gear_ratio = (60.0 / 12.0) * (34.0 / 24.0) * (34.0 / 32.0) distribution_radius = 0.45 mass = 154.0 * 0.454 j = distribution_radius * mass print(drive_gear_ratio) drivetrain = drive(0.005, "drivetrain", 4.0, 3.0, 89.0, 3.0, 1.41, 5840 * 2.0 * math.pi / 60.0, drive_gear_ratio, j, 3.0 * 0.0254, 28.0 * 0.0254 * 0.5, 154.0 * 0.454) #drivetrain.run_pid_test([1.2, 0.0,.1],numpy.matrix([[0.0],[0],[0],[0]]), numpy.matrix([[12.0],[8.0], [0.0],[0.0]]), True, True, 4000) #drivetrain.run_custom_test(numpy.matrix([[0.0],[0],[0],[0]]), numpy.matrix([[12.0],[12.0], [0.0],[0.0]]), full_volts, True, False, True, 400) drivetrain.get_stats() intake = shooter(0.005, "intake", 4.0, 2.0, 134.0, 0.7, 0.71, 18730.0 * 2.0 * math.pi / 60.0, 0.5 * 0.0254**2 * 10.0, 6.67) intake.run_pid_test([0.05, 0.07, 0.0], numpy.matrix([[0.0]]), numpy.matrix([[2000.0]]), True, True, 400) #intake.run_custom_test(numpy.matrix([[0.0]]), numpy.matrix([[1000]]), max_func, True, False, True, 400) intake.get_stats()
def main(): lift = elevator.elevator("Ascensor1") lift.set_motor("stop") lift.set_mov_indicator("stop") lift.set_door("close") lift.set_light_call(2, "on") lift.set_light_int(5, "on") lift.set_light_int(1, "on") lift.set_light_int(2, "on") lift.set_light_int(3, "on") lift.set_light_int(4, "on") try: state_machine(lift) finally: print("Destroy") lift.destroy()
def test_fixed_tests(): assert elevator(0, 0, 0) == "right" assert elevator(0, 0, 1) == "right" assert elevator(0, 0, 2) == "right" assert elevator(0, 1, 0) == "left" assert elevator(0, 1, 1) == "right" assert elevator(0, 1, 2) == "right" assert elevator(0, 2, 0) == "left" assert elevator(0, 2, 1) == "right" assert elevator(0, 2, 2) == "right" assert elevator(1, 0, 0) == "right" assert elevator(1, 0, 1) == "left" assert elevator(1, 0, 2) == "left" assert elevator(1, 1, 0) == "right" assert elevator(1, 1, 1) == "right" assert elevator(1, 1, 2) == "right" assert elevator(1, 2, 0) == "left" assert elevator(1, 2, 1) == "left" assert elevator(1, 2, 2) == "right" assert elevator(2, 0, 0) == "right" assert elevator(2, 0, 1) == "right" assert elevator(2, 0, 2) == "left" assert elevator(2, 1, 0) == "right" assert elevator(2, 1, 1) == "right" assert elevator(2, 1, 2) == "left" assert elevator(2, 2, 0) == "right" assert elevator(2, 2, 1) == "right" assert elevator(2, 2, 2) == "right"
def init_elevator(building_layers): e = elevator(building_layers) t = threading.Thread(target = e.run) t.setDaemon(True) t.start() return (e,t)
return 1 else: return 0 return getbetas def finterest(env): def getinterest(state): if state in env.goal_states or state in env.elevator_states: return args.intrst else: return args.intrst return getinterest from elevator import elevator env = elevator(n=args.len) betas = fbetas(env) interest = finterest(env) action_1_prob = 0.5 action_2_prob = 1-action_1_prob fo_states = [(0,3), (args.len+1, 2), (args.len+1, 4), (2*args.len+2, 5), (2*args.len+2, 3), (2*args.len+2, 1)] v_pi = {i:0.5*(1+i[1]) for i in fo_states} weights = np.zeros_like(np.array(env.feat).reshape(-1,1)) else: raise NotImplementedError env.seed(args.seed) np.random.seed(args.seed) def getAction(args):
def test(self): self.assertEqual(elevator(0, 1, 0), "left") self.assertEqual(elevator(0, 1, 1), "right") self.assertEqual(elevator(0, 1, 2), "right") self.assertEqual(elevator(0, 0, 0), "right") self.assertEqual(elevator(0, 2, 1), "right") self.assertEqual(elevator(0, 0, 0), "right") self.assertEqual(elevator(0, 0, 1), "right") self.assertEqual(elevator(0, 0, 2), "right") self.assertEqual(elevator(0, 1, 0), "left") self.assertEqual(elevator(0, 1, 1), "right") self.assertEqual(elevator(0, 1, 2), "right") self.assertEqual(elevator(0, 2, 0), "left") self.assertEqual(elevator(0, 2, 1), "right") self.assertEqual(elevator(0, 2, 2), "right") self.assertEqual(elevator(1, 0, 0), "right") self.assertEqual(elevator(1, 0, 1), "left") self.assertEqual(elevator(1, 0, 2), "left") self.assertEqual(elevator(1, 1, 0), "right") self.assertEqual(elevator(1, 1, 1), "right") self.assertEqual(elevator(1, 1, 2), "right") self.assertEqual(elevator(1, 2, 0), "left") self.assertEqual(elevator(1, 2, 1), "left") self.assertEqual(elevator(1, 2, 2), "right") self.assertEqual(elevator(2, 0, 0), "right") self.assertEqual(elevator(2, 0, 1), "right") self.assertEqual(elevator(2, 0, 2), "left") self.assertEqual(elevator(2, 1, 0), "right") self.assertEqual(elevator(2, 1, 1), "right") self.assertEqual(elevator(2, 1, 2), "left") self.assertEqual(elevator(2, 2, 0), "right") self.assertEqual(elevator(2, 2, 1), "right") self.assertEqual(elevator(2, 2, 2), "right")
def init_elevator(): elevator_threads = [elevator(x) for x in range(1, 4)] return elevator_threads
#creating game objects #GAME MENU TEXT menuLabel = text.Label("The Red Tower\n", font_name="Tulpen One", font_size=48, color=(120,0,0,255),x=0, y=window.height - 80, halign='center', width=window.width, height=12, multiline=True) #menuLabel.set_style('align', 'center') endLabel = text.Label("ENDING\n", font_name="Tulpen One", font_size=36, color=(255,255,255,255), width = window.width - 40, multiline=True, halign='center', x = 20, y = window.height / 2 + 100) building = gameobject.gameobject(80.0,46.0,200,506, (255,255,255,255)) ground = gameobject.gameobject(0.0,46.0,360,2) shaft1 = gameobject.gameobject(108.0,50.0,44,500, (230,230,230,255)) shaft2 = gameobject.gameobject(202.0,50.0,44,500, (230,230,230,255)) elev1 = elevator.elevator(110.0,50.0,40,45,(0,0,0,255)) elev2 = text.Label("OUT OF\nSERVICE\n", font_name="Tulpen One", font_size=14, color=(0,0,0,255), x=200, y=82, bold=True, halign='center', width=44, multiline=True) floorsLabel = text.Label("9\n8\n7\n6\n5\n4\n3\n2\n1\nM", font_name="Tulpen One", font_size=34, color=(255,255,255,255), x=50, y=515, halign='center', width=20, multiline=True) #load data from files df = open("defaultperson.txt", "r") lines = df.readlines() df.close() nf = open("names.txt", "r") names = nf.readlines() nf.close()
def test_sample_tests(): assert elevator(0, 1, 0) == "left" assert elevator(0, 1, 1) == "right" assert elevator(0, 1, 2) == "right" assert elevator(0, 0, 0) == "right" assert elevator(0, 2, 1) == "right"
#creating game objects #GAME MENU TEXT menuLabel = text.Label("The Red Tower\n", font_name="Tulpen One", font_size=48, color=(120,0,0,255),x=0, y=window.height - 80, halign='center', width=window.width, height=12, multiline=True) #menuLabel.set_style('align', 'center') endLabel = text.Label("ENDING\n", font_name="Tulpen One", font_size=36, color=(255,255,255,255), width = window.width - 40, multiline=True, halign='center', x = 20, y = window.height / 2 + 100) building = gameobject.gameobject(80.0,46.0,200,506, (255,255,255,255)) ground = gameobject.gameobject(0.0,46.0,360,2) shaft1 = gameobject.gameobject(108.0,50.0,44,500, (230,230,230,255)) shaft2 = gameobject.gameobject(202.0,50.0,44,500, (230,230,230,255)) elev1 = elevator.elevator(110.0,50.0,40,45,(92,66,36,255)) elev2 = text.Label("OUT OF\nSERVICE\n", font_name="Tulpen One", font_size=14, color=(0,0,0,255), x=200, y=82, bold=True, halign='center', width=44, multiline=True) floorsLabel = text.Label("9\n8\n7\n6\n5\n4\n3\n2\n1\nM", font_name="Tulpen One", font_size=34, color=(255,255,255,255), x=50, y=515, halign='center', width=20, multiline=True) #load data from files df = open("defaultperson.txt", "r") lines = df.readlines() df.close() nf = open("names.txt", "r") names = nf.readlines() nf.close()
endLabel = text.Label("ENDING\n", font_name="Tulpen One", font_size=36, color=(255, 255, 255, 255), width=window.width - 40, multiline=True, halign='center', x=20, y=window.height / 2 + 100) building = gameobject.gameobject(80.0, 46.0, 200, 506, (255, 255, 255, 255)) ground = gameobject.gameobject(0.0, 46.0, 360, 2) shaft1 = gameobject.gameobject(108.0, 50.0, 44, 500, (230, 230, 230, 255)) shaft2 = gameobject.gameobject(202.0, 50.0, 44, 500, (230, 230, 230, 255)) elev1 = elevator.elevator(110.0, 50.0, 40, 45, (0, 0, 0, 255)) elev2 = text.Label("OUT OF\nSERVICE\n", font_name="Tulpen One", font_size=14, color=(0, 0, 0, 255), x=200, y=82, bold=True, halign='center', width=44, multiline=True) floorsLabel = text.Label("9\n8\n7\n6\n5\n4\n3\n2\n1\nM", font_name="Tulpen One", font_size=34,
def main(): rod_weight = 4.0 * 0.293 * 0.453592 radius = 3.0 / 16.0 * 0.0254 pitch = 16.0/ (1 * 0.0254) load = calculate_load_torque(40. * 4.4482, 2.0 * radius, pitch, 0.19) test = linear_actuator(0.005, "test", 1.0, 1.0, 105.0, 1.8, 2.6, 5676 * 2.0 * math.pi / 60.0, 0.5 * rod_weight * radius * radius, 1.0, pitch, load) #test.run_custom_test(numpy.matrix([[0.0],[0]]), numpy.matrix([[24.0],[0]]), max_func, True, False, True, 800) #test.get_stats() best_G = calculate_ideal_gear_ratio(load, 1.3) print(best_G) #Neo @ 1:3 overdrive running at 10 volts works best drive_gear_ratio = 7.083 * 24.0 / 60.0 * 64.0 / 20.0;#1.13333#5.10#50.0 /34.0 2.16 ratio spread 54 : 30 j = 6.0 #2778 2000 2907 3269 3211 3099 3287 3573 2705 #drivetrain = drive(0.005, "drivetrain", 4.0, 2.0, 131.0, 2.7, 2.41, 5330 * 2.0 * math.pi / 60.0, # drive_gear_ratio, j, 3.0 * 0.0254, 28.0 * 0.0254 * 0.5, 154.0 * 0.454) #radius base might be 25.5 * 0.0254 * 0.5, but not likely, more like 0.45 drivetrain = drive(0.005, "drivetrain", 3.0, 2.0, 131.0, 2.7, 2.41, 5330 * 2.0 * math.pi / 60.0, drive_gear_ratio, j, 3.0 * 0.0254, 25.5 * 0.0254 * 0.5 , (125.0) * 0.454) #drivetrain.run_pid_test([1.0, 0.0,0],numpy.matrix([[0.0],[0],[0],[0]]), numpy.matrix([[55.0],[55.0], [0.0],[0.0]]), True, True, 4000) #drivetrain.run_custom_test(numpy.matrix([[0.0],[0],[0],[0]]), numpy.matrix([[12.0],[12.0], [0.0],[0.0]]), full_volts, True, False, True, 2000) drivetrain.get_stats(True) driveQ_c = numpy.matrix([[1.0 / (0.14)**2.0 , 0, 0, 0], [0, 1.0 / (0.14)**2.0, 0, 0], [0, 0, 1.0 / (1.0)**2.0, 0], [0, 0, 0, 1.0 / (1.0)**2.0]]) driveR_c = numpy.matrix([[0.0001**2, 0.0], [0.0, 0.0001 **2]]) # [0 , 1.0 / (.1 * 0.0254)**2]]) driveA_d, driveB_d, driveQ_d, driveR_d = controls.c2d(drivetrain.A_c, drivetrain.B_c, 0.005, driveQ_c, driveR_c) driveK = controls.dlqr(driveA_d, driveB_d, driveQ_d, driveR_d) print(driveK) elev = elevator(0.005, "elev", 2.0, 2.0, 134.0, 0.7, 0.71, 18730.0 * 2.0 * math.pi / 60.0, 63.0, 3.0 * (0.8755 - 0.16) * 0.0254, 18.8* 0.454)#11.59) #elev.export("../python") elevQ_c = numpy.matrix([[1.0 / (0.0254 * 0.01)**2.0 , 0], [0 , 1.0 / (.1 * 0.0254)**2]]) elevR_c = numpy.matrix([[1.0 / 13.0**2]]) elevA_d, elevB_d, elevQ_d, elevR_d = controls.c2d(elev.A_c, elev.B_c, 0.005, elevQ_c, elevR_c) elevK = controls.dlqr(elevA_d, elevB_d, elevQ_d, elevR_d) elevL = controls.dkalman(elevA_d, elevB_d, elevQ_d, elevR_d) #print(elevK) elev.run_test([[0.],[0.]],[[0.0],[60.0]])
endLabel = text.Label("ENDING\n", font_name="Tulpen One", font_size=36, color=(255, 255, 255, 255), width=window.width - 40, multiline=True, halign='center', x=20, y=window.height / 2 + 100) building = gameobject.gameobject(80.0, 46.0, 200, 506, (255, 255, 255, 255)) ground = gameobject.gameobject(0.0, 46.0, 360, 2) shaft1 = gameobject.gameobject(108.0, 50.0, 44, 500, (230, 230, 230, 255)) shaft2 = gameobject.gameobject(202.0, 50.0, 44, 500, (230, 230, 230, 255)) elev1 = elevator.elevator(110.0, 50.0, 40, 45, (92, 66, 36, 255)) elev2 = text.Label("OUT OF\nSERVICE\n", font_name="Tulpen One", font_size=14, color=(0, 0, 0, 255), x=200, y=82, bold=True, halign='center', width=44, multiline=True) floorsLabel = text.Label("9\n8\n7\n6\n5\n4\n3\n2\n1\nM", font_name="Tulpen One", font_size=34,