def __init__(self): self.elements = [ Wheel("front left"), Wheel("front right"), Wheel("back left"), Wheel("back right"), Body(), Engine() ]
def init(): wheelOne = Wheel(6, 19, "Wheel One") wheelTen = Wheel(5, 13, "Wheel Ten") wheelArray = [wheelOne, wheelTen] initGPIO(wheelArray) for wheel in wheelArray: print "Initializing " + wheel.wheelName wheel.initZero() print wheel.wheelName + " is set to Zero\n" return wheelArray
def initWheels(): wheelTen = Wheel(5, 13, "Wheel Ten", 16, 20) wheelOne = Wheel(6, 19, "Wheel One", 16, 20) wheelDecimal = Wheel(21, 26, "Wheel Decimal", 16, 20) wheelArray = [wheelTen, wheelOne, wheelDecimal] initGPIO(wheelArray) for wheel in wheelArray: print "Initializing " + wheel.wheelName wheel.initZero() print wheel.wheelName + " is set to Zero\n" return wheelArray
def retrieve_page(url): # 打开文件时必须设置一下encoding,否则在win平台下默认以gbk来解析 global STORE_FILE with open(STORE_FILE, 'w', encoding=Config.DEFAULT_ENCODING) as file: # 许多网页默认返回的encoding是iso-8859-1,这是一种单字节的编码形式,实际编码还得依据charset说明。 t = Wheel.Wheel(url, 'get') r = t.send() file.write(r.body)
def __init__(self): """Initializes the data""" #create empty object properties self.mass = None self.wheel = Wheel() self.motor = Motor() self.GearRatio = None self.GearEfficieny = None self.Cd = None self.Af = None self.battery = Battery()
class Bike: """Class for modeling a bicycle""" #put any class variables here def __init__(self): """Initializes the data""" #create empty object properties self.mass = None self.wheel = Wheel() self.motor = Motor() self.GearRatio = None self.GearEfficieny = None self.Cd = None self.Af = None self.battery = Battery() def AirDrag(self,rho,v): return(0.5*rho*self.Cd*self.Af*v*v) def WheelDrag(self): #assumes normal force is always equal to gravity return(self.wheel.Crr*self.mass*9.81) def MotorSpeed2WheelSpeed(self,Speed): return(Speed/self.GearRatio) def WheelSpeed2BikeSpeed(self,Speed): return(Speed*self.wheel.Radius()) def BikeSpeed2WheelSpeed(self,Speed): return(Speed/self.WheelSpeed2BikeSpeed(1)) def WheelSpeed2MotorSpeed(self,Speed): return(Speed/self.MotorSpeed2WheelSpeed(1)) def BikeSpeed2MotorSpeed(self,Speed): return(self.WheelSpeed2MotorSpeed(self.BikeSpeed2WheelSpeed(Speed))) def MotorSpeed2BikeSpeed(self,Speed): return(Speed/self.BikeSpeed2MotorSpeed(1)) def MotorTorque2WheelTorque(self,MT): return(MT*self.GearRatio*self.GearEfficiency)
def __init__(self, orientations, permutator): self.wheel = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ] self.leftWheel = Wheel([ '2', 'Y', 'Z', '0', '1', 'A', 'W', 'I', 'P', 'K', 'S', 'N', '3', 'T', 'E', 'R', 'M', 'U', 'C', '5', 'V', '6', 'X', '7', 'F', 'Q', 'O', 'L', '4', '8', 'G', 'D', '9', 'B', 'J', 'H' ], 0) self.middleWheel = Wheel([ '0', 'L', 'X', '1', '2', '8', 'H', 'B', '3', 'N', 'R', 'O', 'K', 'D', 'T', '7', 'C', '6', 'P', 'I', 'V', 'J', '4', 'A', 'U', 'W', 'M', 'E', '9', '5', 'Q', 'S', 'Z', 'G', 'Y', 'F' ], 0) self.rightWheel = Wheel([ '3', '5', 'H', 'E', 'F', 'G', 'D', 'Q', '8', 'M', '2', 'K', 'L', 'J', 'N', 'S', 'U', 'W', 'O', 'V', 'R', 'X', 'Z', 'C', 'I', '9', 'T', '7', 'B', 'P', 'A', '0', '1', 'Y', '6', '4' ], 0) self.characterCounter = 0 # can be used both for encryption and decryption for orientation in range(orientations[0]): self.leftWheel.turn() for orientation in range(orientations[1]): self.middleWheel.turn() for orientation in range(orientations[2]): self.rightWheel.turn() self.permutator = permutator
def reset(self): #self.startOrientation = p.getQuaternionFromEuler([-2.3561944901795866, 0.5235987755999999, 0]) self.robot = p.loadURDF("%s/dai.urdf" % self.urdfRootPath, self.startPos, self.startOrientation) self.buildJointNameToIdDict() self.slider1 = Slider2(self.jointNameToId["SliderMotor1"], self.robot) self.slider2 = Slider2(self.jointNameToId["SliderMotor2"], self.robot) self.slider3 = Slider2(self.jointNameToId["SliderMotor3"], self.robot) self.wheel1a = Wheel(self.jointNameToId["WheelMotor1a"], self.robot) self.wheel2a = Wheel(self.jointNameToId["WheelMotor2a"], self.robot) self.wheel3a = Wheel(self.jointNameToId["WheelMotor3a"], self.robot) self.wheel1b = Wheel(self.jointNameToId["WheelMotor1b"], self.robot) self.wheel2b = Wheel(self.jointNameToId["WheelMotor2b"], self.robot) self.wheel3b = Wheel(self.jointNameToId["WheelMotor3b"], self.robot) self.inertiaMeter = InertiaMeter(self.robot) self.camera1 = Camera() self.camera2 = Camera(((0, 0, 10), (0, 0, 0), (0, 1, 0)), (45.0, 1.0, 0.1, 10.1), 224, 224)
from Wheel import Wheel import math wheel = Wheel() for i in range(10**3): wheel.set_speed(math.sin(i*(math.pi/36))) wheel.set_angle(i) assert math.fabs(wheel.speed) <= 1.0 assert wheel.angle > 0 or wheel.angle < 360 print "Passed"
def __init__(self): Wheel.__init__(self, Firm.AUDI)
class Round: __GUESS_TYPE_WHEEL = 'wheel' __GUESS_TYPE_BUY = 'buy' __VOWEL_COST = 200 __WORD_VALUE = 500 def __init__(self, secret_word: SecretWord, theme: str, players: Tuple[Player, ...] = None): self._set_secret_word(secret_word) self._theme = theme self._set_players(players) self._set_wheel() self._set_menu() def _set_players(self, players): if players is None: players = tuple([Player("Player")]) self._players = players self._players_count = len(self._players) self._current_player_index = 0 self._current_player = self._players[0] def _set_wheel(self): self._wheel = Wheel([100, 200, 300, 400, 500]) self._letter_value = 0 def _set_secret_word(self, secret_word): self._secret_word = secret_word self._guessed_letters = [] def _set_menu(self): self._menu = Menu( 'Escolha uma das opções:', { '1': { 'description': 'Rodar a roda (chutar uma consoante)', 'action': self._spin_the_wheel }, '2': { 'description': f'Comprar vogál por R${Round.__VOWEL_COST:.2f}', 'action': self._buy_vowel }, '3': { 'description': 'Advinhe a palavra', 'action': self._guess_word } }) def run(self): return self._run_turn() def _run_turn(self): self._print_turn_start_message() self._input_options_menu() def _print_turn_start_message(self): RoundCLI.print_start_message(self._secret_word, self._theme, self._current_player) def _input_options_menu(self): try: option_action = self._menu.input_menu() option_action() except InvalidMenuOption as e: print(e) sleep(1) self._run_turn() return def _spin_the_wheel(self): self._letter_value = self._wheel.spin() self._try_to_guess(Round.__GUESS_TYPE_WHEEL) def _buy_vowel(self): try: self._current_player.takes_money(Round.__VOWEL_COST) self._try_to_guess(Round.__GUESS_TYPE_BUY) except InvalidAmount: print(f'Você não tem dinheiro suficiente para comprar uma vogal') sleep(2) self._run_turn() def _guess_word(self): self._print_turn_start_message() guess = input('Qual é a palavra? ') has_guessed_word = self._secret_word.check_word(guess) self._print_turn_start_message() sleep(1) if has_guessed_word: self._current_player.add_money(Round.__WORD_VALUE) print(f'Você chutou {self._secret_word.get_word()} e acertou!') sleep(2) print(f'Você ganhou R${Round.__WORD_VALUE:.2f}') sleep(2) self._check_round(has_guessed_word) def _try_to_guess(self, guess_type): self._print_turn_start_message() if guess_type == Round.__GUESS_TYPE_WHEEL: RoundCLI.print_letter_value_message(self._letter_value) try: guess = self._input_guess(guess_type) has_guessed_letter = self._check_guess(guess, guess_type) self._check_round(has_guessed_letter) except (InvalidLetter, HasGuessedLetterBefore) as error_message: print(error_message) sleep(1.5) self._try_to_guess(guess_type) except NothingLeftToGuess as error_message: print(error_message) sleep(1.5) def _check_guess(self, guess, guess_type): print(f"Você chutou '{guess}'") letter_count = self._secret_word.get_letter_count(guess) has_guessed_letter = self._reveal_letter(guess, guess_type) if has_guessed_letter: RoundCLI.print_guessed_correctly_message(letter_count, guess) if guess_type == Round.__GUESS_TYPE_WHEEL: earned_money = self._letter_value * letter_count self._current_player.add_money(earned_money) RoundCLI.print_earned_money_message(earned_money) return has_guessed_letter def _reveal_letter(self, guess, guess_type): if guess_type == Round.__GUESS_TYPE_WHEEL: has_guessed_letter = self._secret_word.reveal_consonant_or_number( guess) elif guess_type == Round.__GUESS_TYPE_BUY: has_guessed_letter = self._secret_word.reveal_vowel(guess) else: has_guessed_letter = False return has_guessed_letter def _input_guess(self, guess_type): guess = '' if guess_type == Round.__GUESS_TYPE_WHEEL: guess = RoundCLI.input_consonant_or_number_guess() elif guess_type == Round.__GUESS_TYPE_BUY: guess = RoundCLI.input_vowel_guess() return guess def _check_round(self, has_guessed_letter): if self._secret_word.was_guessed: return RoundCLI.print_end_turn_message(has_guessed_letter) if has_guessed_letter: return self._continue_turn() else: return self._next_turn() def _continue_turn(self): return self._run_turn() def _next_turn(self): self._select_next_player() return self._run_turn() def _select_next_player(self): next_player_index = self._current_player_index + 1 index_is_out_of_bounds = next_player_index >= self._players_count if index_is_out_of_bounds: next_player_index = 0 self._current_player_index = next_player_index self._current_player = self._players[next_player_index]
from Wheel import Wheel class Brake: def __init__(self,type): self.type= type def apply(self): return self.apply def display_info_brake(self): print("Brake is",self.type) my_car=Wheel(1.75) my_car.display_info_wheel()
def error(self): return Wheel.distance_between_numbers(int(self.expected), int(self.actual))
from GearBoxType import GearBoxType from Suspension import Suspension from Body import Body from Tire import Tire from Wheel import Wheel from Brake import Brake from lab1 import Car from CarModel import CarModel from Engine import Engine engine = Engine(capacity=2, number_of_cylinders=4) car_model = CarModel() gear_box_type = GearBoxType(name='', remarks='') suspension = Suspension(spring_rate=0.0) body = Body(number_of_doors=4) wheel = Wheel(diameter=21) gear_box = GearBox(gear_ratio=1.2, current_gear=3) tire = Tire(width=12, air_pressure=14) brake = Brake(type='brembo') car = Car(registration_num=1303, year=2001, license_number='XCSSERRS', engine=engine, gear_box=gear_box, gear_box_type=gear_box_type, suspension=suspension, body=body, tire=tire, wheel=wheel, brake=brake)
class Enigma: def __init__(self, orientations, permutator): self.wheel = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ] self.leftWheel = Wheel([ '2', 'Y', 'Z', '0', '1', 'A', 'W', 'I', 'P', 'K', 'S', 'N', '3', 'T', 'E', 'R', 'M', 'U', 'C', '5', 'V', '6', 'X', '7', 'F', 'Q', 'O', 'L', '4', '8', 'G', 'D', '9', 'B', 'J', 'H' ], 0) self.middleWheel = Wheel([ '0', 'L', 'X', '1', '2', '8', 'H', 'B', '3', 'N', 'R', 'O', 'K', 'D', 'T', '7', 'C', '6', 'P', 'I', 'V', 'J', '4', 'A', 'U', 'W', 'M', 'E', '9', '5', 'Q', 'S', 'Z', 'G', 'Y', 'F' ], 0) self.rightWheel = Wheel([ '3', '5', 'H', 'E', 'F', 'G', 'D', 'Q', '8', 'M', '2', 'K', 'L', 'J', 'N', 'S', 'U', 'W', 'O', 'V', 'R', 'X', 'Z', 'C', 'I', '9', 'T', '7', 'B', 'P', 'A', '0', '1', 'Y', '6', '4' ], 0) self.characterCounter = 0 # can be used both for encryption and decryption for orientation in range(orientations[0]): self.leftWheel.turn() for orientation in range(orientations[1]): self.middleWheel.turn() for orientation in range(orientations[2]): self.rightWheel.turn() self.permutator = permutator def printState(self): print('The wheel orientations from left to right are:', self.leftWheel.getOrientation(), self.middleWheel.getOrientation(), self.rightWheel.getOrientation()) def getChout(self, chin): print('Processing character', chin) self.characterCounter += 1 self.rightWheel.turn() print('The right wheel turns.') if self.characterCounter % 7 == 0: self.middleWheel.turn() print('The middle wheel turns.') if self.characterCounter % 5 == 0: self.leftWheel.turn() print('The left wheel turns.') self.printState() print('Still processing', chin) rightOut_midIn = self.rightWheel.getContactOut(self.wheel.index(chin)) midOut_leftIn = self.middleWheel.getContactOut(rightOut_midIn) leftOut = self.leftWheel.getContactOut(midOut_leftIn) print('Encrypted letter:', self.wheel[leftOut]) self.printState() return self.wheel[leftOut] def encrypt(self, message): initChars = list(message) chars = [] if len(initChars) == 10: for i in self.permutator: chars.append(initChars[i]) else: chars = initChars[:] output = '' for char in chars: output += self.getChout(char) return output def getDChout(self, chin): print('Processing character', chin) self.printState() leftOut_midIn = self.leftWheel.getDContactOut(self.wheel.index(chin)) # if self.characterCounter % 5 == 0: # self.leftWheel.turnOtherWay() midOut_rightIn = self.middleWheel.getDContactOut(leftOut_midIn) # if self.characterCounter % 7 == 0: # self.middleWheel.turnOtherWay() rightOut = self.rightWheel.getDContactOut(midOut_rightIn) print('Decrypted Letter:', self.wheel[rightOut]) self.printState() # self.rightWheel.turnOtherWay() if self.characterCounter % 5 == 0: self.leftWheel.turnOtherWay() print('The left wheel turns the other way.') if self.characterCounter % 7 == 0: self.middleWheel.turnOtherWay() print('The middle wheel turns the other way.') self.rightWheel.turnOtherWay() print('The right wheel turns the other way.') self.characterCounter -= 1 return self.wheel[rightOut] def decrypt(self, message): chars = list(message) self.characterCounter = len(chars) for i in range(1, self.characterCounter + 1): self.rightWheel.turn() if i % 7 == 0: self.middleWheel.turn() if i % 5 == 0: self.leftWheel.turn() charsReversed = chars[::-1] output = '' for char in charsReversed: output = self.getDChout(char) + output properOutput = ['', '', '', '', '', '', '', '', '', '', ''] if len(chars) == 10: for i, j in zip(self.permutator, range(0, 10)): properOutput[i] = output[j] else: properOutput = output[:] op = '' for i in properOutput: op += i return op def protoGetChout(self, chin): print('Processing character', chin) self.printState() self.characterCounter += 1 rightOut_midIn = self.rightWheel.getContactOut(self.wheel.index(chin)) midOut_leftIn = self.middleWheel.getContactOut(rightOut_midIn) leftOut = self.leftWheel.getContactOut(midOut_leftIn) print('Encrypted letter:', self.wheel[leftOut]) self.rightWheel.turn() print('The right wheel turns.') if self.characterCounter % 7 == 0: self.middleWheel.turn() print('The middle wheel turns.') if self.characterCounter % 5 == 0: self.leftWheel.turn() print('The left wheel turns.') self.printState() return self.wheel[leftOut] def protoEncrypt(self, message): chars = list(message) output = '' for char in chars: output += self.protoGetChout(char) return output def protoGetDChout(self, chin): print('Processing character', chin) self.printState() if self.characterCounter % 5 == 0: self.leftWheel.turnOtherWay() print('The left wheel turns the other way.') if self.characterCounter % 7 == 0: self.middleWheel.turnOtherWay() print('The middle wheel turns the other way.') self.rightWheel.turnOtherWay() print('The right wheel turns the other way.') leftOut_midIn = self.leftWheel.getDContactOut(self.wheel.index(chin)) # if self.characterCounter % 5 == 0: # self.leftWheel.turnOtherWay() midOut_rightIn = self.middleWheel.getDContactOut(leftOut_midIn) # if self.characterCounter % 7 == 0: # self.middleWheel.turnOtherWay() rightOut = self.rightWheel.getDContactOut(midOut_rightIn) print('Decrypted Letter:', self.wheel[rightOut]) self.printState() # self.rightWheel.turnOtherWay() self.characterCounter -= 1 return self.wheel[rightOut] def protoDecrypt(self, message): chars = list(message) self.characterCounter = len(chars) for i in range(1, self.characterCounter + 1): self.rightWheel.turn() if i % 7 == 0: self.middleWheel.turn() if i % 5 == 0: self.leftWheel.turn() charsReversed = chars[::-1] output = '' for char in charsReversed: output = self.protoGetDChout(char) + output return output
GPIO.setup(wheel.output, GPIO.OUT) GPIO.setup(wheel.input, GPIO.IN) GPIO.output(wheel.output, GPIO.LOW) # Parse command line parameters. sensor_args = { '11': Adafruit_DHT.DHT11, '22': Adafruit_DHT.DHT22, '2302': Adafruit_DHT.AM2302 } if len(sys.argv) == 3 and sys.argv[1] in sensor_args: sensor = sensor_args[sys.argv[1]] pin = sys.argv[2] else: print('usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin#') print('example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO #4') sys.exit(1) humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) try: if humidity is not None and temperature is not None: wheelOne = Wheel(4, 19) wheelTen = Wheel(5, 13) wheelArray = [wheelOne, wheelTen] initGPIO(wheelArray) wheelTen.initZero() GPIO.cleanup() else: print('Failed to get reading. Try again!') sys.exit(1) except KeyboardInterrupt: GPIO.cleanup()
def main(): b = Bike() print(b) print(Wheel.Count())
from GearBoxType import GearBoxType from Suspension import Suspension from Body import Body from Tire import Tire from Wheel import Wheel from Brake import Brake from lab1 import Car from CarModel import CarModel from engine import Engine engine = Engine(capacity=2, number_of_cylinders=4) car_model = CarModel() gear_box_type = GearBoxType(name='', remarks='') suspension = Suspension(spring_rate=0.0) body = Body(number_of_doors=4) wheel = Wheel(diameter=17) gear_box = GearBox(gear_ratio=1.2, current_gear=3) tire = Tire(width=12, air_pressure=14) brake = Brake(type='brembo') car = Car(registration_num=8457, year=1998, license_number='XCSSERRS', engine=engine, gear_box=gear_box, gear_box_type=gear_box_type, suspension=suspension, body=body, tire=tire, wheel=wheel, brake=brake)
def __init__(self): Wheel.__init__(self, 'TransportWheels') self.base_method = 'rotate around the axis in the vertical plane'
import os from Error import Error from Scene import Scene from Light import Light from Radio import Radio from Vegetables import Vegetables from Wheel import Wheel error = Error() scene = Scene() light = Light() radio = Radio() vegetables = Vegetables() wheel = Wheel() class Consumer: def __init__(self): print("init consumers") def new_data(self, dic): if dic["type"].lower() == "scene": print "it's Scene" scene.new_data(dic) elif dic["type"].lower() == "light": print "it's Light" light.new_data(dic) elif dic["type"].lower() == "radio": print "it's Radio"
def run(self, start_url, headers=None): # 单线程模式 # 为队列添加初始url ignore_file_ext = [ 'ico', 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'css', 'zip', 'rar', 'ttf' ] special_ext = ['doc', 'docx', 'xls', 'xlsx', 'csv'] if not isinstance(start_url, Url): start_url = Url(start_url) start_url.parent_url = 'https://www.baidu.com' self._task_queue.append((start_url, 0)) # 先写一个完整的请求—响应—解析—更新的过称,然后循环 while len(self._task_queue) != 0: base_url, current_depth = self._task_queue.popleft() if current_depth == self._probe_depth: break # 特殊后缀,如可下载文件则跳过检测,但输出url地址 if base_url.file_ext in special_ext: print('Downloadable Files: {}'.format(base_url.canonical_url)) continue # 两次过滤,一次在任务队列弹出时,另一次在添加入任务队列时。 if base_url.file_ext in ignore_file_ext: continue # send request self._history.append(base_url) wheel = Wheel(base_url, 'get', headers=headers) # get response ''' except AttributeError as ext: print("Response parsing error. Please check the url:{}".format(base_url.original_url)) traceback.print_exc() continue ''' try: reply = wheel.send() except Exception: # if requests fail, we should ignore the following parsing process. print('Connection errors happened in: {}'.format( base_url.original_url)) self._failure_req.append(base_url) continue # 当前只处理正常返回200的页面,而不管301、302等重定向页面 if reply.code != 200 or reply.body == '': continue # get the dirty Urls, so it's time to add the father url here try: Urls = getURL_with_xpath(reply.body, base_url) except AttributeError as ext: print(ext, ' and the source is: {}'.format(reply.req_url)) continue # filter out useful urls newUrls = sanitize_urls(Urls) # update the tasks and history for url in newUrls: if url not in self._history: self._task_queue.append((url, current_depth + 1)) print("we've searched {} urls, current depth is {}".format( len(self._history), current_depth)) print("there're {} urls left".format( len([x[0] for x in self._task_queue])))
def __init__(self): Wheel.__init__(self, Firm.FORD)
from Car import Car from Body import Body from Engine import Engine from Wheel import Wheel from CarElementDoVisitor import CarElementDoVisitor from CarElementPrintVisitor import CarElementPrintVisitor body = Body() engine = Engine() wheel = Wheel("front") car = Car() visitor1 = CarElementPrintVisitor() visitor2 = CarElementDoVisitor() body.accept(visitor1) engine.accept(visitor1) wheel.accept(visitor1) car.accept(visitor1) body.accept(visitor2) engine.accept(visitor2) wheel.accept(visitor2) car.accept(visitor2)
import pygame from Keyboard import Keyboard from Renderer import Renderer from Wheel import Wheel from Car import Car from NewGround import NewGround from Physics import Vector, Point, Function # init R = Renderer(1000, 500) K = Keyboard() NG = NewGround() ground_display = 500 / R.scale WF = Wheel(NG, 128, -800) # front wheel WB = Wheel(NG, 0, -800) # back wheel C = Car(WB, WF) run = True # main loop while run: R.delay(20) # event handle for event in pygame.event.get(): if event.type == pygame.QUIT: run = False K.check(C)
def _set_wheel(self): self._wheel = Wheel([100, 200, 300, 400, 500]) self._letter_value = 0