Skip to content

Commit

Permalink
Misc touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil-kale committed Nov 10, 2024
1 parent 8e0e2d4 commit 7457a7c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
run_visualizer: bool = False,
run_controller: bool = True,
tune_controller: bool = False,
cam_color_mask_detect: bool = False,
):
self.pause_period = 0.01
self.saturate_angle = 14.0
Expand Down Expand Up @@ -95,14 +96,17 @@ def __init__(
# get the file camera.json with the current dir
file_path = os.path.join(current_dir, "camera_params.json")

self.camera_debug = camera_debug

with open(file_path, "r") as file:
data = json.load(file) # Load JSON data as a dictionary

if self.virtual is not True:
self.cv_system = Camera(data["u"], data["v"], camera_port, camera_debug)
self.cv_system.open_camera()
self.cv_system.calibrate(8, 6)
# self.cv_system.colorMaskDetect()
if cam_color_mask_detect:
self.cv_system.colorMaskDetect()

self.current_position = Point(0, 0)

Expand Down Expand Up @@ -138,7 +142,8 @@ def run(self):
if self.run_controller:
if self.virtual is False:
self.current_position = self.cv_system.get_ball_coordinates()
print(f"Current position is: {self.current_position}")
if self.camera_debug:
print(f"Current position is: {self.current_position}")
else:
self.current_position = Point(0, 0)

Expand Down Expand Up @@ -238,8 +243,7 @@ def run(self):
# add argument for CV/Camera debug
parser.add_argument(
"--camera_debug",
type=bool,
default=False,
action="store_true",
help="Flag for showing more camera info for debugging",
)

Expand All @@ -254,6 +258,12 @@ def run(self):
help="Run the control loop in tuning mode",
)

parser.add_argument(
"--cam_color_mask_detect",
action="store_true",
help="Run the camera calibration",
)

args = parser.parse_args()

run_controller = args.inhibit_controller == False
Expand All @@ -270,5 +280,6 @@ def run(self):
servo_offsets=servo_offsets,
tune_controller=args.tune_controller,
run_controller=run_controller,
cam_color_mask_detect=args.cam_color_mask_detect,
)
mcl.run()

0 comments on commit 7457a7c

Please sign in to comment.