FRC-1799 / Note-Detection

Note detection added in python
0 stars 0 forks source link

Make note detection be done! #7

Open scottpantall opened 6 months ago

scottpantall commented 6 months ago

We want note detection to work! What do we need to do?

From @oof15642

  1. I changed the ports so that it would cycle through each one, try to start the video with open cv. If it didn’t start the video, it would destroy the video and try again. If it was a camera, it broke out of the look and kept that video.
  2. Changed is_note function to check if there was a note, or was 2 notes (check how variable detecting is printed)
  3. Implemented Owen’s function, which should be self explanatory

Here’s the code I used from ai for the index checking:

import cv2

# Get the list of available camera indexes (assuming up to 10 cameras)
camera_indexes = list(range(10))

# Check each camera index
for index in camera_indexes:
    cap = cv2.VideoCapture(index)
    if cap.isOpened():
        print(f"Camera index {index} is available.")
        cap.release()
    else:
        print(f"Camera index {index} is not available.")
# Range would be 4 tho
# With the 2 note thing, detections basically prints out detections(xyxy=[x, y, x, y], confidence=[confidence)
# (simplified) 
# So using that you can check if detections ==none (no note
# Detections < 2 (1 note)
# Else: 2 or more notes

Also for 2 or more notes, here’s documentation on the max() function I used https://www.google.com/url?q=https://www.w3schools.com/python/ref_func_max.asp&sa=U&ved=2ahUKEwjM9ZHJofqEAxUJQjABHYpFB4cQFnoECAIQAg&usg=AOvVaw1mqlDz9RHq-zCo65-w6O-Y

scottpantall commented 6 months ago

I am following these instructions (https://docs.wpilib.org/en/stable/docs/software/vision-processing/wpilibpi/using-a-coprocessor-for-vision-processing.html). I have the Pi running with a camera attached. I just need to get the python running.

I had the python running on my computer with python v3.10 (at least I'm pretty sure it was running) but when I upgraded my comptuer to use python v3.12, it made it so I can't install with pip cuz reasons so I'm currently trying to figure that out.

scottpantall commented 6 months ago

The instructions I'm following have the Raspberry Pi connected to the RoboRio via ethernet cable, not USB, which concerns me. Should anyone have any resources on connecting the Pi to the Rio via USB, I'm all ears.

scottpantall commented 6 months ago

My issue was that the inference module doesn't work with python v3.12 so I uninstalled it and used v3.11.8 which seems to be working: https://pypi.org/project/inference/

This confuses me since we have a poseEstimate.cpython-312.pyc file which seems to tell me we used v3.12 to build that file but if this works, it works.

scottpantall commented 6 months ago

Good news! I can get it to attempt to run on the Pi.

Bad news! The Pi currently have access to the internet and can't just go get the inference module. I'll have to play more tomorrow. image

scottpantall commented 6 months ago

This might help but might be horrible since inference has a LOT of dependencies... https://skylerh.com/how-to-install-python-modules-without-internet-access/#:~:text=Use%20Command%20Prompt%20To%20Install,having%20a%20working%20Python%20interpreter!

Fooot-Code commented 6 months ago

Definitely use Python 11 fo running on your own, because that is what is auto installed on the pi

scottpantall commented 6 months ago

Alright. 2 things to figure out first...

  1. How do we get the Raspberry Pi to communicate with the RoboRio using USB? The vast majority of the resources discuss connecting with an Ethernet cable which would require us to have an ethernet switch since our radio is also plugged into the RoboRio using an ethernet cable.
  2. How do we get the Raspberry Pi to send data to the RoboRio's NetworkTables? We format the data to publish to NetworkTables but don't actually send it: https://github.com/FRC-1799/Note-Detection/blob/Issue7-make-it-be-done/main.py#L72
scottpantall commented 6 months ago

I can write to network tables in desktop simulation mode! I used this python package: https://pypi.org/project/pynetworktables/ It literally just writes the same values that it writes to the console.

We will need to read the robot positions from network tables (Code that has been written by @twisterjafla in a different branch for robot-comp-code-2024) in order to use the toRobotPosit to communicate as desired.

We should also be able to get the Raspberry Pi to run our note detection on startup by following these directions: https://learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup#method-1-rclocal

scottpantall commented 6 months ago

The robot positions ("robotPositX", "robotPositY", "RobotRotation") are written from the semiAutoManager class (lines 62-64) and are written to the SmartDashboard.

scottpantall commented 5 months ago

We are able to read the robot positions from network tables! W00t!

I don't think we need to worry about checking USB ports for cameras but I'll make sure of that tomorrow. I am also unsure how @oof15642 was dealing with multiple notes.

I'll put up a PR for this branch so we can discuss it in the code.

scottpantall commented 5 months ago

I got the note detection to only care about 1 note! W00t!