View Full Version : Limit Switch Draws Tears
Imagine yourself: 11 hours, 5 programmers, no mentors, 1 fiesty limit switch. The result? 5 programmers suffering a severe mental breakdown.
We are attempting to program a very simple limit switch that will disable a motor when the limit switch circuit is closed. We have wired the two limit switch wires into to the ground and signal connections on input four of the digital sidecar. We are programming in C++ and whenever we attempt to get a signal back from the input it always shows up as equaling one, no matter what we do. Please help us, it seemed so simple when we started 11 HOURS AGO!
Radical Pi
14-02-2010, 23:56
what are you using to discover the value? The Dashboard? If so the default dashboard code returns hard-coded values that do not reflect the status of the system
Make sure the digital module is on slot 4. Also make sure power is properly wired to the sidecar. Try last year's sidecar if you have to. Also try a different limit switch.
If you are using the CAN bus for motor control, you could just directly wire the limit switch to the Jaguar and forget about this entire mess
Alan Anderson
15-02-2010, 00:08
We have wired the two limit switch wires into to the ground and signal connections on input four of the digital sidecar.
Have you verified that the switch works? How?
What are you using as a limit switch? The microswitches I'm familiar with have three connections.
As far as we can tell everything is as you say, we have the module in slot 4 and are attemting to get the state of the input directly from the module itself not the dashboard. We simply created an object called Dig4 and set it equal to DigitalInput(1), here's the code.
#include "WPILib.h"
#include "Vision/AxisCamera.h"
#include "Vision/HSLImage.h"
#include "PIDController.h"
#include "Gyro.h"
#include "Target.h"
#include "DashboardDataSender.h"
#include "Jaguar.h"
#include "Compressor.h"
#include "Solenoid.h"
#include "Victor.h"
class DefaultRobot : public SimpleRobot
{
//RobotDrive *myRobot; // robot drive system
Joystick *rightstick; // joystick 2
Joystick *leftstick; // joystick 1
Gyro *gyro; // gyro initialization
DashboardDataSender *dds; // Driver station data sender
DriverStation *ds; // driver station object
Victor *jag1;// single jaguar motor control
Victor *jag2;
Victor *jag3;
Victor *jag4;
Compressor *compressor; // new compressor object
Solenoid *solleft; // solenoid on left
Solenoid *solright; // solenoid on right
DigitalInput *Dig1;
enum Resolution_t
{
kResolution_320x240
};
/*enum // Driver Station jumpers to control program operation
{ ARCADE_MODE = 1, // Tank/Arcade jumper is on DS Input 1 (Jumper present is arcade)
ENABLE_AUTONOMOUS = 2, // Autonomous/Teleop jumper is on DS Input 2 (Jumper present is autonomous)
} jumpers; */
public:
DefaultRobot(void)
{
GetWatchdog().SetEnabled(false);
ds = DriverStation::GetInstance();
//myRobot = new RobotDrive(1, 3, 2, 4); // create robot drive base
leftstick = new Joystick(1);
rightstick = new Joystick(2); // create the joysticks
dds = new DashboardDataSender(); // dashboard data sending
compressor = new Compressor(10, 8); //compressor on ports 10 and 8
solleft = new Solenoid(1); //solenoid on ports 1 and 2(below)
solright = new Solenoid(2);
jag1= new Victor(1);
jag2= new Victor(2);
jag3= new Victor(3);
jag4= new Victor(4);
Dig1 = new DigitalInput(1, 1);
//Update the motors at least every 100ms.
}
/**
* Drive left & right motors for 2 seconds, enabled by a jumper (jumper
* must be in for autonomous to operate).
*/
void Autonomous(void)
{
}
void OperatorControl(void)
{
AxisCamera &camera = AxisCamera::GetInstance();
camera.WriteResolution(AxisCameraParams::kResoluti on_320x240);
camera.WriteBrightness(200);
while (IsOperatorControl())
{ GetWatchdog().Feed();
if (Dig1->Get() == 0)
{
jag1->Set(0.0);
jag2->Set(0.0);
jag3->Set(0.0);
jag4->Set(0.0);
}
else if(Dig1->Get() == 1)
{
jag1->Set(-leftstick->GetY());
jag2->Set(rightstick->GetY());
jag3->Set(-leftstick->GetY());
jag4->Set(rightstick->GetY());
}
else
{
jag1->Set(-1.0);
jag2->Set(1.0);
}
compressor->Start();
if (leftstick->GetRawButton(2))
{
//jag->Set(1.0);
solleft->Set(1);
solright->Set(0);
}
else
{
//jag->Set(0.0);
solleft->Set(0);
solright->Set(1);
}
//myRobot->TankDrive(rightstick, leftstick);
compressor->GetPressureSwitchValue();
}
};
};START_ROBOT_CLASS(DefaultRobot);
We have also used our multimeter to check the limit switch and the digital side car works for everything else we have used (motors, compressor, gyro and so on). We also found out earlier that this year it is illegal to connect the limit switch directly to the jaguar in accordance to R<54>.
Soo, we are still stuck.
Which rule was that? <R54> is the no modifying motors rule.
<R60-L> reads: L. If CAN-bus functionality is used, limit switch jumpers may be removed from a Jaguar speed controller and a custom limit switch circuit may be substituted (so that the cRIO-FRC may read the status of the limit switches).
Also see:<R68> All outputs from sensors, custom circuits and additional electronics shall connect to only
[...]
G. the CAN-bus if and only if all Jaguar speed controllers on the CAN-bus are wired in full compliance with Rule <R63> and Rule <R64>, or
H. the sensor inputs on the Jaguar speed controller.
This is going to sound very strange, but today (we haven't ever come in on sunday before) my team was supposed to spend 4 hours in the shop to clean up the wires on our bot for a revealing day/ showcase tommorow. After putting everything back together, our robot still didn't run. 5 hours later we realized that a limit switch was creating a short. It took us about a total of 13 hours to get it going. I feel your immense pain.
eugenebrooks
15-02-2010, 00:34
<<< Dig1 = new DigitalInput(1, 1); >>>
Your digital sidecar is in slot 4, so the line above should be
Dig1 = new DigitalInput(4,1);
if my memory serves me correctly, assuming that
you are using digital input 1 as the code implies.
In your constructor, I see this line that stands out:
Dig1 = new DigitalInput(1, 1);
The DigitalInput constructor you're using looks like this:
DigitalInput::DigitalInput(UINT32 slot, UINT32 channel)
By constructing with DigitalInput(1, 1), it will try to look for a digital input on module 1. This won't work, since that's the analog module.
If you change it to look like this it should read Digital Input #1 from the default digital module (module #4).
Dig1 = new DigitalInput(1);
Mike Betts
15-02-2010, 00:37
... Dig1 = new DigitalInput(1, 1);`...
In your original post you state that the swich is wired into input 4 on the digital sidecar. And, as Alan pointed out, the cRIO digital module should be plugged into slot 4.
Therefore, I would guess that the statement above should be
Dig1 = new DigitalInput(4, 4);
Or am I missing something?
Regards,
Mike
Alan Anderson
15-02-2010, 00:51
...We simply created an object called Dig4 and set it equal to DigitalInput(1), here's the code.
Dig1 = new DigitalInput(1, 1);
Yeah, lots of people caught this one.
We have tried all of the possible solutions however they have all failed terrifically.
Mike Betts
15-02-2010, 01:57
We have tried all of the possible solutions however they have all failed terrifically.
OK. That statement really scares me...
Now, don't get me wrong. Your code has more than one problem (like 3 conditions for a Boolean condition) but, for anyone to help, you need to clearly define what is wired and what you want to do, in plain language please...
Mike
where exactly would these 3 conditions for a boolean variable be?
eugenebrooks
15-02-2010, 02:53
The digital input is one, or zero.
Don't count on the code handled by the final else
statement to ever get executed.
if (Dig1->Get() == 0)
{
jag1->Set(0.0);
jag2->Set(0.0);
jag3->Set(0.0);
jag4->Set(0.0);
}
else if(Dig1->Get() == 1)
{
jag1->Set(-leftstick->GetY());
jag2->Set(rightstick->GetY());
jag3->Set(-leftstick->GetY());
jag4->Set(rightstick->GetY());
}
else
{
jag1->Set(-1.0);
jag2->Set(1.0);
}
Mike Betts
15-02-2010, 06:10
Ahhh... While I sleep, my minions carry on!
Thanks Doc.
A switch is either ON or OFF...
Focusing on the limit switch problem:
1. It should be referred to as DigitalInput (1) or DigitalInput (4,1) - nothing else.
The first number refers to the slot where your digital module is - in this case Slot 4.
2. Make sure your switch itself is a normally Open type switch
Switches come as Normally Open and Normally Closed - closed will always show one unless it is operated in a different way.
You can check this using a multimeter.
Mike Betts
15-02-2010, 07:49
...Make sure your switch itself is a normally Open type switch Switches come as Normally Open and Normally Closed - closed will always show one unless it is operated in a different way...
Not true. "Normally" only reflects the position of the contacts when the switch is not pressed. A NO switch will close when pressed, a NC switch will open.
There are many times when you want a NC switch. This is particularly true of limit switches. If a wire breaks and the switch is no longer "in the circuit" you want the motor or actuator that you are limiting to stop. This is usually much safer...
Regards,
Mike
Yes yes yes, we understand the dynamics of how a switch works :)
The third condition was just an act of desperation, seeing if anything would work.
The switch itself is perfect. It is wired up correctly and everything as previously stated. I believe where our problem lies is within the coding. I think it is declared properly, yet the switch refuses to recognize a closed position.
I blame Fate.
Mike Betts
15-02-2010, 08:50
Yes yes yes, we understand the dynamics of how a switch works :)
The third condition was just an act of desperation, seeing if anything would work.
The switch itself is perfect. It is wired up correctly and everything as previously stated. I believe where our problem lies is within the coding. I think it is declared properly, yet the switch refuses to recognize a closed position.
I blame Fate.
So what you are saying is that you knowingly posted code here which you knew could not work and want us to divine why the code that you did not show us (the code that should work) does not work...
How do you expect anyone to help you?
Mike
Alan Anderson
15-02-2010, 08:54
I believe where our problem lies is within the coding.
It is abundantly clear that the code is broken, as has been pointed out to you by multiple people. Please please please please read the responses telling you exactly what line is totally wrong (hint: it's the one saying DigitalInput(1,1), and should be changed to DigitalInput(4), assuming your limit switch is on DIO 4 of a Digital Sidecar connected to the module in slot 4).
I blame Fate.
If you regularly ignore the advice of people trying to help you, the blame quickly shifts.
Make sure your limit switch is wired up between the Signal and Ground wires (and NOT Signal and Power). Signal and Ground are the only two wires you need for a simple limit switch.
Double check with a meter with the switch connected and robot powered on that the voltage across the switch changes from 0 to 5V.
I know this might be something you have already done, however I've run into many teams that try and wire the Power and Signal wires to the switch, and verify that the "switch works" by just checking whether the resistance across the switch goes to 0
Now here is where things get interesting. We have read and tried all of the above solutions AND the reason why we posted the code was so that you could better understand our situtation. Just because we had 3 conditions for a boolean operation does not constitute snotty remarks. It is very eaasy to ignore the third condition as that is not our main problem. I think it is you that must read our responses to the solutions posted. Thank you Mr. Lim and those of you who posted solutions, we have tried all of them , but failure seems too proud to leave us this day.
Mike Betts
15-02-2010, 10:03
Now here is where things get interesting. We have read and tried all of the above solutions AND the reason why we posted the code was so that you could better understand our situtation. Just because we had 3 conditions for a boolean operation does not constitute snotty remarks. It is very eaasy to ignore the third condition as that is not our main problem. I think it is you that must read our responses to the solutions posted. Thank you Mr. Lim and those of you who posted solutions, we have tried all of them , but failure seems too proud to leave us this day.
This will be my last post on this thread.
You originally said that you had two limit switches wired to DI 4 on the digital sidecar.
You then posted a code fragment with this:
Dig1 = new DigitalInput(1, 1);
which is an example of code that can not possible work. Why? The Analog I/O module must be in slot #1.
I replied that the code fragment should have been
Dig1 = new DigitalInput(4, 4);
assuming the digital I/O module is plugged into slot 4 of the cRIO.
You then replied that you had "tried all of the possible solutions" and I asked you to tell us exactly how the switches are wired.
You did not.
The discussion of three conditions came about because you asked. I merely said that you had more than one issue... I also asked you to tell us what you were trying to accomplish. You did not.
The discussion of normally open versus normally closed was especially pertinent as we still do not know how the TWO switches are wired.
Since you will not tell us how things are wired we have to guess... Two normally open switches, wired in series and operated one at a time will never close a circuit and always return a 1 in your code... This is an example of why limit switches are almost always wired as normally closed.
You were asked to explain your wiring. You did not...
You posted code which could not work and you knew that it could not work because you are addressing the analog module...
And somehow you infer that we are to blame because we can not read your mind...
I am done here...
Good luck
Mike
z2daj,
You need to understand that the CD community consists of VERY good mentors who pretty much could solve your problem in a matter of seconds if they were there and able to collect the information they need. What you perceive as a snotty remark is probably a bit a frustration on our part by the inability to get the information we need.
It's a limit switch, and we want to get you up and running ASAP.
Can you answer these questions for us?
1. Does your switch, when hooked up with the robot powered on, measure 5V and then change to 0V across the terminals when you press and release your switch?
2. Where exactly is your switch hooked up on the digital side car? Digital I/O 4? Not relays, or PWM?
3. Is there anything else hooked up to this Digital Side Car? Speed controllers? Other switches/sensors?
4. Do these other items on the Digital Side Car work? Are all the green LEDs on?
5. Where is the Digital Side Car hooked up to on the cRIO? To a DIO module in slot 4? Using the originally supplied cable? Are the thumbscrews screwed in?
6. If your switch is hooked up to digital input 4 on the digital side car, and the digital sidecar is hooked up to the cRIO through a DIO module in the fourth slot (fourth counted from the end with the power connector) then your initialization should be:
Dig4 = new DigitalInput(4);
Can you verify if that is what you are using?
6. Add a printf line to the end of your teleop code:
printf("DIO4: %d\n",Dig4->Get());
7. Open a Target Console in WindRiver by right-clicking VxWorks6x in the bottom-left window then Target Tools->Target Console
8. The Target Console should now spit out the state of your switch continuously. Does it ever switch from 1 to 0 when you press your switch?
9. Are there any experienced teams in your area you can contact? Two days to burn on a limit switch is too much, and if I were in your shoes, I'd get help in person ASAP. FIRST is a wonderful thing - I'm sure someone would be willing.
Ok guys, after re-reading my posts, I would like to apologize for my rudeness. I let my frustration get the better of me. I left it alone for awhile and let somebody else take control. He told me later that he got it working, although I didn't get to ask how due to the snow.
Thank you all for everything and good luck to you and your teams during these final days of the build season.
-Zach Jasensky
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.