View Single Post
  #8   Spotlight this post!  
Unread 17-02-2015, 16:00
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: Robot Code Problem ** Again**

Quote:
Originally Posted by AnnaliseDonavan View Post
Code:
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
Drive.arcadeDrive(drivestick);

Button button1 = new JoystickButton(joystick, 1),
button2 = new JoystickButton(joystick, 2),
button3 = new JoystickButton(joystick, 3),
button4 = new JoystickButton(joystick, 4),
button5 = new JoystickButton(joystick, 5),
button6 = new JoystickButton(joystick, 6),
button7 = new JoystickButton(joystick, 7),
button8 = new JoystickButton(joystick, 8),
button9 = new JoystickButton(joystick, 9),
button10 = new JoystickButton(joystick, 10),
button11 = new JoystickButton(joystick , 11);


button1.whenPressed(new ElevatorOff());
button2.whenPressed(new ElevatorOn());
button3.whenPressed(new ElevatorReverse());
button4.whenPressed(new ArmsOut());
button5.whenPressed(new ArmsIn());
button6.whenPressed(new ArmsVerticalIn());
button7.whenPressed(new ArmsVarticalOut());
button8.whenPressed(new BlueLightShow());
button9.whenPressed(new LigthShowOn());
button10.whenPressed(new RedLightShow());
button11.whenPressed(new LightShowEnd());
}
First off, each of the buttons needs a type to specified. I personally do the declarations as all one line, and don't even name them. I would recommend you write them as such:
Code:
new JoystickButton(joystick, 0).whenPressed(new Command());
I'm not really sure whether or not this would cause compile errors, but I would definitely recommend using the OI class that even comes with the command based template to define the buttons, or at least do them in the Robot class constructor or as fields. Doing them in the periodic loop definitely isn't smart, as you want that loop to run as fast as possible, and creating 22 new objects every couple of milliseconds or so is a sure fire way to slow down the speed at which driver commands will be processed and to give the roboRIO memory issues. I'm also not sure if that is allowed, as I thought that joystick buttons are the same as DIO, PWM, etc. ports, in that you cannot allocate them multiple times.

As for anything beyond that, I'm sorry, but I didn't read it all. When posting code on chief, or anywhere else on the internet for that matter, always remember to format your code with code tags, which on chief look like this: [*CODE][*/CODE], except without the star. Another good rule of thumb is that people won't help you if you post more than 200 lines of code. So try and meet that, even if it takes some abstraction on your part.
__________________
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