|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hi I'm a programmer on team 5464 and we need to know how to program a motor to a trigger on a joystick. We are fairly new to Java, so you may need to explain the steps. We do not know where to begin. We have a code to move a robot.
Thank you for your time |
|
#2
|
|||
|
|||
|
Re: Help with Programming a trigger!
Have you looked at any instructions or sample-code. One good place to start is within File --> New --> Other... --> Example Java Projects -->CommandBased Robot --> GearsBot.
|
|
#3
|
||||
|
||||
|
Re: Help with Programming a trigger!
Are you using iterative robot or command based?
|
|
#4
|
||||
|
||||
|
Re: Help with Programming a trigger!
I think it is command based in Eclipse. I could be wrong.
|
|
#5
|
|||
|
|||
|
Re: Help with Programming a trigger!
Be aware that "trigger" may not always be a trigger in code. On a regular joystick you are probably going to use something like the following with shooter being some sort of motor controller such as CANTalon shooter = new CANTalon(10);
Code:
if(stick.getTrigger()) {
shooter.set(1.0); // turn it on when pressed
} else {
shooter.set(0.0); // turn it off when released
}
!!!However, if you are using something like a Playstation type controller (such as Logitech F310 with switch on back in X position), the two triggers may actually show as a pair of axis (each with values on a 0-1.0 scale) instead of as a trigger. On ours the left trigger is axis 2 and the right is axis 3 but you can use the USB section of the driver station to determine yours. This then looks more like the following. Code:
if(stick.getRawAxis(3) > .5) {
motor.set(1.0);
} else {
motor.set(0.0);
}
Code:
motor.set(stick.getRawAxis(3)); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|