Hi!
We were excited to finally have an angle to goal PID loop somewhat working the other day until we realized how inconsistent it was. Sometimes it would be dead on, other times it would be just enough off that our shot missed. I set the tolerance to a minimal .5 degrees so it should be going right where it is told to be going.
The prime suspect is how our camera and gyro is mounted.(C is for camera and G is for gyro, arrow points to where we line up)
We have never done vision before this season so we weren't exactly trained on where the ideal places are for the camera and gyro to make programming easier. Thankfully for programming, we do shoot only a couple feet from the end of the batter, so there is more wiggle room. Our current vision code looks like this:
Code:
###X is inputted into gyroMagic which then is used for when I call the visionTurn function for the PID loop###
def gyroMagic(self, x):
angle = ((x-170)*(60/320)) #170 is about center of target when lined up
yaw=self.navx.getYaw()
print (yaw)
if yaw > 0:
self.desiredAngle=self.navx.getYaw()+(angle)
if self.desiredAngle>179:
self.desiredAngle -= 360
else:
self.desiredAngle=self.navx.getYaw()+(angle)
if self.desiredAngle<-179:
self.desiredAngle += 360
return self.desiredAngle
def visionTurn(self):
if self.vision_state == 1:
self.turnController.setSetpoint(self.desiredAngle)
self.rotateReady = True
self.vision_state=2
elif self.vision_state == 2:
if self.turnController.onTarget() or self.cancel.get():
self.vision_state=3
self.rotateReady=False
self.auto_aline_autoNow=False
So my ultimate question is, as someone who hasn't taken a trig class yet, how do I offset the camera and gyro placement to get a more accurate angle to the target? I am also of thinking of changing my angle algorithm to copy what
Jared Russell recommends, but I believe that an offset algorithm would make our robot shoot much better. Any help would be greatly appreciated! Thanks!