![]() |
Java button help
Hello, we are brand new to programming in Java this year. We are following the cookbook from firstforge. We were able to move the robot using a joystick but cannot figure out how to use a button to enable a motor. We created a subsystem called shooter then a command called ShootBall. We get an error in out code and can't figure out why. Our code is in the attachment.
Here is shooter: Code:
/*Code:
/*Code:
package edu.wpi.first.wpilibj.templates; |
Re: Java button help
You never set the speed of the motors once you get the value of the button (true/false)
Not sure how its done in the subsystem programming methods, but in iterative, its: Code:
if(joystick.getTrigger()) |
Re: Java button help
In the Subsystem objects you want to include all the methods which control the hardware of that subsystem.
So for instance in the Shooter subsystem you would want a method that would drive the shooter wheel: i.e. Code:
Also Delete the defaultCommand, because that will cause that command to run, even without pushing a button (it runs by default). Once you have that method in your Shooter Subsystem, you create a command that requires that subsystem and calls the "drive" method in the execute method. In this case, since you are using a button, you will not have variable control of the motor, but on off control. So the idea is everytime the button is pressed, drive the shooter wheel with a constant value between -1 and 1. Your execute method in the ShootBall command should look something like this: Code:
protected void execute() {Lastly, now that you have your subsystem and command set up, in OI map all you need to do is: Code:
i.e one method could be Code:
public double getRightStickVal()You could then create another command call shootBallWithJoystick, have it require shooter as well and in the execute method of that command do something like this: Code:
protected void execute() {We used the CommandBase Robot template for our 2012 robot in Java, and find it to be an extremely nice way to control the robot. Hope that helps, Kevin |
Re: Java button help
Thanks you were an immense help.
|
| All times are GMT -5. The time now is 10:12. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi