Log in

View Full Version : Please Help Rookie with Simple Program


obot
15-02-2012, 21:23
Please help me write Java program that will turn on and off a motor through Jaguar attached to PWM 3 on digital sidecar. I would like it to be mapped to button 4 on left joystick for on and button 5 on left joystick to turn it off. Please, please help

Thanks
Obot

theNerd
15-02-2012, 22:05
Are you trying to send analog signals (-1.0 - 1.0)? or do you just want it to turn on and off like a relay?

obot
15-02-2012, 22:10
Just turn on and off like a relay, Please.

neal
15-02-2012, 22:14
You could do something simple like this:


import edu.wpi.first.wpilibj.*;

public class TestBot extends SimpleRobot {

private Joystick joystick1;
private Jaguar jag;

public void robotInit() {
joystick1 = new Joystick(1);
jag = new Jaguar(3);
Watchdog.getInstance();
}

public void autonomous() {
while (isAutonomous() && isEnabled()) {
getWatchdog().feed();
}
}

public void operatorControl() {

while (isOperatorControl() && isEnabled()) {
getWatchdog().feed();
boolean motorOn = false;

if(joystick1.getButton(4)) {
motorOn = true;
}
if(joystick1.getButton(5)) {
motorOn = false;
}

if(motorOn) {
jag.set(1.0);
} else {
jag.set(0.0);
}

Timer.delay(0.005);
}
}

public void disabled() {
while (isDisabled()) {
getWatchdog().feed();
}
}

}

obot
15-02-2012, 22:22
Thanks Neal. I will try it!

austin1743
18-02-2012, 22:03
how did this work out for you guys?