|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#2
|
|||
|
|||
|
Re: Problems with Java in Eclipse **please help!**
One of the nice things about the FIRST Robotics Library (WPILib) is that you don't need to control all four motors individually!
Take a look at your "robotDrive41" object. It has two methods that you probably care about, arcadeDrive and tankDrive. It's your choice which one to use. For the purposes of this, I'll use arcade drive in examples, but substitute as necessary. If you haven't yet, add a joystick in RobotBuilder. You can find it under the "OI" header in RobotBuilder. Drag it under Operator Interface. Alternatively, right click Operator Interface and add the joystick. In the subsystem class, you can have a method that looks something like this: Code:
public void arcadeDrive(double moveValue, double rotateValue){
robotDrive41.arcadeDrive(moveValue, rotateValue);
}
Before you create the command, you'll want to change a few things (some of these don't change all that well after you create the command and export to Java): http://imgur.com/V7BAYne The first thing that's different is the "Requires" line. This line tells the robot that this command is the only command that can use the Drive subsystem when it's running. You'll see why it's really useful in a little bit. Second is unchecking the "Button on SmartDashboard". It makes no sense to have a button for checking the joysticks. Third is the parameter, speed. To add a parameter, click on the grey box and then "Add Parameter" in the popup. Make sure that you click enter after changing the name of the parameter. The Type should be double. Click save and close. This speed parameter will be useful later. Code:
public class DriveCommand extends Command{
...
public void execute(){
double move= Robot.oi.getJoystick().getX();
double rotate= -Robot.oi.getJoystick().getY();
Code:
if(Math.abs(move)<.1) move = .0; if(Math.abs(rotate)<.1) rotate=0; Code:
move *= m_speed; rotate *= m_speed; Robot.drive.arcadeDrive(move, rotate); Make sure to press enter before clicking "Save and close". It will not save otherwise. If unsure, re-open the "Edit parameters" popup to check that the value is still 1. http://imgur.com/pGeDcWH Lastly, let's make it so that if you hold down a button, the robot goes at half speed (note that depending on how your robot is mechanically, you may want .6 or .7 speed in the program to actually go half speed. Experiment until it's how you like it). Drag a button under the joystick (it's under the OI header in RobotBuilder, or you can right click on the joystick "folder" and add the button there). Name the button something like "SlowDownButton". Set which joystick and button you want it to be bound to. The button should trigger the DriveCommand again, but with a slower speed. Again, when you set the speed, make sure to click enter and all of that. Leave the "When to Run" on whileHeld: http://imgur.com/fN6oF8P Export everything, save, and deploy. Reply if you have any questions or issues. Good luck in competition! |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|