Skip to content

Sourcery Starbot ⭐ refactored DavidePatria/tello_driver - #1

Open
SourceryAI wants to merge 1 commit into
DavidePatria:masterfrom
SourceryAI:master
Open

SourceryAI wants to merge 1 commit into
DavidePatria:masterfrom
SourceryAI:master

Conversation

@SourceryAI

Copy link
Copy Markdown

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 master branch, then run:

git fetch https://github.com/sourcery-ai-bot/tello_driver master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment thread scripts/teleop_tello.py
else:
self.timeout = None

self.timeout = 1.0 / rate if rate != 0.0 else None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PublishThread.__init__ refactored with the following changes:

Comment thread scripts/teleop_tello.py
Comment on lines -113 to +112
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PublishThread.wait_for_subscribers refactored with the following changes:

Comment thread scripts/teleop_tello.py
Comment on lines -170 to +166
if rlist:
key = sys.stdin.read(1)
else:
key = ''
key = sys.stdin.read(1) if rlist else ''

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getKey refactored with the following changes:

Comment thread src/3
Comment on lines -52 to +54
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')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function notify_cmd_success refactored with the following changes:

Comment thread src/3
break
except BaseException as err:
rospy.logerr('fgrab: pyav stream failed - %s' % str(err))
rospy.logerr(f'fgrab: pyav stream failed - {str(err)}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TelloNode.framegrabber_loop refactored with the following changes:

Comment thread src/test.py
Comment on lines -18 to -77
# 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()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

This removes the following comments ( why? ):

# Test raw video
# Test video decoding
# Test flying

Comment thread src/test_h264_sub.py
Comment on lines -24 to +25
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]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function StandaloneVideoStream.read refactored with the following changes:

data = self.udp.recv(2048)
if not data:
print('! Got empty from recv: %s' % str(data))
print(f'! Got empty from recv: {str(data)}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TelloDriver._listener_loop refactored with the following changes:

continue
elif line.find('phy#') == 0:
phyid = 'phy'+line.strip()[4:]
phyid = f'phy{line.strip()[4:]}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 19-19 refactored with the following changes:

Comment thread wifi_docker_proxy/go.py
Comment on lines -129 to +151
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],
)
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function dispatcher refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant