Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions tthhiinnggyy.py → camera.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Will your code should be at the bottom. Fill in the stuff in HooBoyShoot. Also I think the calls to AutonTankDrive are wrong.
Camera#Will your code should be at the bottom. Fill in the stuff in HooBoyShoot. Also I think the calls to AutonTankDrive are wrong.

import math
import serial
Expand All @@ -19,12 +19,12 @@
MUZZLE_VELOCITY = 30 #meters/second
COMPLETELY_ARBITRARY_CONSTANT = 1

class Tthhinnggyy:
class Camera:
old_x = 0
mid_x = None
mid_y = None
theta = None
distance = None
distance = None #returnss in meters
ser = None
driveDelay = 0

Expand Down Expand Up @@ -77,15 +77,6 @@ def uncode(self, string):
number += char
return stuff


def centerLine(self):
if(abs(self.distance - REF_DIST) > DDZ_MOV): #meters, arbitrary deadzone value
spd = math.copysign(0.1, self.distance - REF_DIST)#max(MIN_MOV_SPD, abs(distance))*math.copysign(1.0, distance)
self.autonTankDrive(spd,spd)
return False
return True


#max(MIN_ROT_SPD, min(MAX_ROT_SPD, abs(self.theta - REF_THETA)))
''' def ShootDistance(self): #I *guarantee* this does *not* work
angle = math.arcsin(((REF_TOW_H - REF_CAM_H)/self.distance+4.9*self.distance)/MUZZLE_VELOCITY)
Expand All @@ -96,7 +87,7 @@ def centerLine(self):
#it can be changed, but it's not important anyway
'''
'''
thng.receive()
if thng.centerSide() and thng.centerLine() : #this works because of short-circuiting
cam.receive()
if cam.centerSide() and cam.centerLine() : #this works because of short-circuiting
HooBoyShoot()
'''
25 changes: 14 additions & 11 deletions components/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from ctre.cantalon import CANTalon
from wpilib.interfaces import Gyro
from . import Component
import tthhiinnggyy
from tthhiinnggyy import Tthhinnggyy
import camera
from camera import Camera
import math


Expand Down Expand Up @@ -53,7 +53,7 @@ def __init__(self, robot):
self.rbmotor.setPosition(0)
self.lbmotor.setPosition(0)
self.myInertia = 0
self.thng = Tthhinnggyy()
self.cam = Camera()

def drive_forward(self, speed) :
self.drive.tankDrive(speed, speed, True)
Expand Down Expand Up @@ -99,20 +99,20 @@ def turnAngle(self, degrees, speed=0.2):
return False

def visionLineUp(self):
self.thng.receive()
if self.thng.centerSide():#and self.thng.centerLine() : #this works because of short-circuiting
self.cam.receive()
if self.cam.centerSide():#and self.cam.centerLine() : #this works because of short-circuiting
print("hooboyshoot")
self.reset()
#oh what fun it is to ride

def findGoal(self):
x = 25
self.thng.receive()
self.cam.receive()
if x < 25:
x += 1
self.autonTankDrive(0,0)
return False
if self.centerSide():#and self.thng.centerLine() : #this works because of short-circuiting #in a one-horse open sleigh
if self.centerSide():#and self.cam.centerLine() : #this works because of short-circuiting #in a one-horse open sleigh
self.reset()
x = 0
return True
Expand Down Expand Up @@ -156,14 +156,14 @@ def convertEncoderRaw(self, selectedEncoderValue):
return selectedEncoderValue * self.INCHES_PER_REV

def centerSide(self):
if(self.thng.mid_x == None):
if(self.cam.mid_x == None):
self.autonTankDrive(0, 0)

if(self.myInertia > 0):
self.myInertia -= 1
return False
elif(abs(self.thng.mid_x) > tthhiinnggyy.DDZ_ROT): #radians, arbitrary deadzone value
if(abs(self.thng.mid_x) > 0.15):
elif(abs(self.cam.mid_x) > camera.DDZ_ROT): #radians, arbitrary deadzone value
if(abs(self.cam.mid_x) > 0.15):
spdMag = 0.15
else:
spdMag = 0.09
Expand All @@ -173,10 +173,13 @@ def centerSide(self):
self.myInertia = 0
if(self.myInertia <= 5):
self.myInertia += 1
spd = math.copysign(spdMag, self.thng.mid_x)#min(max(MIN_ROT_SPD, abs(self.mid_x)), MAX_ROT_SPD), self.mid_x) #again arbitrary numbers
spd = math.copysign(spdMag, self.cam.mid_x)#min(max(MIN_ROT_SPD, abs(self.mid_x)), MAX_ROT_SPD), self.mid_x) #again arbitrary numbers
self.autonTankDrive(spd, -spd)
return False
self.autonTankDrive(0, 0)
if(self.myInertia > 0):
self.myInertia -= 1
return True

def convert(self, x):#converting meters to inches
return x*39.37