Skip to content

Commit cc98b73

Browse files
committed
formatting
1 parent 1bd1d79 commit cc98b73

File tree

8 files changed

+64
-38
lines changed

8 files changed

+64
-38
lines changed

robot/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
from robot.wrapper import Robot, NoCameraPresent
1212
from robot.greengiant import OUTPUT, INPUT, INPUT_ANALOG, INPUT_PULLUP
13-
from robot.vision import MARKER_ARENA,MARKER_CUBE_WINKIE,MARKER_CUBE_GILLIKIN, MARKER_CUBE_QUADLING,MARKER_CUBE_MUNCHKIN, MARKER_DEFAULT, RoboConUSBCamera
13+
from robot.vision import MARKER_ARENA, MARKER_CUBE_WINKIE, MARKER_CUBE_GILLIKIN, MARKER_CUBE_QUADLING, MARKER_CUBE_MUNCHKIN, MARKER_DEFAULT, RoboConUSBCamera
1414

1515
MINIUM_VERSION = (3, 6)
1616
if sys.version_info <= MINIUM_VERSION:
1717
raise ImportError("Expected python {} but instead got {}".format(
1818
MINIUM_VERSION, sys.version_info))
1919

2020
__all__ = ["Robot", "NoCameraPresent", "OUTPUT", "INPUT", "INPUT_ANALOG",
21-
"INPUT_PULLUP", "MARKER_ARENA","MARKER_CUBE_WINKIE","MARKER_CUBE_GILLIKIN", "MARKER_CUBE_QUADLING","MARKER_CUBE_MUNCHKIN", "MARKER_DEFAULT"]
21+
"INPUT_PULLUP", "MARKER_ARENA", "MARKER_CUBE_WINKIE", "MARKER_CUBE_GILLIKIN", "MARKER_CUBE_QUADLING", "MARKER_CUBE_MUNCHKIN", "MARKER_DEFAULT"]

robot/calibrate_camera.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
KD = 5
1515
K_READING_COUNTS = 0.5
1616

17+
1718
def _get_reading():
1819
while True:
1920
try:
2021
return R.see()[0].dist
2122
except IndexError:
2223
print("saw nothing")
2324

25+
2426
def _get_reading_number(error):
2527
result = int(K_READING_COUNTS / error)
2628
result = abs(result)
@@ -30,6 +32,7 @@ def _get_reading_number(error):
3032
result = 6
3133
return result
3234

35+
3336
R = robot.Robot()
3437
result = {}
3538

@@ -57,10 +60,12 @@ def _get_reading_number(error):
5760
previous_error = error
5861
error = TARGET - average_dist
5962

60-
print("Tried: {} got dist {} error: {}".format(value, average_dist, error))
61-
print(" Max: {} min: {} range: {}".format(max(dists), min(dists), max(dists) - min(dists)))
63+
print("Tried: {} got dist {} error: {}".format(
64+
value, average_dist, error))
65+
print(" Max: {} min: {} range: {}".format(
66+
max(dists), min(dists), max(dists) - min(dists)))
6267
print(" P = {} reading_counts {}".format(error * KP, reading_counts))
6368

6469
result[res] = (value, value)
6570

66-
pprint.pprint(result)
71+
pprint.pprint(result)

robot/cytron.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def __init__(self, max_motor_voltage):
4747

4848
# because we care about heating effects in the motors, we have to scale by
4949
# the square of the ratio
50-
self.power_scaling_factor = (max_motor_voltage / _MAX_OUTPUT_VOLTAGE) ** 2
50+
self.power_scaling_factor = (
51+
max_motor_voltage / _MAX_OUTPUT_VOLTAGE) ** 2
5152

5253
self._percentages = [0, 0]
5354
self._dir = [_DIR_PIN_1, _DIR_PIN_2]
@@ -65,7 +66,8 @@ def __init__(self, max_motor_voltage):
6566
def __getitem__(self, index):
6667
"""Returns the current PWM value in RC units. Adds a sign to represent"""
6768
if index not in (1, 2):
68-
raise IndexError(f"motor index must be in (1,2) but instead got {index}")
69+
raise IndexError(
70+
f"motor index must be in (1,2) but instead got {index}")
6971

