View Full Version : Spike Relay code failing
kingkurry
03-02-2012, 13:38
We are using a spike relay to control a spinbrush in the front of the robot to sweep in balls. I created a new spike relay object and used the left trigger to get it to move. However, every time I hit the trigger, the ENTIRE robot jerks forward and then becomes unresponsive until I disable and renable teleop. And when i say jerk froward, I mean that the CIM motos, which are connected to our 4 jaguars, move and the spin brush moves too, albeit for a short period of time. Is there some issue in the code that could cause this to happen?
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Relay;
public class Test extends IterativeRobot {
Joystick leftStick;
Joystick rightStick;
RobotDrive robot;
Relay spike;
double leftValue, rightValue;
public void robotInit() {
leftStick = new Joystick(1);
rightStick = new Joystick(2);
robot = new RobotDrive(1,2,3,4);
spike = new Relay(5);
}
public void disabledPeriodic(){
}
public void autonomousPeriodic() {
}
public void teleopPeriodic() {
//robot.setSafetyEnabled(false);
robot.tankDrive(leftStick.getY(),rightStick.getY() );
//robot.tankDrive(leftValue, rightValue);
//spike.set(Relay.Value.kForward);
if(leftStick.getRawButton(1)){
spike.set(Relay.Value.kForward);
}
}
Also, I am plugging in the relay to the relay port of the sidecar. We are just using 5 here because we tried switching between different relay port numbers.
BurtGummer
03-02-2012, 23:28
Can you drive the robot around normally until you hit the trigger?
eddie12390
04-02-2012, 09:17
Could you try this: http://www.usfirst.org/sites/default/files/uploadedFiles/Robotics_Programs/FRC/Game_and_Season__Info/2012_Assets/DB37%20Ribbon%20Cable%20Assembly%20-%20Rework%20Instructions.pdf
We had very similar problems with out ribbon cable and ended up just using a previous year's cable.
kingkurry
04-02-2012, 11:47
The robot does drive somewhat normally until we hit the trigger, however we have noticed that if we go full forward on the left side and full throttle reverse on the right side, the robot locks up and we need to disable and renable teleop for it to work again. Both sides forward, both sides backward, one side forward with the other side at 0 and Left reverse and right forward are fine. It's only going forward on the right side and reverse on the left that makes it lock up.
Also, we did change our ribbon cable. We are using this old printer cable.
BurtGummer
05-02-2012, 09:03
Hmm, doesn't sound like a programming issue to me, though I could be wrong. However, nothing comes to mind as to what could be the issue. I'll think it over today and hopefully come up with something!
Stimpy1901
05-02-2012, 12:36
For relays, we use the following to make our spikes operate.
if (joy.getTrigger()) {
trigger.set(Relay.Value.kOn);
trigger.set(Relay.Value.kReverse);
} else {
trigger.set(Relay.Value.kOff);
}
Here is a link to the Javadoc (http://www.wbrobotics.com/javadoc/edu/wpi/first/wpilibj/Relay.html)
kingkurry
06-02-2012, 21:33
Well we managed to get past the joystick issues during driving through some limiting code. We limited the joystick y values to .6 only when driving the sides in opposite directions to keep the robot from locking up. I am not sure why but suppling any throttle value higher than around .6 to the jaguars when going opposite directions causes it to shut down. Im thinking that this may be a voltage issue, because if we use a battery that is only about 25% charged we can limit it at .75 without any problems. But the relays are still not working.
On a side note, to wire the relays do we need to modify a PWM cable, because only the B(closest to fuse) is labeled. The ground could be the middle pin which would require a modification of the cable.
Just today, I wired a PWM from Relay to a Spike without problems, if that counts for anything.
korsuk19
07-02-2012, 19:23
so for clarification when coding something like:
Relay spike = new Relay(5);
the spike relay would connect through PWM output 5 correct?
kingkurry
07-02-2012, 20:45
It would actually connect to Relay output 5. PWM and Relay outputs use the same cable but different types of signals.
kingkurry
11-02-2012, 19:31
Could someone please try running this code on their robot? All it does is control a relay and drive the bot. We are getting weird problems with this:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Drivetrain extends IterativeRobot {
RobotDrive drive;
Joystick left,right;
double leftValue,rightValue;
Relay spike;
public void robotInit() {
drive = new RobotDrive(1,2,3,4);
left = new Joystick(1);
right = new Joystick(2);
spike = new Relay(1);
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
//spike.set(Relay.Value.kForward);
leftValue = left.getY();
rightValue = right.getY();
drive.tankDrive(left,right);
//drive.tankDrive(limit(leftValue), limit(rightValue));
}
public static double limit(double num) {
final double limit = .6;
if (num > limit) {
return limit;
}
if (num < -limit) {
return -limit;
}
return num;
}
}
When we try and set the relay to forward, the cim motors(which are connected to the jaguars) jerk then become unresponsive. The relay code is commented out right now.
Also, when we try and drive left forward and back reverse without limiting the values to around .6 it stops and becomes unresponsive. driving both wheels forwards or reverse works fine, as long as they are going the same direction, and driving left reverse and right forward doesn't give us any problem.
If someone else could run this it would show us the the programming isnt the problem.
Thanks in advance for your help.
BurtGummer
12-02-2012, 08:07
I don't have a robot to load your code on right now......but it looks fine.
This sounds like an electrical/wiring issue. At first thought, it seems like it might be drawing too much current and lowering the voltage of the battery to the point where the cRio is losing it's minimum voltage to operate.
There's of course of ton of things you could do to try and troubleshoot this.
1. Try changing your code to run only two motors instead of four. Use one on the left and one on the right like tank drive. Re-create the situation that causes it to stop and see if it persists.
2. Instead of changing the code, try unhooking the PWM cables to one jaguar at a time. Create the same situation that causes it to stop for each unhooked PWM cable.
3. Enable the relay code ( code it so a joystick button press sets it to kForward, so its off when it first starts until you press the button) , plug in all jaguars, but disconnect the spike from the digital sidecar. Run the robot and press the button you assigned in the code to turn on the spike relay (pretending its plugged in, even though it isn't). If it still jerks and dies, then it's code related. If not, you've got a wiring issue.
I'm not too sure that the relay problem is directly related to the motor issue.
Let me know if any of that gets you some results. I'll think of some more things to do for troubleshooting. If you could, PM me a picture of your control system including all components.
-Sean
We'll be trying some of those suggestions you've provided. Thanks! :)
We had similar issue and after 3 hours of trying to fix it, we figured someone forgot to power the Digital Sidecar.
Before powering it, it could only handle 2 CIM motors, anything more would just make everything not work. And even Relay caused it to jerk and become unresponsive. (Same issue as you are having.)
After powering it, all the lights turned on, including the team light, and everything worked fine.
I would double check the wiring for powering the Digital Sidecar to 20 amps breaker. And also see if your team light is working.
Hope that helps.
kingkurry
13-02-2012, 19:29
So we did check the sidecar. It is being powered properly. Can someone please run this code on their robot? Just to confirm that it is not a programming issue.
We did try binding the relay to a trigger. Whenever we hit the trigger the same thing happens. In other words, activating the relay causes it to jerk. Also, we tried to disconnect the relay but still run it. We got the same issue. We did try running the relay but commenting out the robot drive object and related methods. This didnt get the relay to run but the cim motors didnt jerk at least.
Thank You.
kingkurry
15-02-2012, 17:17
So does anyone have any suggestions?
One non-programming possibility is that there is an intermittent electrical connection somewhere. We had one of those a few years ago, where the IFI controller would lose power when the robot leapt forward, causing the robot to...stop leaping forward. Doesn't sound *exactly* like your situation, but I can see scenarios where something like you are describing might happen.
BurtGummer
15-02-2012, 20:27
So does anyone have any suggestions?
Check your PMs.
It could really be a bad spike also. In fact, one of ours stopped working today randomly as well. We checked all the cables and nothing seemed wrong with them, then we tried a different Spike and it worked fine.
kingkurry
17-02-2012, 23:06
Here are some photos of our wiring:
http://dl.dropbox.com/u/45939446/Robot%20Good.rar
we were helping a team at the Utah Regional and there connector on the spike wasn't working, we had to take off the case to get the connector in it, also today i tried wiring the spikes and put the PWM cable in wrong and busted the pins off it. So ya, they have been known to have connector issues.
You cant plug a relay into a pwm you have to plug it into a relay port right across from the pwm's. And also the b pin on the relay goes to the - one on the dsc.
synthmusic
26-01-2013, 13:41
I would double check the wiring for powering the Digital Sidecar to 20 amps breaker. And also see if your team light is working.
THANK YOU! we spent a bunch of time looking at this, and then we found the sidecar had been wired to the camera power port based on this tip. :yikes:
Check your power source...
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.