View Single Post
  #6   Spotlight this post!  
Unread 06-11-2014, 16:45
AWoL's Avatar
AWoL AWoL is offline
Lvl. 225 Dark Code Mage (Java Type)
AKA: Adam Wolnikowski
FRC #0225 (TechFire)
Team Role: Programmer
 
Join Date: Mar 2014
Rookie Year: 2014
Location: York, Pennsylvania
Posts: 116
AWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond reputeAWoL has a reputation beyond repute
Re: Can someone explain this code?

From a style and code neatness standpoint, might I suggest putting your right talons in an array and your left talons in another? Then you can set an entire side's speeds with a for loop like so:

Code:
for (int i = 0; i < left.length; i++)
{
   left[i].set(1);
}
or now with the roboRIO (Java SE 8), with a for each loop...

Code:
for (Talon t : left)
   t.set(1);
then put it in another method for easy use...

Code:
public void setLeft(int speed)
{
   for (Talon t : left)
      t.set(speed);
}
or even a more general method for less code...

Code:
public void setSpeed(Talon[] tarray, int Speed)
{
   for (Talon t : tarray)
      t.set(speed);
}
and finally, work in the inversion...

Code:
public void setSpeed(Talon[] tarray, int Speed)
{
   for (Talon t : tarray)
   {
      if (t.equals(talon1) || t.equals(talon5) || t.equals(talon6))
         t.set(-speed);
      else
         t.set(speed);
   }
}
We handle setting our drivetrain speed in a similar fashion.
__________________
2016 Competition Results (Co-captain, Driver, and Lead Programmer; Junior)
Springside-Chestnut Hill District Event - WINNER / #2 Seed, #1 Seed's First Pick / Gracious Professionalism Award
Westtown District Event - WINNER / #1 Seed / Industrial Design Award
MAR District Championship - WINNER / #1 Seed / Industrial Design Award / Dean's List Finalist Award (Me)
World Championship, Carson Subdivision - QUARTERFINALIST / #3 Seed, #2 Seed's First Pick
Indiana Robotics Invitational - FINALIST / #14 Seed, #2 Seed's Second Pick

Last edited by AWoL : 06-11-2014 at 16:47. Reason: Note at the end.
Reply With Quote