ut-robotics / picr21-team-sauna-madis

0 stars 0 forks source link

Avoid using global variables #26

Closed ReikoR closed 2 years ago

ReikoR commented 2 years ago

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/4c6d1c92842338af8816641a25f335507717bdcf/saun/uusmain.py#L32

Either pass variables as function arguments and return changed variables as function return values or create a class.

ReikoR commented 2 years ago
  1. Global variables and code duplication in cameraSetThreshold.py

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/1f4b77ebae64bb29882fd5f36271e09f96811f76/saun/cameraSetThreshold.py#L13-L30

functools.partial can be used to bind values to trackbar onChange function.

Something like this should work:

from functools import partial

def update_value(value_name, new_value):
    data[value_name] = new_value

for key in data.keys():
    cv2.createTrackbar(key, "Processed", data[key], 255, partial(update_value, key))
  1. Global variable in ps4controller.py

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/1f4b77ebae64bb29882fd5f36271e09f96811f76/saun/ps4controller.py#L51

throwerspeed can be class variable.

ReikoR commented 2 years ago

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/13853b7f57bae658ed3a05742286b5a1353aca76/saun/movement.py#L9

https://github.com/ut-robotics/picr21-team-sauna-madis/blob/13853b7f57bae658ed3a05742286b5a1353aca76/saun/movement.py#L31

move_style should not be global. It can be class variable.

uschults commented 2 years ago

Globals are removed.