7072
index -= 1
7173
return self._percentages[index]
@@ -74,7 +76,8 @@ def __setitem__(self, index, percent):
7476
"""Clamps input value, converts from percentage to wiring pi format and
7577
sets a PWM format"""
7678
if index not in (1, 2):
77-
raise IndexError(f"motor index must be in (1,2) but instead got {index}")
79+
raise IndexError(
80+
f"motor index must be in (1,2) but instead got {index}")
7881

7982
index -= 1
8083
percent = clamp(percent, -100, 100)

robot/greengiant.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""A set of constants and interfaces for controlling the green giant over I2C"""
22

3+
34
def clamp(value, smallest, largest):
45
"""Return `value` if in bounds else returns the exceeded bound"""
56
return max(smallest, min(value, largest))
67

8+
79
def _decrement_pin_index(index):
810
"""Validate then decrement the pin index.
911
@@ -17,6 +19,7 @@ def _decrement_pin_index(index):
1719

1820
return index
1921

22+
2023
OUTPUT = "OUTPUT"
2124
INPUT = "INPUT"
2225
INPUT_ANALOG = "INPUT_ANALOG"
@@ -104,6 +107,7 @@ def read_high_low_data(bus, high_addr, low_addr):
104107
class GreenGiantInternal(object):
105108
"""Intertions for use with the user
106109
not intended to be part of the robot API"""
110+
107111
def __init__(self, bus):
108112
self._bus = bus
109113
self.enabled_12v = False
@@ -151,7 +155,8 @@ def mode(self):
151155
def mode(self, mode):
152156
self._mode = mode
153157
mask = _GG_GPIO_MASKS[mode]
154-
self._bus.write_byte_data(_GG_I2C_ADDR, _GG_CONTROL_START + self._index, mask)
158+
self._bus.write_byte_data(
159+
_GG_I2C_ADDR, _GG_CONTROL_START + self._index, mask)
155160

156161
@property
157162
def digital(self):
@@ -168,7 +173,8 @@ def digital(self, value):
168173
f"requiring pin_mode {OUTPUT} but instead pin_mode is "
169174
f"{self._mode}")
170175

171-
self._bus.write_byte_data(_GG_I2C_ADDR, _GG_DIGITAL_START + self._index, int(value))
176+
self._bus.write_byte_data(
177+
_GG_I2C_ADDR, _GG_DIGITAL_START + self._index, int(value))
172178

173179
@property
174180
def analog(self):
@@ -182,9 +188,10 @@ def analog(self):
182188
raw_adc_max = 0xFFC0
183189

184190
analog_addr = _GG_ANALOG_START + (self._index * 2)
185-
raw_adc_value = read_high_low_data(self._bus, analog_addr, analog_addr + 1)
191+
raw_adc_value = read_high_low_data(
192+
self._bus, analog_addr, analog_addr + 1)
186193

187-
return (raw_adc_value / raw_adc_max) * self._adc_max
194+
return (raw_adc_value / raw_adc_max) * self._adc_max
188195

189196
def __bool__(self):
190197
"""Return a bool if in a digital mode or a float if in an analogue"""
@@ -197,6 +204,7 @@ def __bool__(self):
197204

198205
class GreenGiantGPIOPinList():
199206
"""A list of pins indexed from 1"""
207+
200208
def __init__(self, bus, adc_max):
201209
self._list = [GreenGiantGPIOPin(bus, i, adc_max)
202210
for i in range(4)]
@@ -211,6 +219,7 @@ def __setitem__(self, index, value):
211219

212220
class GreenGiantPWM():
213221
"""An object implementing a descriptor protocol to control the servos"""
222+
214223
def __init__(self, bus):
215224
self._bus = bus
216225

robot/log.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import logging
44

55
# Python 2.6's logging doesn't have NullHandler
6+
7+
68
class NullHandler(logging.Handler):
79
def emit(self, record):
810
pass
911

12+
1013
# Default to sending our log messages nowhere
1114
logger = logging.getLogger("sr")
1215
logger.addHandler(NullHandler())

robot/reset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import robot.cytron as c
1414
import robot.greengiant as gg
1515

16+
1617
def reset():
1718
"""Resets the robot components to their default state.
1819
Used by Shepherd when the Stop button is pressed.

robot/vision.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import robot.apriltags3 as AT
2121

2222

23-
2423
# TODO put all of the paths together
2524
IMAGE_TO_SHEPHERD_PATH = "/home/pi/shepherd/shepherd/static/image.jpg"
2625

@@ -101,10 +100,10 @@ class Capture(NamedTuple):
101100

102101
# MARKER_: Marker Data Types
103102
# MARKER_TYPE_: Marker Types
104-
MARKER_TYPE, MARKER_OFFSET, MARKER_COUNT, MARKER_SIZE, MARKER_COLOUR,MARKER_SPECIES = (
105-
'type', 'offset', 'count', 'size', 'colour','species')
106-
MARKER_ARENA,MARKER_CUBE_WINKIE,MARKER_CUBE_GILLIKIN,MARKER_CUBE_QUADLING,MARKER_CUBE_MUNCHKIN,MARKER_DEFAULT = "arena", "winkie", "gillikin","quadling","munchkin","default"
107-
ARENA,CUBE = "arena","cube"
103+
MARKER_TYPE, MARKER_OFFSET, MARKER_COUNT, MARKER_SIZE, MARKER_COLOUR, MARKER_SPECIES = (
104+
'type', 'offset', 'count', 'size', 'colour', 'species')
105+
MARKER_ARENA, MARKER_CUBE_WINKIE, MARKER_CUBE_GILLIKIN, MARKER_CUBE_QUADLING, MARKER_CUBE_MUNCHKIN, MARKER_DEFAULT = "arena", "winkie", "gillikin", "quadling", "munchkin", "default"
106+
ARENA, CUBE = "arena", "cube"
108107
# NOTE Data about each marker
109108
# MARKER_OFFSET: Offset
110109
# MARKER_COUNT: Number of markers of type that exist
@@ -352,7 +351,6 @@ def __init__(self,
352351
bounding_box=True,
353352
usb_stick=False,
354353
send_to_sheep=False,
355-
356354
save=True):
357355

358356
super(PostProcessor, self).__init__()
@@ -402,12 +400,12 @@ def _draw_bounding_box(self, frame, detections):
402400
polygon_is_closed,
403401
colour,
404402
thickness=self._bounding_box_thickness*3)
405-
else:
406-
cv2.polylines(frame,
407-
[integer_corners],
408-
polygon_is_closed,
409-
colour,
410-
thickness=self._bounding_box_thickness)
403+
else:
404+
cv2.polylines(frame,
405+
[integer_corners],
406+
polygon_is_closed,
407+
colour,
408+
thickness=self._bounding_box_thickness)
411409

412410
return frame
413411

@@ -484,7 +482,7 @@ def __init__(self,
484482
self.camera = camera
485483

486484
self.frames_to_postprocess = queue.Queue(max_queue_size)
487-
self.post_processor = PostProcessor(self,zone = self.zone)
485+
self.post_processor = PostProcessor(self, zone=self.zone)
488486

489487
def stop(self):
490488
"""Cleanup to prevent leaking hardware resource"""

robot/wrapper.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class to their respecitve classes
2727
# this boot cycle. This is to highlight weird behaviour in the arena
2828
COPY_STAT_FILE = "/tmp/usb_file_uploaded"
2929

30+
3031
def setup_logging(level):
3132
"""Display the just the message when logging events
3233
Sets the logging level to `level`"""
@@ -43,6 +44,7 @@ def setup_logging(level):
4344

4445
class NoCameraPresent(Exception):
4546
"""Camera not connected."""
47+
4648
def __str__(self):
4749
return "No camera found."
4850

@@ -73,7 +75,8 @@ def __init__(self,
7375
# check if copy stat file exists and read it if it does then delete it
7476
try:
7577
with open(COPY_STAT_FILE, "r") as f:
76-
_logger.info("Robot code copied %s from USB\n", f.read().strip())
78+
_logger.info("Robot code copied %s from USB\n",
79+
f.read().strip())
7780
os.remove(COPY_STAT_FILE)
7881
except IOError:
7982
pass
@@ -92,8 +95,8 @@ def __init__(self,
9295
self.mode = start_data['mode']
9396
else:
9497
_logger.warning("Robot initalized but usercode running before"
95-
"`robot.wait_start`. Robot will not wait for the "
96-
"start button until `robot.wait_start` is called.")
98+
"`robot.wait_start`. Robot will not wait for the "
99+
"start button until `robot.wait_start` is called.")
97100

98101
def subsystem_init(self, camera):
99102
"""Allows for initalisation of subsystems after instansating `Robot()`
@@ -117,7 +120,6 @@ def subsystem_init(self, camera):
117120

118121
self._vision = vision.Vision(self.zone, camera=self.camera)
119122

120-
121123
def report_hardware_status(self):
122124
"""Print out a nice log message at the start of each robot init with
123125
the hardware status"""
@@ -132,13 +134,14 @@ def report_hardware_status(self):
132134
"changing for a charged battery")
133135

134136
if self._gg_version != 3:
135-
self._warnings.append("Green Giant version not 3 but instead {}".format(self._gg_version))
136-
137-
camera_type_str = "Camera: {}".format(self.camera.__class__.__name__)
137+
self._warnings.append(
138+
"Green Giant version not 3 but instead {}".format(self._gg_version))
138139

140+
camera_type_str = "Camera: {}".format(
141+
self.camera.__class__.__name__)
139142

140-
#Adds the secret poem every now and then!
141-
if random.randint(0,100) == 1:
143+
# Adds the secret poem every now and then!
144+
if random.randint(0, 100) == 1:
142145
_logger.info("Today your task is a challenging one")
143146
_logger.info("Gifts for the wizard and deliveries to run")
144147
_logger.info("But due to the unfortunate timing you can not go")
@@ -147,14 +150,17 @@ def report_hardware_status(self):
147150
_logger.info("Starting in your home (where ever it is found)")
148151
_logger.info("Then taking gifts from your robots zone ")
149152
_logger.info("Delivering it to the wizard on its own")
150-
_logger.info("To the road is good and to the emerald palace is ideal ")
151-
_logger.info("And if in another country you get some but a point they will steal")
153+
_logger.info(
154+
"To the road is good and to the emerald palace is ideal ")
155+
_logger.info(
156+
"And if in another country you get some but a point they will steal")
152157
_logger.info("There are many things that are to be considered")
153158
_logger.info("But remember to bring your gifts for the wizard")
154159

155160
# print report of hardware
156161
_logger.info("------HARDWARE REPORT------")
157-
_logger.info("Time: %s", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
162+
_logger.info("Time: %s", datetime.now().strftime(
163+
'%Y-%m-%d %H:%M:%S'))
158164
_logger.info("Patch Version: 0")
159165
_logger.info(battery_str)
160166
_logger.info("ADC Max: %.2fv", self._adc_max)
@@ -267,7 +273,8 @@ def wait_start(self):
267273

268274
if self.startfifo is None:
269275
self._start_pressed = True
270-
_logger.info("No startfifo so using defaults (Zone: {})".format(self.zone))
276+
_logger.info(
277+
"No startfifo so using defaults (Zone: {})".format(self.zone))
271278
return
272279

273280
blink_thread = threading.Thread(target=self._wait_start_blink)

0 commit comments

Comments
 (0)