How to use __set_clock method in autotest

Best Python code snippet using autotest_python

planner.py

Source:planner.py Github

copy

Full Screen

...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))...

Full Screen

Full Screen

plane_main.py

Source:plane_main.py Github

copy

Full Screen

...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 # 游戏开始...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful