Sourcery Starbot ⭐ refactored DavidePatria/tello_driver - #1
SourceryAI wants to merge 1 commit into
Conversation
| else: | ||
| self.timeout = None | ||
|
|
||
| self.timeout = 1.0 / rate if rate != 0.0 else None |
There was a problem hiding this comment.
Function PublishThread.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| print("Waiting for subscriber to connect to {}".format(self.publisher.name)) | ||
| print(f"Waiting for subscriber to connect to {self.publisher.name}") | ||
| rospy.sleep(0.5) | ||
| i += 1 | ||
| i = i % 5 | ||
| i %= 5 |
There was a problem hiding this comment.
Function PublishThread.wait_for_subscribers refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Replace assignment with augmented assignment (
aug-assign)
| if rlist: | ||
| key = sys.stdin.read(1) | ||
| else: | ||
| key = '' | ||
| key = sys.stdin.read(1) if rlist else '' |
There was a problem hiding this comment.
Function getKey refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| rospy.loginfo('%s command executed' % cmd) | ||
| rospy.loginfo(f'{cmd} command executed') | ||
| else: | ||
| rospy.logwarn('%s command failed' % cmd) | ||
| rospy.logwarn(f'{cmd} command failed') |
There was a problem hiding this comment.
Function notify_cmd_success refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| break | ||
| except BaseException as err: | ||
| rospy.logerr('fgrab: pyav stream failed - %s' % str(err)) | ||
| rospy.logerr(f'fgrab: pyav stream failed - {str(err)}') |
There was a problem hiding this comment.
Function TelloNode.framegrabber_loop refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| # Test raw video | ||
| if True: | ||
| drone1.start_video() | ||
| while True: | ||
| time.sleep(1.0) | ||
|
|
||
| # Test video decoding | ||
| if False: | ||
| import av | ||
| import cv2 | ||
| import numpy | ||
|
|
||
| container = av.open(drone1.get_video_stream()) | ||
| for frame in container.decode(video=0): | ||
| image = cv2.cvtColor(numpy.array( | ||
| frame.to_image()), cv2.COLOR_RGB2BGR) | ||
| cv2.imshow('Frame', image) | ||
| key = cv2.waitKey(1) | ||
| if key and chr(key) in ('q', 'Q', 'x', 'X'): | ||
| break | ||
|
|
||
| # Test flying | ||
| if False: | ||
| time.sleep(2.0) | ||
| drone1.takeoff() | ||
| time.sleep(3.5) | ||
|
|
||
| drone1.set_vspeed(1.0) | ||
| time.sleep(0.6) | ||
| drone1.set_vspeed(0.0) | ||
|
|
||
| time.sleep(2.0) | ||
|
|
||
| drone1.set_pitch(0.4) | ||
| drone1.set_yaw(1.0) | ||
| time.sleep(0.5) | ||
| drone1.set_pitch(0.0) | ||
| drone1.set_yaw(0.0) | ||
|
|
||
| time.sleep(2.0) | ||
|
|
||
| drone1.flip(1) | ||
|
|
||
| time.sleep(2.0) | ||
|
|
||
| drone1.set_vspeed(-0.5) | ||
| time.sleep(0.6) | ||
| drone1.set_vspeed(0.0) | ||
|
|
||
| drone1.start_video() | ||
| while True: | ||
| time.sleep(1.0) | ||
|
|
||
| drone1.palm_land() | ||
| time.sleep(3.0) | ||
|
|
||
| except BaseException: | ||
| traceback.print_exc() | ||
| finally: | ||
| if False: | ||
| drone1.reset_cmd_vel() | ||
| drone1.land() |
There was a problem hiding this comment.
Function test refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
This removes the following comments ( why? ):
# Test raw video
# Test video decoding
# Test flying
| while 0 < len(self.queue) and len(data) + len(self.queue[0]) < size: | ||
| data = data + self.queue[0] | ||
| while len(self.queue) > 0 and len(data) + len(self.queue[0]) < size: | ||
| data += self.queue[0] |
There was a problem hiding this comment.
Function StandaloneVideoStream.read refactored with the following changes:
- Ensure constant in comparison is on the right (
flip-comparison) - Replace assignment with augmented assignment (
aug-assign)
| data = self.udp.recv(2048) | ||
| if not data: | ||
| print('! Got empty from recv: %s' % str(data)) | ||
| print(f'! Got empty from recv: {str(data)}') |
There was a problem hiding this comment.
Function TelloDriver._listener_loop refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| continue | ||
| elif line.find('phy#') == 0: | ||
| phyid = 'phy'+line.strip()[4:] | ||
| phyid = f'phy{line.strip()[4:]}' |
There was a problem hiding this comment.
Lines 19-19 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| cmds.append(['docker', 'run', | ||
| '-d', '--rm', '--privileged', | ||
| '--env', 'DRONE_AP='+drone_ap, | ||
| '--env', 'WIFI_DEV='+wifi_dev, | ||
| '--env', 'LOCAL_CMD_CLIENT_PORT='+local_cmd_client_port, | ||
| '--env', 'LOCAL_VID_SERVER_PORT='+local_vid_server_port, | ||
| '--name', container_name, | ||
| image_name]) | ||
| cmds.append(['./setup_network.sh', container_name, wifi_dev]) | ||
| cmds.extend( | ||
| ( | ||
| [ | ||
| 'docker', | ||
| 'run', | ||
| '-d', | ||
| '--rm', | ||
| '--privileged', | ||
| '--env', | ||
| f'DRONE_AP={drone_ap}', | ||
| '--env', | ||
| f'WIFI_DEV={wifi_dev}', | ||
| '--env', | ||
| 'LOCAL_CMD_CLIENT_PORT=' + local_cmd_client_port, | ||
| '--env', | ||
| 'LOCAL_VID_SERVER_PORT=' + local_vid_server_port, | ||
| '--name', | ||
| container_name, | ||
| image_name, | ||
| ], | ||
| ['./setup_network.sh', container_name, wifi_dev], | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Function dispatcher refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run: