|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Spike Code Problems
So I updated my code, but nothing seems to be happening! Here's the updated version:
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Timer;
public class RobotTemplate extends SimpleRobot {
RobotDrive myDrive;
Joystick moveStick, rotateStick;
Talon backRight, backLeft, frontRight, frontLeft;
Relay relay;
public void robotInit() {
frontLeft = new Talon(1);
backLeft = new Talon(2);
backRight = new Talon(3);
frontRight = new Talon(4);
relay = new Relay(1);
//myDrive = new RobotDrive(frontLeft, backLeft, frontRight, backRight);
myDrive = new RobotDrive(backLeft, backRight, frontLeft, frontRight);
moveStick = new Joystick(2);
rotateStick = new Joystick(1);
}
/**
* This function is called once each time the robot enters autonomous mode.
*/
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
while (isOperatorControl() && isEnabled()) {
myDrive.mecanumDrive_Cartesian(moveStick.getY(), rotateStick.getX(), moveStick.getX(), 0);
if (rotateStick.getTrigger(GenericHID.Hand.kLeft) && isEnabled()) {
relay.set(Relay.Value.kOff);
relay.setDirection(Relay.Direction.kForward);
}
}
//mecanumDrive_Polar(moveStick.getY(), moveStick.getX(), rotateStick.getX());
Timer.delay(0.1);
}
}
/**
* This function is called once each time the robot enters test mode.
*/
|
|
#2
|
|||||
|
|||||
|
Re: Spike Code Problems
Quote:
First, you called relay.set(Relay.Value.kOff); This essentially disables the relay; it won't let either the forward or re reverse direction be enabled. The relay.set is usually called in the initialize method, unless the way in which it operates changes for different parts of the program. Second, you don't have any way to turn the relay off. The if statement that wraps the relay.setDirection() should have an else case that does this. Further, this if statement probably doesn't need the isEnabled() as part of the condition, as it was checked just a few microseconds earlier at the top of the while loop. Edit: One more thing - didn't you mean to include the delay within the loop? Last edited by GeeTwo : 04-12-2015 at 21:33. |
|
#3
|
||||||
|
||||||
|
Re: Spike Code Problems
Quote:
|
|
#4
|
|||||
|
|||||
|
Re: Spike Code Problems
No, not quite the same mistake; I made my own mistake of switching the two as I moved back and forth between windows.
To correct my previous post: within the initialization method, setDirection() should be once, with either kForward_val or kReverse_val. set() should be called in both branches of an if-then-else in the while loop in operatorControl(), on with kOff_val, the other with kOn_val. If the system winds up running backward, just change the call to setDirection. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|