Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up for python 3 #1130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions donkeycar/benchmarks/tub.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def benchmark():
contents = record_file.read_text()
if contents:
contents = json.loads(contents)
print('Record %s' % contents)
print(f'Record {contents}')


if __name__ == "__main__":
timer = timeit.Timer(benchmark)
time_taken = timer.timeit(number=1)
print('Time taken %s seconds' % time_taken)
print(f'Time taken {time_taken} seconds')
print('\nDone.')
6 changes: 3 additions & 3 deletions donkeycar/benchmarks/tub_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def benchmark():

deletions = np.random.randint(0, write_count, 100)
tub.delete_records(deletions)

for record in tub:
print('Record %s' % record)
print(f'Record {record}')

tub.close()


if __name__ == "__main__":
timer = timeit.Timer(benchmark)
time_taken = timer.timeit(number=1)
print('Time taken %s seconds' % time_taken)
print(f'Time taken {time_taken} seconds')
print('\nDone.')
12 changes: 6 additions & 6 deletions donkeycar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@


class Config:

def from_pyfile(self, filename):
d = types.ModuleType('config')
d.__file__ = filename
try:
with open(filename, mode='rb') as config_file:
exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
except IOError as e:
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
e.strerror = f'Unable to load configuration file ({e.strerror})'
raise
self.from_object(d)
return True

def from_object(self, obj):
for key in dir(obj):
if key.isupper():
setattr(self, key, getattr(obj, key))

def __str__(self):
result = []
for key in dir(self):
Expand All @@ -44,7 +44,7 @@ def show(self):


def load_config(config_path=None, myconfig="myconfig.py"):

if config_path is None:
import __main__ as main
main_path = os.path.dirname(os.path.realpath(main.__file__))
Expand All @@ -53,7 +53,7 @@ def load_config(config_path=None, myconfig="myconfig.py"):
local_config = os.path.join(os.path.curdir, 'config.py')
if os.path.exists(local_config):
config_path = local_config

logger.info(f'loading config file: {config_path}')
cfg = Config()
cfg.from_pyfile(config_path)
Expand Down
2 changes: 1 addition & 1 deletion donkeycar/contrib/robohat/code-robocarstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def main():
break
last_input = time.monotonic()

logger.debug("Read from UART: %s" % (byte))
logger.debug(f"Read from UART: {byte}")

# if data is recieved, check if it is the end of a stream
if(byte == b'\r'):
Expand Down
4 changes: 2 additions & 2 deletions donkeycar/contrib/robohat/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def main():

if DEBUG:
logger.info("Get: steering=%i, throttle=%i" % (int(steering.value), int(throttle.value)))

if(USB_SERIAL):
# simulator USB
print("%i, %i" % (int(steering.value), int(throttle.value)))
Expand All @@ -146,7 +146,7 @@ def main():
last_input = time.monotonic()

if (DEBUG):
logger.debug("Read from UART: %s" % (byte))
logger.debug(f"Read from UART: {byte}")

# if data is recieved, check if it is the end of a stream
if(byte == b'\r'):
Expand Down
3 changes: 1 addition & 2 deletions donkeycar/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'''
from .la import Vec2

class LineSeg2d(object):
class LineSeg2d():

def __init__(self, x1, y1, x2, y2):
a = Vec2(x1, y1)
Expand Down Expand Up @@ -34,4 +34,3 @@ def cross_track_error(self, vec2_pt):
if err_vec.cross(self.ray) < 0.0:
sign = -1.
return mag * sign

14 changes: 7 additions & 7 deletions donkeycar/gym/gym_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ class DonkeyRealEnv(gym.Env):
def __init__(self, time_step=0.05, frame_skip=2):

print("starting DonkeyGym env")

try:
donkey_name = str(os.environ['DONKEY_NAME'])
except:
except Exception:
donkey_name = 'my_robot1234'
print("No DONKEY_NAME environment var. Using default:", donkey_name)

try:
mqtt_broker = str(os.environ['DONKEY_MQTT_BROKER'])
except:
except Exception:
mqtt_broker = "iot.eclipse.org"
print("No DONKEY_MQTT_BROKER environment var. Using default:", mqtt_broker)

# start controller
self.controller = DonkeyRemoteContoller(donkey_name=donkey_name, mqtt_broker=mqtt_broker)

# steering and throttle
self.action_space = spaces.Box(low=np.array([self.STEER_LIMIT_LEFT, self.THROTTLE_MIN]),
high=np.array([self.STEER_LIMIT_RIGHT, self.THROTTLE_MAX]), dtype=np.float32 )
Expand All @@ -61,10 +61,10 @@ def __init__(self, time_step=0.05, frame_skip=2):

# wait until loaded
self.controller.wait_until_connected()


def close(self):
self.controller.quit()
self.controller.quit()

def step(self, action):
for i in range(self.frame_skip):
Expand Down
7 changes: 2 additions & 5 deletions donkeycar/gym/remote_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class DonkeyRemoteContoller:
def __init__(self, donkey_name, mqtt_broker, sensor_size=(120, 160, 3)):
self.camera_sub = MQTTValueSub("donkey/%s/camera" % donkey_name, broker=mqtt_broker)
self.controller_pub = MQTTValuePub("donkey/%s/controls" % donkey_name, broker=mqtt_broker)
self.camera_sub = MQTTValueSub(f"donkey/{donkey_name}/camera", broker=mqtt_broker)
self.controller_pub = MQTTValuePub(f"donkey/{donkey_name}/controls", broker=mqtt_broker)
self.jpgToImg = JpgToImgArr()
self.sensor_size = sensor_size

Expand All @@ -37,6 +37,3 @@ def observe(self):
jpg = self.camera_sub.run()
self.img = self.jpgToImg.run(jpg)
return self.img



Loading