|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
Re: Limit Switch Draws Tears
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 |
|
#3
|
|||||
|
|||||
|
Re: Limit Switch Draws Tears
Quote:
What are you using as a limit switch? The microswitches I'm familiar with have three connections. |
|
#4
|
|||
|
|||
|
Re: Limit Switch Draws Tears
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.
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::kResolution_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);
Soo, we are still stuck. |
|
#5
|
|||||
|
|||||
|
Re: Limit Switch Draws Tears
Which rule was that? <R54> is the no modifying motors rule.
<R60-L> reads: Quote:
Quote:
|
|
#6
|
|||
|
|||
|
Re: Limit Switch Draws Tears
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.
|
|
#7
|
|||
|
|||
|
Re: Limit Switch Draws Tears
<<< 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. Last edited by eugenebrooks : 15-02-2010 at 00:46. |
|
#8
|
||||
|
||||
|
Re: Limit Switch Draws Tears
In your constructor, I see this line that stands out:
Code:
Dig1 = new DigitalInput(1, 1); Code:
DigitalInput::DigitalInput(UINT32 slot, UINT32 channel) If you change it to look like this it should read Digital Input #1 from the default digital module (module #4). Code:
Dig1 = new DigitalInput(1); |
|
#9
|
||||
|
||||
|
Re: Limit Switch Draws Tears
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 |
|
#10
|
|||||
|
|||||
|
Re: Limit Switch Draws Tears
[edit]Yeah, lots of people caught this one.[/edit]
Last edited by Alan Anderson : 15-02-2010 at 00:52. Reason: took me too long to look up the documentation |
|
#11
|
|||
|
|||
|
Re: Limit Switch Draws Tears
We have tried all of the possible solutions however they have all failed terrifically.
|
|
#12
|
||||
|
||||
|
Re: Limit Switch Draws Tears
Quote:
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 |
|
#13
|
|||
|
|||
|
Re: Limit Switch Draws Tears
where exactly would these 3 conditions for a boolean variable be?
|
|
#14
|
|||
|
|||
|
Re: Limit Switch Draws Tears
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); } |
|
#15
|
||||
|
||||
|
Re: Limit Switch Draws Tears
Ahhh... While I sleep, my minions carry on!
Thanks Doc. A switch is either ON or OFF... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| limit switch | solomason519 | Programming | 9 | 09-02-2010 08:50 |
| Using a limit switch to limit motion | ManicMechanic | Programming | 16 | 20-12-2007 00:54 |
| limit switch | wedellm | Electrical | 4 | 16-02-2007 13:01 |
| Limit Switch Basics | JWSnedden | Programming | 6 | 30-11-2006 19:48 |