Skip to content

TechnoJays/robot2024

Repository files navigation

Team 94 FIRST Robotics 2024 FRC Robot Code

FIRST Robotics FRC is a high school robotics program. This repository contains the code used in the Southfield High School Team 94 (Retrojays) robot for the year 2024.

Getting Started

Development Requirements

  • Python 3.11: This codebase uses Python 3.11
  • robotpy: Be sure to follow the robotpy instructions for the latest robotPy setup. This is largely handled by installing the project as mentioned below.

It is highly recommended that you use a python environment manager with python to help as the version of python required by pyfrc changes year over year.

  • pyenv is useful for managing multiple python versions on your computer: NOTE your python version and pip version/dependencies are highly correlated
    • The most sane method for installing pyenv is using the pyenv installer
      • If you are more confident, you can use brew install pyenv for macOS and Homebrew
      • On windows, you can usescoop install pyenv with Scoop as the closest thing to Homebrew (if you have the misfortune to be using Windows and possibly follow this page for more instructions on supporting different python versions
  • pipenv is useful for dependency management for this project as well
    • `` to create a python 3.11 environment for this project
    • python -m pip install . to setup this project in the created virtualenv
    • pipenv shell to enter the environment for this project
    • pip install tox to install tox in the environment
    • tox after that to run the tests

IDEs like Pycharm also support pipenv.

It is very important that you have updated pip to the latest version. You can do so with the command below:

# Confirm your python version in python 3 
python --version

Good luck!

Deploying to the Robot

Accessing the Robot

The robot can be reached over ethernet or local usb connection.

With the robot connected to your laptop over USB, your best bet is to attempt to connect with

# lvuser is the user where robot code is deployed, the `94` here is as programmed when flashing the roborio
ssh lvuser@roborio-94-frc.local

If you know the IP of the robot, it can be accessed at:

# note IP assignment is done dynamically through DHCP, so this IP address may
# not always be true
ssh lvuser@169.254.171.191

These steps are useful for confirming connectivity to the robot before attempting to deploy.

Running robotPy Deployment commands

Robotpy provides useful commands to copy/install all .py files in the src/ folder to the robot.

RobotPy has some great robot code deployment instructions and automation.

To deploy code after being connected

python src/robot.py deploy --netconsole

Running Tests

  1. Make sure, you have tox installed:

    pipenv install -r requirements.txt
    pipenv shell
  2. Run the projects tests:

    tox

tox is running python src/robot.py coverage test from RobotPy Unit Testing

If you would like to run the tests without coverage, you can execute

python src/robot.py test

And individual tests can be run by passing pytest arguments to the test option of the pyfrc test command

python src/robot.py test -- ./tests/test_oi.py

Running the Camera Server (CSCore)

It is often useful to test the vision processing code independently of the robot code. Especially since the robotpy cscore SPECIFICALLY STATES THAT YOU MUST NOT IMPORT wpilib IN VISION CODE OR VICE VERSA

Use the handy commands below to run vision code locally on your laptop

python -m cscore src/vision/vision.py:start_camera

TODO setup GitHub actions for the robot code. Examples are provided directly from the wpilib docs, setting up CI for robot code

Project Formatting

To be soothing to your mind, the project attempts to make python/PEP formatting not an issue. Given you think you are ready to commit your code changes. Just run:

black --check .

To show which files black will reformat.

black --diff .

Shows the changes black will make, and then:

black .

will let the reformatting goodness happen. Black comes with the pipenv install -e . of the project.