Best Python code snippet using autotest_python
planner.py
Source: planner.py
...26 self.laser_data_view_right_ = None27 self.loop_ = self.create_timer(self.timer_, self.__loop_callback_)28 def __get_clock(self):29 return self.clock_30 def __set_clock(self, value):31 self.clock_ = value32 def __clock_sleep(self):33 time.sleep(self.__get_clock())34 def __loop_callback_(self):35 """planner loop"""36 self.__clock_sleep()37 self.laser_data_front_, \38 self.laser_data_left_, \39 self.laser_data_right_, \40 self.laser_data_view_left_, \41 self.laser_data_view_front_, \42 self.laser_data_view_right_ = self.__laser_matrix_processing()43 self.__mode_supervisor()44 self.__mov_supervisor()45 self.__set_prev_mode()46 self.__log()47 def __laser_matrix_processing(self):48 """get laser data from node"""49 return [self.node_.sensor.laser_scan_ranges_front(),50 self.node_.sensor.laser_scan_ranges_left(),51 self.node_.sensor.laser_scan_ranges_right(),52 self.node_.sensor.laser_scan_ranges_front()[:30],53 self.node_.sensor.laser_scan_ranges_front()[31:59],54 self.node_.sensor.laser_scan_ranges_front()[60:]]55 def __mode_supervisor(self):56 self.__view_processing()57 self.mode_ = self.__mode_selector()58 def __view_processing(self):59 self.collision_array_ = [min(self.laser_data_view_left_),60 min(self.laser_data_view_front_),61 min(self.laser_data_view_right_)]62 self.collision_array_min_index_ = \63 self.collision_array_.index(min(self.collision_array_))64 self.collision_array_max_index_ = \65 self.collision_array_.index(max(self.collision_array_))66 def __mode_selector(self):67 if self.prev_mode_ != 'forward' and \68 self.collision_array_[1] > SEC_THRESHOLD and \69 self.collision_array_[0] > NEAR_THRESHOLD and \70 self.collision_array_[2] > NEAR_THRESHOLD:71 return 'forward'72 if self.prev_mode_ == 'forward' and \73 self.collision_array_[1] > SEC_THRESHOLD and \74 self.collision_array_[0] > NEAR_THRESHOLD and \75 self.collision_array_[2] > NEAR_THRESHOLD:76 return 'forward'77 if self.prev_mode_ == 'forward' and \78 (self.collision_array_[1] <= SEC_THRESHOLD or \79 self.collision_array_[0] <= NEAR_THRESHOLD or \80 self.collision_array_[2] <= NEAR_THRESHOLD):81 return 'stop'82 if self.prev_mode_ == 'stop':83 if self.collision_array_min_index_ == 0:84 return 'turn_right'85 if self.collision_array_min_index_ == 2:86 return 'turn_left'87 if self.collision_array_min_index_ == 1:88 if self.collision_array_max_index_ == 0:89 return 'turn_left'90 if self.collision_array_max_index_ == 2:91 return 'turn_right'92 if self.prev_mode_ == 'turn_left' or self.prev_mode_ == 'turn_right':93 if self.collision_array_[1] > SEC_THRESHOLD:94 return 'forward'95 return self.prev_mode_96 sys.exit('unknown dir')97 def __mov_supervisor(self):98 if self.mode_ == 'forward' and self.prev_mode_ != 'forward':99 self.__forward_mode()100 if self.mode_ == 'stop' and self.prev_mode_ != 'stop':101 self.__stop_mode()102 if self.mode_ == 'turn_left' and self.prev_mode_ != 'turn_left':103 self.__turn_left_routine()104 if self.mode_ == 'turn_right' and self.prev_mode_ != 'turn_right':105 self.__turn_right_routine()106 def __set_prev_mode(self):107 self.prev_mode_ = self.mode_108 def __forward_mode(self):109 self.__set_clock(FORWARD_CLOCK)110 self.__forward_routine()111 def __forward_routine(self,):112 self.node_.movement.go_forward()113 def __stop_mode(self):114 self.__set_clock(STOP_CLOCK)115 self.__stop_routine()116 def __stop_routine(self):117 self.node_.movement.stop()118 def __turn_left_routine(self):119 self.node_.movement.turn_left()120 def __turn_right_routine(self):121 self.node_.movement.turn_right()122 def __log(self):123 """logger"""124 self.get_logger().info('--------------------')125 self.get_logger().info(' prev mode: ' + str(self.prev_mode_))126 self.get_logger().info(' mode: ' + str(self.mode_))127 self.get_logger().info(' left: ' + str(self.collision_array_[0]) + ' ' +128 str(self.collision_array_[0] > NEAR_THRESHOLD))...
plane_main.py
Source: plane_main.py
...17 def star_game(self):18 print("游æå¼å§...")19 while True:20 # 1.设置å·æ°é¢ç21 self.__set_clock()22 # 2.äºä»¶çå¬23 self.__event_handler()24 # 3.碰ææ£æµ25 self.__check_collide()26 # 4.æ´æ°ãç»å¶ç²¾çµç»27 self.__update_sprites()28 # 5.æ´æ°æ¾ç¤º29 pygame.display.update()30 def __creat_sprites(self):31 # å建è影精çµåç²¾çµç»32 bg1 = ps.BackGround()33 bg2 = ps.BackGround(True)34 # bg2.rect.y = -bg2.rect.height35 self.back_group = pygame.sprite.Group(bg1, bg2)36 # å建ææºçç²¾çµç»37 self.enemy_group = pygame.sprite.Group()38 # å建è±éçç²¾çµåç²¾çµç»39 self.hero = ps.Hero()40 self.hero_group = pygame.sprite.Group(self.hero)41 def __event_handler(self):42 for event in pygame.event.get():43 if event.type == pygame.QUIT:44 PlaneGame.__game_over()45 elif event.type == ps.CREAT_ENEMY_EVENT:46 # 1.å建ææºç²¾çµ47 enemy = ps.Enemy()48 # 2.æ·»å è³ææºç²¾çµç»49 self.enemy_group.add(enemy)50 elif event.type == ps.HERO_FIRE_EVENT:51 self.hero.fire()52 # é®çäºä»¶ æ¹æ³ä¸ï¼53 # elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:54 # print("åå³ç§»å¨")55 # é®çäºä»¶ï¼æ¹æ³äºï¼56 keys_pressed = pygame.key.get_pressed()57 # å¤æå
ç»ä¸å¯¹åºçæé®çç´¢å¼å¼ 158 if keys_pressed[pygame.K_RIGHT]:59 # print('åå³ç§»å¨')60 self.hero.speed = 261 elif keys_pressed[pygame.K_LEFT]:62 self.hero.speed = -263 else:64 self.hero.speed = 065 def __check_collide(self):66 # 1.åå¼¹æ§æ¯ææº67 pygame.sprite.groupcollide(self.hero.bullet_group, self.enemy_group, True, True)68 # 2.ææºæ§æ¯è±é69 enemies = pygame.sprite.spritecollide(self.hero, self.enemy_group, True)70 if len(enemies):71 self.hero.kill()72 PlaneGame.__game_over()73 def __update_sprites(self):74 self.back_group.update()75 self.back_group.draw(self.screen)76 self.enemy_group.update()77 self.enemy_group.draw(self.screen)78 self.hero_group.update()79 self.hero_group.draw(self.screen)80 self.hero.bullet_group.update()81 self.hero.bullet_group.draw(self.screen)82 def __set_clock(self):83 self.clock.tick(ps.FRAME_PER_SEC)84 @staticmethod85 def __game_over():86 print("游æç»æ")87 pygame.quit()88 exit()89if __name__ == '__main__':90 # å建游æ对象91 game = PlaneGame()92 # 游æå¼å§...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!