{"id":18518362,"url":"https://github.com/flash3388/frc-vision-template","last_synced_at":"2025-05-14T15:32:44.776Z","repository":{"id":43861938,"uuid":"291879248","full_name":"Flash3388/FRC-Vision-Template","owner":"Flash3388","description":"Template for FRC vision code which runs on another platform (jetson, rpi, etc)","archived":false,"fork":false,"pushed_at":"2023-01-30T21:08:35.000Z","size":191,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T04:42:07.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Flash3388.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-01T02:49:14.000Z","updated_at":"2021-12-11T11:08:14.000Z","dependencies_parsed_at":"2023-02-16T11:45:19.377Z","dependency_job_id":null,"html_url":"https://github.com/Flash3388/FRC-Vision-Template","commit_stats":null,"previous_names":[],"tags_count":1,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flash3388%2FFRC-Vision-Template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flash3388%2FFRC-Vision-Template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flash3388%2FFRC-Vision-Template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flash3388%2FFRC-Vision-Template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flash3388","download_url":"https://codeload.github.com/Flash3388/FRC-Vision-Template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171954,"owners_count":22026552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T17:13:06.949Z","updated_at":"2025-05-14T15:32:40.151Z","avatar_url":"https://github.com/Flash3388.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FRC Vision\n\nVision code for FRC which runs separately from the robot code. The code will connect to network tables and allow\nrunning and configuring vision code based on the `VisionControl` interface from FlashLib.\n\n## Program Parameters\n\n- `--config-file=PATH`: sets the path to the configuration file. Default `/home/flash/frc.json`.\n- `--console-log`: enables logging to the console\n- `--file-log`: enables logging to file\n- `--log-file-out=PATH`: sets the log file path. Default `frcvision.log`.\n- `--log-level={DEBUG|INFO|WARN|ERROR}`: sets the log level. Default `ERROR`.\n\n## Configuration\n\nThe configuration file allows editing different aspects of the code functionality. See [config.json](config.json) for example.\n\nThe configuration is made up of several parts in a hierarchy:\n- root: all the settings\n    - cameras: configurations for the connected cameras, should have information about all the cameras in a format matching\n      the following template:\n      ```JSON\n      \"cameras\": [\n          {\n            \"name\": \"a name for the camera. it's purely for debugging reasons\",\n            \"path\": \"device path, like /dev/video0\",\n            \"pixel format\": \"MJPEG, YUYV, etc || optional\",\n            \"width\": \"width of the camera resolution || optional\",\n            \"height\": \"height of the camera resolution  || optional\",\n            \"fps\": \"frames per second  || optional\",\n            \"brightness\": \"brightness precentage || optional\",\n            \"white balance\": \"auto, hold, specific value, etc || optional\",\n            \"exposure\": \"auto, hold, specific value, etc  || optional\",\n            \"fov\": \"field of view in radians || optional\"\n            \"properties\": [\n                {\n                  \"name\": \"custom prop name\",\n                  \"value\": \"custom prop value\"\n                }\n            ]\n          }\n      ]\n      ```\n    - nt: settings about network table connection. Different modes require\n        different settings.\n      ```json\n      \"nt\": {\n          \"mode\": \"mode for connection with network tables\",\n          \"team\": \"team number\" || optional\n          \"addresses\": [\n              \"address of the server of network tables\",\n              \"another possibility of address\"\n          ] || optional,\n          \"port\": \"port of the server\" || optional\n      }\n      ```\n        - mode \"CLIENT_TEAM\"\n            - connect as a client to the server\n            - uses roboRIO addresses expected for the team\n            - requires \"team\" setting\n        - mode \"CLIENT_CUSTOM\"\n            - connect as a client to the server\n            - uses configured addresses and port to connect to the server\n            - requires \"addresses\" setting\n            - requires \"port\" setting\n        - mode \"SERVER\"\n            - run as the server for network tables\n            - allows clients to connect\n    - target: information about the target to find matching the following format:\n      ```JSON\n      \"target\": {\n          \"realWidth\": \"real life width in cm\",\n          \"dimensionsRatio\": \"ratio between real life width and height\"\n      }\n      ```\n    - vision: configuration for the vision code running matching the following format:\n      ```JSON\n      \"vision\": {\n          \"color\": {\n              \"space\": \"color space to work with\",\n              \"min\": [\n                  \"minimum values to filter in the image for each color dimension\"\n              ],\n              \"max\": [\n                  \"maximum values to filter in the image for each color dimension\"\n              ]    \n          },\n          \"type\": \"type of vision control, which determine how to use the cameras. Based on VisionType enum\",\n          \"camera\": \"only for SINGLE_CAMERA type - specifies index of camera to use from among the camera configs\"\n          \"autoStart\": \"boolean indicating whether to start vision immediately, or wait for a start command\"\n          \"options\": {\n              \"option_name\": \"value for option\"\n          } \n      }\n      ```\n        - `VisionType` indicates how the vision should reflect when having several cameras.\n            - `SINGLE_CAMERA`: vision code will only run on one camera while the rest will simply be used for looking.\n            - `SWITCHED_CAMERA`: vision code will use the currently selected camera. Switching cameras will affect vision as well.\n        - color space: one of `RGB`, `HSV`, `BGR` \n      \n## Vision Options\n\nThe supported `VisionOption` types are:\n- `StandardVisionOptions.DEBUG`: additional debug information during the vision code\n- `StandardVisionOptions.EXPOSURE`: exposure setting of the camera used for vision\n\nIn addition, there are custom vision options:\n- `ExtraVisionOptions.SELECTED_CAMERA`: index for which camera to show. depending on the `VisionType` used this \n  might affect vision or simply affect what is shown by the MJpeg server\n- `ExtraVisionOptions.COLOR_SPACE`: color space used in the color filtering. The `MIN`/`MAX` options\n  available for use depend on the amount of dimensions in the space.\n- `ExtraVisionOptions.COLOR_DIM1_MIN`: min value for the first dimension in the color filtering\n- `ExtraVisionOptions.COLOR_DIM1_MAX`: max value for the first dimension in the color filtering\n- `ExtraVisionOptions.COLOR_DIM2_MIN`: min value for the second dimension in the color filtering\n- `ExtraVisionOptions.COLOR_DIM2_MAX`: max value for the second dimension in the color filtering\n- `ExtraVisionOptions.COLOR_DIM3_MIN`: min value for the third dimension in the color filtering\n- `ExtraVisionOptions.COLOR_DIM3_MAX`: max value for the third dimension in the color filtering\n\n## Robot Interaction\n\nTo interact with this vision code from the robot, use `NtRemoteVisionControl` from `flashlib.frc.nt`\nwhich implements remote `VisionControl` through network-tables.\n```Java\nVisionControl visionControl = new NtRemoteVisionControl(\"vision\");\nvisionControl.start();\n\nvisionControl.setOption(StandardVisionOption.DEBUG, true);\nOptional\u003cVisionResult\u003e result = visionControl.getLatestResult(true);\nresult.ifPresent((value)-\u003e System.out.println(value.getAnalysis()));\n```\n\nSee [this example](https://github.com/Flash3388/FlashFRC/tree/development/examples/vision/robot-nt-vision) for more.\n\n## Build and Deploy\n\nBuilding and deploying is based on _gradle_ tasks. Run the wrapper (`./gradlew` on UNIX and `gradlew.bat` on Windows)\nwith the tasks `build` to build and `deploy` to deploy.\n\nDeploying will push the compiled code and the [configuration file](config.json) to a place specified by gradle configuration, as seen\nin [gradle.properties](gradle.properties):\n- `DEPLOY_PATH`: absolute path on the remote to deploy the code. Should exist. Will be the parent folder of the code.\n- `DEPLOY_HOST`: hostname of the remote device to deploy to.\n- `DEPLOY_USER`: username to connect to on the remote when deploying.\n\nFor security reasons, the password to connect to the deploy target is not saved in gradle.properties and needs to be\nspecified manually when deploying:\n```shell script\n./gradlew deploy -PtargetPassword=somepassword\n```\n\nThe program will be deployed to `DEPLOY_PATH/frcvision.zip` and then\nextracted to `DEPLOY_PATH/frcvision`.\n\n### Running\n\nTo run the deployed code, run the `DEPLOY_PATH/frcvision/bin/frcvision` file.\nOr, run the _gradle_ task `runRemote`.\n\nFor security reasons, the password to connect to the deployment target is not saved in gradle.properties and needs to be\nspecified manually when deploying:\n```shell script\n./gradlew runRemote -PtargetPassword=somepassword\n```\n\nThis will also deploy the code first, kill any previous processes\nof the code running, and then start the new one.\n\nThe gradle task will output information from the standard output\nof the remote process. Killing the gradle task (with CTRL+C for example)\nwill not kill the remote process. Run the task\n```shell\n./gradlew killRemote\n```\n\n#### Debug\n\nFor additional debug information, use `-PrunDebug=1`. This will\nrun the program with the options:\n- `--log-level=DEBUG`\n- `--console-log`\n\n#### Run with Simulator\n\nFor testing, it is possible to run the code locally alongside a simulation of the robot.\nThe program will connect to locally-connected cameras following the configuration set for it.\n\nIn order for the code to be connected to network-tables to communicate with the robot,\nthe \"nt\" configuration should be set to connect to a locally running server:\n\n```json\n{\n  \"nt\": {\n    \"mode\": \"CLIENT_CUSTOM\",\n    \"addresses\": [\n      \"127.0.0.1\"\n    ],\n    \"port\": 1735\n  }\n}\n```\n\nIn addition, network-tables has some native code. The code version must match the platform\non which it runs. The value is configured in [gradle properties file](gradle.properties) under the key `REMOTE_ARCH`. \nIt needs to be modified to the local computer arch in order to run. \nThe value should be `{osName}{arch}`, for example `linuxx86-64` for a computer running _linux_ with a _x86-64_ CPU.\n\nTo run locally, executed:\n```shell\n./gradlew run\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflash3388%2Ffrc-vision-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflash3388%2Ffrc-vision-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflash3388%2Ffrc-vision-template/lists"}