![]() |
Spike Code Problems
Hi! My robotics class is using cRIO FRC 2014 on Netbeans with Java. The code we are using does not seem to work. We are coding a Spike relay as a kind of intake system, yet each time we upload it to try and control it, nothing happens! If any of you could take a look at the code to see if you notice any problems that would be great! Thanks!
Code:
package edu.wpi.first.wpilibj.templates; |
Re: Spike Code Problems
As I read this, the only time that the trigger is read and the relay is set is at the beginning of teleop (OperatorControl). This polling and setting needs to be in the function which is called repeatedly while in that state. Not being familiar with SimpleRobot (or SampleRobot, as I thought it had become), I don't know the name of that method.
|
Re: Spike Code Problems
operatorControl is only called once, at the start of teleop. So you have to have all of your teleop code in the loop.
This is how your teleop method flows right now: 1. Check if teleop is enabled and the robot is enabled 2. If so, update drivebase inputs 3. Repeat 1 and 2 4. Loop exits -- teleop is over or the robot is disabled 5. Check if the left trigger is pulled and the robot is enabled 6. If so, set the relay 7. Delay 0.1 seconds 8. Exit operatorControl Move everything after the loop into the loop, then it should work. Also, you should format your code (alt+shift+F in Netbeans). The indenting is messed up and that can lead to some headache trying to understand the code |
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; |
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? |
Re: Spike Code Problems
Quote:
|
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. |
| All times are GMT -5. The time now is 09:16. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi