View Single Post
  #2   Spotlight this post!  
Unread 03-15-2016, 06:55 PM
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 232
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Drive forward to x inches

So this is written in python but you can make it work for java.

Code:
def encoder_drive(self, target_position, max_speed):
		target_offset = target_position - self.return_drive_encoder_position() #Figure out how far off you are
		
		if abs(target_offset)> 1000: #If you're less than 1000 'ticks' away (maybe change to 1 inch for you) then drive forward more
			self.y = target_offset * self.drive_constant.value # speed = offset * low constant (decreases speed as you approach target)
			self.y = max(min(max_speed, self.y), -max_speed) #limit that speed to some speed x)
			return False #you aren't at the position yet
		return True # if you're within an inch, you're there
later on in the code you want to tell robotdrive to drive with the y variable. Take a look at 1418's 2015 code here
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
Reply With Quote