Best Python code snippet using tempest_python
hardware.py
Source:hardware.py
...24 self._enable_camera = camera25 def connect(self, address, port=11311):26 self._uri = "http://{}:{}".format(address, port)27 self._irs_values = [0.0 for _ in range(8)]28 self._set_env()29 rospy.init_node("robobo_demo")30 # Service Proxys31 self._move_srv = rospy.ServiceProxy(HardwareRobobo.MOVE_WHEELS_TOPIC, MoveWheels)32 self._pan_tilt_srv = rospy.ServiceProxy(HardwareRobobo.PAN_TILT_TOPIC, MovePanTilt)33 self._emotion_srv = rospy.ServiceProxy(HardwareRobobo.SET_EMOTION_TOPIC, SetEmotion)34 self._talk_srv = rospy.ServiceProxy(HardwareRobobo.TALK_TOPIC, Talk)35 self._leds_srv = rospy.ServiceProxy(HardwareRobobo.SET_LED_TOPIC, SetLed)36 # Sensor Receivers37 self._IRsub = rospy.Subscriber("robot/irs", IRs, self._irs_callback)38 if self._enable_camera:39 self._image_subscribe_front = rospy.Subscriber(HardwareRobobo.IMAGE_TOPIC, CompressedImage, self._camera_callback_front, queue_size=1)40 self._receiving_image_front = None41 return self42 def _set_env(self):43 os.environ['ROS_MASTER_URI'] = self._uri44 def spin(self):45 self._set_env()46 rospy.spin()47 def set_emotion(self, emotion):48 self._set_env()49 self._emotion_srv(String(emotion))50 def move(self, left_speed, right_speed, millis, blockid=0):51 """52 Move the robot wheels for `millis` time53 Arguments54 left_speed: speed of the left wheel. Range: 0-10055 right_speed: speed of the right wheel. Range: 0-10056 millis: how many millisecond to move the robot57 """58 self._set_env()59 self._move_srv(Int8(left_speed), Int8(right_speed), Int32(millis), Int16(blockid))60 time.sleep(millis/1000.0)61 62 def talk(self, message):63 self._set_env()64 self._talk_srv(String(message))65 def set_led(self, selector, color):66 self._set_env()67 self._leds(String(selector), String(color))68 69 def read_irs(self):70 """71 Returns sensor readings: [backR, backC, backL, frontRR, frontR, frontC, frontL, frontLL]72 """73 return self._irs_values74 def _irs_callback(self, ros_data):75 self._irs_values = [76 ros_data.BackR.range,77 ros_data.BackC.range,78 ros_data.BackL.range,79 ros_data.FrontRR.range,80 ros_data.FrontR.range,81 ros_data.FrontC.range,82 ros_data.FrontL.range,83 ros_data.FrontLL.range84 ]85 # print(self._irs_values)86 def _camera_callback_front(self, ros_data):87 if self._receiving_image_front is None:88 #### direct conversion to CV2 ####89 np_arr = np.fromstring(ros_data.data, np.uint8)90 image_np = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)91 # save result in memory (FLIP NEEDED [only front camera?])92 self._receiving_image_front = cv2.flip(image_np, 1)93 def get_image_front(self):94 if not self._enable_camera:95 raise HardwareRoboboException("Camera is disabled")96 # Retrieve last image from image topic97 #import datetime98 #start = datetime.datetime.now()99 self._receiving_image_front = None100 while self._receiving_image_front is None:101 time.sleep(0.002)102 #print("Image download took {}".format(datetime.datetime.now()-start))103 image = self._receiving_image_front104 self._receiving_image_front = None105 106 return image107 def set_phone_pan(self, pan_position, pan_speed, pan_blockid=1):108 """109 Command the robot to move the smartphone holder in the horizontal (pan) axis.110 This function is asyncronous.111 Arguments112 pan_position: Angle to position the pan at. Range: 11-343.113 pan_speed: Movement speed for the pan mechanism. Range: 0-100.114 pan_blockid: A unique 'blockid' for end-of-movement notification at /robot/unlock/move topic. Must be greater that 0 to move.115 """116 self._set_env()117 self._pan_tilt_srv(Int16(pan_position), Int8(pan_speed), Int16(pan_blockid), Int16(0), Int8(0), Int16(0))118 def set_phone_tilt(self, tilt_position, tilt_speed, tilt_blockid=1):119 """120 Command the robot to move the smartphone holder in the vertical (tilt) axis.121 This function is asyncronous.122 Arguments123 tilt_position: Angle to position the tilt at. Range: 26-109.124 tilt_speed: Movement speed for the tilt mechanism. Range: 0-100.125 tilt_blockid: A unique 'blockid' for end-of-movement notification at /robot/unlock/move topic. Must be greater that 0 to move.126 """127 self._set_env()128 self._pan_tilt_srv(Int16(0), Int8(0), Int16(0), Int16(tilt_position), Int8(tilt_speed), Int16(tilt_blockid))129 def sleep(self, seconds):130 self._set_env()...
env_accessor.py
Source:env_accessor.py
...21 _path_json_opted: str = 'PATH_JSON_OPTED'22 _google_credential: str = 'GOOGLE_APPLICATION_CREDENTIALS'23 def __init__(self):24 dotenv.load_dotenv(self._dotenv_file)25 def _set_env(self, key: str, value: str) -> None:26 os.environ[key] = value27 dotenv.set_key(self._dotenv_file, key, value)28 @property29 def log_mode(self) -> str:30 return decouple.config(self._log_mode)31 @log_mode.setter32 def log_mode(self, value: str):33 self._set_env(self._log_mode, value)34 @property35 def key_to_encrypt(self) -> str:36 return decouple.config(self._key_to_encrypt)37 38 @key_to_encrypt.setter39 def key_to_encrypt(self, value: str):40 self._set_env(self._key_to_encrypt, value)41 @property42 def algorithm_to_encrypt(self) -> str:43 return decouple.config(self._algorithm_to_encrypt)44 @algorithm_to_encrypt.setter45 def algorithm_to_encrypt(self, value: str):46 self._set_env(self._algorithm_to_encrypt, value)47 @property48 def host_database(self) -> str:49 return decouple.config(self._host_database)50 51 @host_database.setter52 def host_database(self, value: str):53 self._set_env(self._host_database, value)54 @property55 def username_database(self) -> str:56 return decouple.config(self._username_database)57 58 @username_database.setter59 def username_database(self, value: str):60 self._set_env(self._username_database, value)61 62 @property63 def password_database(self) -> str:64 return decouple.config(self._password_database)65 @password_database.setter66 def password_database(self, value: str):67 self._set_env(self._password_database, value)68 69 @property70 def database_user(self) -> str:71 return decouple.config(self._database_user)72 @database_user.setter73 def database_user(self, value: str):74 self._set_env(self._database_user, value)75 @property76 def database_dictionary(self) -> str:77 return decouple.config(self._database_dictionary)78 @database_dictionary.setter79 def database_dictionary(self, value: str):80 self._set_env(self._database_dictionary, value)81 @property82 def path_yolov3_names(self) -> str:83 return decouple.config(self._path_yolov3_names)84 @path_yolov3_names.setter85 def path_yolov3_names(self, value: str):86 self._set_env(self._path_yolov3_names, value)87 @property88 def path_yolov3_config(self) -> str:89 return decouple.config(self._path_yolov3_config)90 @path_yolov3_config.setter91 def path_yolov3_config(self, value: str):92 self._set_env(self._path_yolov3_config, value)93 @property94 def path_yolov3_weights(self) -> str:95 return decouple.config(self._path_yolov3_weights)96 @path_yolov3_weights.setter97 def path_yolov3_weights(self, value: str):98 self._set_env(self._path_yolov3_weights, value)99 @property100 def path_json_opted(self) -> str:101 return decouple.config(self._path_json_opted)102 @path_json_opted.setter103 def path_json_opted(self, value: str):104 self._set_env(self._path_json_opted, value)105 @property106 def path_json_definition_all_word(self) -> str:107 return decouple.config(self._path_json_definition_all_word)108 @path_json_definition_all_word.setter109 def path_json_definition_all_word(self, value: str):110 self._set_env(self._path_json_definition_all_word, value)111 @property112 def path_json_definition_common_word(self) -> str:113 return decouple.config(self._path_json_definition_common_word)114 @path_json_definition_common_word.setter115 def path_json_definition_common_word(self, value: str):116 self._set_env(self._path_json_definition_common_word, value)117 @property118 def google_credential(self) -> str:119 return decouple.config(self._google_credential)120 @google_credential.setter121 def google_credential(self, value: str):122 self._set_env(self._google_credential, value)...
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!!