View Single Post
  #1   Spotlight this post!  
Unread 02-12-2016, 06:20 PM
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 216
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Problem with NavX to turn around.

Hi,

This year, our shooter direction is opposite of our front of our robot. I decided that we should use the NavX we just got to semi-accurately turn ourselves around. We don't have any encoders on our motors so I just made a simple function that would have the motors turn until it hit a 10 degree range in which case it would stop.

The problem is that it doesn't always work. It works 9/10 times but that one time it just spins endlessly in a circle and never stops. This, of course, is not something you want to happen. I am asking if there is a better way to go about programming this so it ALWAYS works? Here is the current function:

Code:
        #if button pressed, start
        if self.turn_button.get():
            self.turn_state=0
            yaw=self.navx.getYaw()
            #Our NavX is not completely centered on the robot so 
            #that is why it isn't 180 degrees for turning around
            if yaw > 0:
               
                self.desired=self.navx.getYaw()-227
            else:
                self.desired=self.navx.getYaw()+133
 
 
        current=self.navx.getYaw()
        if self.turn_state==0:
            self.turn_state=1
        elif self.turn_state==1:
            if current < (self.desired+10) and current > self.desired:
                self.turn_state=2
            else:
                self.drive2.set(.7)
                self.drive1.set(.5)
Any help would be greatly appreciated!
Reply With Quote