Skip to content

Commit

Permalink
0.1.0: Added README
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Duckworth authored and Tyler Duckworth committed Sep 21, 2019
1 parent ce28342 commit 92dae7f
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Users/s848387/.local/share/virtualenvs/bruhbot-RyimO_7k/bin/python"
}
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ verify_ssl = true
pyfrc = "*"
black = "*"
flake8 = "*"
robotpy-ctre = "*"

[requires]
python_version = "3.7"
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# BruhBot - Rename coming soon

A revamp of the code for our 2019-2020 Robot, Rosetta, in the MagicBot Framework.

## Running

Make sure you have Python 3.7 or above, PIP, and pipenv installed. When you do, type ```pipenv install``` to install the dependencies, ```pipenv start``` to open a shell for that virtual environment, and ```python3 robot.py [flag]``` to run the code in whatever fashion you want.

## Why does this exist?

Since we have started using RobotPy, the Python framework for FIRST Robotics, we have admired, but never used, the MagicBot framework for our code.

This is an attempt to rewrite a previous codebase in the hopes of gaining enough experience to use it for next year's robot.

## Versioning

This project will follow a simple Semantic Versioning process. That is to say, MAJOR.MINOR.PATCH (Example: 0.5.2, 0.4.1, 0.4.0, etc.)

Version 1.0.0 Will mark the completion of our project, with any other commits being bug fixes or updates to libraries.
Empty file added components/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions components/arm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SETUP
# DigitalInput(0) - Limit Switch
# Interrupts the shooter when pressed
# Spark(1) - Shooter
# DoubleSolenoid(2, 3) - Intake Solenoid

# WHAT DOES IT DO
from wpilib import DigitalInput, Spark, DoubleSolenoid


class Arm:
intakeSolenoid: DoubleSolenoid

38 changes: 28 additions & 10 deletions components/drivetrain.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
import wpilib
import wpilib.drive
from wpilib.drive import MecanumDrive

from ctre import WPI_TalonSRX


class Drivetrain:
# We also use injection here to access the l_motor and r_motor declared in BruhBot's
# createObjects method.
l_motor: wpilib.Talon
r_motor: wpilib.Talon
m_lfront: WPI_TalonSRX
m_rfront: WPI_TalonSRX
m_lback: WPI_TalonSRX
m_rback: WPI_TalonSRX

xSpeed = 0
ySpeed = 0
zRotation = 0
gyroAngle = 0

# Declare the basic drivetrain setup.
def setup(self):
self.dif_drive = wpilib.drive.DifferentialDrive(self.l_motor, self.r_motor)
self.mec_drive = MecanumDrive(
self.m_lfront, self.m_lback, self.m_rfront, self.m_rback
)
self.mec_drive.setExpiration(0.1)
self.mec_drive.setSafetyEnabled(True)

# Change x and y variables for movement.
def move(self, x, y):
self.x = x
self.y = y

# Each time move is called, call arcadeDrive with supplied x and y coordinates.
def move(self, x, y, z, gyroAngle):
self.xSpeed = x if abs(x) > 0.03 else 0
self.ySpeed = y if abs(y) > 0.03 else 0
self.zRotation = z
self.gyroAngle = gyroAngle

# Each time move is called, call arcadeDrive with supplied
# x and y coordinates.
def execute(self):
self.dif_drive.arcadeDrive(self.x, self.y)
self.mec_drive.driveCartesian(
self.xSpeed, self.ySpeed, self.zRotation, self.gyroAngle
)
Empty file added components/hatch.py
Empty file.
28 changes: 28 additions & 0 deletions components/shooter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from wpilib import DigitalInput, Spark


class Shooter:
limitSwitch: DigitalInput
shooter: Spark

def __init__(self):
self.speed = 0
self.switchState = False
self.enabled = False

def enable(self):
self.enabled = True

def is_pressed(self):
self.switchState = self.limitSwitch.get()

def set_speed(self, new_speed):
self.speed = new_speed

def execute(self):
if self.enabled and self.switchIsOn:
self.shooter.set(self.speed)
else:
self.shooter.set(0)
self.enabled = False
self.switchIsOn = False
18 changes: 12 additions & 6 deletions robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
import magicbot
import components.drivetrain

from ctre import WPI_TalonSRX


# Main class for the robot
class BruhBot(magicbot.MagicRobot):
"""
The Bruh Bot. Perfect for next year's water game.
"""
# Using a technique called injection, we can access the class
# Using a technique called injection, we can access the class
# Drivetrain from components/drivetrain.py here.
drive: components.drivetrain.Drivetrain

# Creates all 'objects' used by the robot. Includes high level systems (grabber, drivetrain, etc)
# and lower level things, like motors or pnuematics
# Creates all 'objects' used by the robot. Includes high level systems
# (grabber, drivetrain, etc) and lower level things,
# like motors or pnuematics
def createObjects(self):
# Motors
self.l_motor = wpilib.Talon(1)
self.r_motor = wpilib.Talon(2)
self.m_lfront = WPI_TalonSRX(1)
self.m_rfront = WPI_TalonSRX(2)
self.m_lback = WPI_TalonSRX(3)
self.m_rback = WPI_TalonSRX(4)

# Joysticks (PS4 Controller, in our case)
self.joystick = wpilib.Joystick(0)
Expand All @@ -28,7 +34,7 @@ def teleopInit(self):

# Called each tick (every few miliseconds) during the teleop period
def teleopPeriodic(self):
self.drive.move(self.joystick.getX(), self.joystick.getY())
self.drive.move(self.joystick.getX(), self.joystick.getY(), 0, 0)


# If being ran directly, create a new instance of the BruhBot class
Expand Down
7 changes: 7 additions & 0 deletions tests/pyfrc_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'''
This test module imports tests that come with pyfrc, and can be used
to test basic functionality of just about any robot.
'''

from pyfrc.tests import *
from magicbot.magicbot_tests import *

0 comments on commit 92dae7f

Please sign in to comment.