Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Digital Inputs + Auton? (http://www.chiefdelphi.com/forums/showthread.php?t=74078)

Straberrie 10-02-2009 15:16

Digital Inputs + Auton?
 
Hey,

I was trying to get different autons based on switches, and the code is as follows (example):

Quote:

void Autonomous(void)
{
if (s1->Get())
{
myRobot->Drive(-0.6, 0.5);
Wait(1.0);
myRobot->Drive(0.0,0.0);
}
else
{
myRobot->Drive(0.0,0.0);
}
}
and i defined the s1:

Quote:

DigitalInput *s1;
s1 = new DigitalInput(1);
However, when when i ran the auton, it went according to the code inside the if statement even when the switch was off. I was hoping that when the switch was off, it would refer to the "else" part of the code, but the code did not change despite the switch being off or on. What did i do wrong??

THANK YOU!!! :]

Alan Anderson 10-02-2009 15:31

Re: Digital Inputs + Auton?
 
It might be a physical connection issue. How exactly is your switch wired?

Straberrie 10-02-2009 15:38

Re: Digital Inputs + Auton?
 
Switch 1 is getting plugged in to positive-negative end signal; the other six are only getting signal because all switches are grounded together. However, the only switch used in the code is switch1


(Thank you by the way!)

Alan Anderson 10-02-2009 15:46

Re: Digital Inputs + Auton?
 
Quote:

Originally Posted by Straberrie (Post 818017)
Switch 1 is getting plugged in to positive-negative end signal;...

I don't understand that description. Can you give specific details about where each of the Digital Input's pins is connected, and what kind of switch you are using?

Boydean 10-02-2009 15:49

Re: Digital Inputs + Auton?
 
Are you using the KoP switch? Print the status of the digital input to see what is coming from the switch. We had some problems with the KoP switch going between on and off really fast when it was off. To fix the problem we connected a resistor to pull the signal down to zero.

Straberrie 10-02-2009 16:11

Re: Digital Inputs + Auton?
 
1 Attachment(s)
To Alan Anderson: I attached pictures of the switches. (Thanks)

To BoyDean: I am not aware of that (sorry), but I will try it with prints. (Thanks)

:]

byteit101 10-02-2009 21:31

Re: Digital Inputs + Auton?
 
looks like you wired it sideways on the DSC
you have it like this
********
********
*****000

when it should be like this
*****0
*****0
*****0

Mike Betts 10-02-2009 22:20

Re: Digital Inputs + Auton?
 
Rebecca,

For the most part, your switches look good. I assume (the connection is slightly off picture) that the commons on the switches are tied to ground (to the black wire on the PWM cable in the SW1 position).

Byteit101's comment is not appropriate and your wiring should work.

The resistors referenced by Brandon are 10K pull-ups and are internal to the sidecar (schematic). You do not need to add more.

Other than something very weird such as a bad DS or the DS not getting power, I would concentrate on software.

Unfortunately, my team is using Labview and I have not played with this year's C++ at all...

Good Luck,

Mike

JBotAlan 10-02-2009 22:41

Re: Digital Inputs + Auton?
 
Quote:

Originally Posted by byteit101 (Post 818237)
looks like you wired it sideways on the DSC

Nope. It's hard to decode, but it looks as though those horizontal cables are all signal wires. There's one cable that connects to the ground and 5v like we are used to seeing, and then the rest of the cables are the signal wires for the rest of the switches. There is a unified ground; this is a conservative design.

Assuming everything is wired properly, when the switch is CLOSED, you will get a ZERO from the digital input, and when it is OPEN, you will get a ONE. I emphasize because it is backwards from common sense.

Now, you did mention that the else is never executed, regardless of the state of the switch.
  • Stupid question: does anything else on that sidecar work? If the PWM outputs on it work OK, then something else is the matter.
  • You should check that the switches are operating as you expect. Put a multimeter in the mode to measure ohms. Put one probe on the center terminal and the other on the terminal you have wired to the signal pin. With the switch one way, it should read either 0 ohms, or something close. The other way, it should read infinite--on my meter, it reads "0 F" when it is infinite (this should be the same display it has with the probes in the air, not touching each other).
  • You can measure (in the volts mode) what the voltage is between the signal pin and the ground. It should read 5v when the switch is open, and 0v when closed.
  • You can repeatedly print the state of the input, but I don't quite know how to do this yet. If you need help, I will figure it out.

If all else fails, post back here and somebody will help.

Jacob

edit: AND SEE ALAN'S POST. I neglected to realize this situation; as he says, if you aren't wiring the common wire to ground, you will always see a 1 coming in that input. Thanks, Alan.

Alan Anderson 11-02-2009 00:08

Re: Digital Inputs + Auton?
 
Quote:

Originally Posted by Straberrie (Post 818036)
I attached pictures of the switches.

Heh. The one wire that I really want to know about isn't visible, being just off the right side of the picture of the back of the switches. It should be connected to the ground (black) wire of DIO 1. If you have it going instead to +5 (red), you'll never see any change on the signal input.

Straberrie 13-02-2009 06:11

Re: Digital Inputs + Auton?
 
Thank you everyone!!!!!

One of our mentors found the problem! Apparently it was a loose wire! Which is y switch 1 always had a value of 1!

and again, Thank u all very much!!!!!!! :]

Doug Leppard 13-02-2009 10:23

Re: Digital Inputs + Auton?
 
Quote:

Originally Posted by Mike Betts (Post 818277)
Rebecca,

For the most part, your switches look good. I assume (the connection is slightly off picture) that the commons on the switches are tied to ground (to the black wire on the PWM cable in the SW1 position).

Byteit101's comment is not appropriate and your wiring should work.

The resistors referenced by Brandon are 10K pull-ups and are internal to the sidecar (schematic). You do not need to add more.

Other than something very weird such as a bad DS or the DS not getting power, I would concentrate on software.

Unfortunately, my team is using Labview and I have not played with this year's C++ at all...

Good Luck,

Mike

For the digital inputs on the driver station does it have internal 10k pull ups?

We were getting bad data at times.

Alan Anderson 13-02-2009 11:07

Re: Digital Inputs + Auton?
 
Quote:

Originally Posted by Doug Leppard (Post 819884)
For the digital inputs on the driver station does it have internal 10k pull ups?

No. The Driver Station digital inputs are floating, and any required pullup (or pulldown) must be supplied externally.

Doug Leppard 13-02-2009 11:28

Re: Digital Inputs + Auton?
 
Quote:

Originally Posted by Alan Anderson (Post 819907)
No. The Driver Station digital inputs are floating, and any required pullup (or pulldown) must be supplied externally.

I assume we would use 10k resistors.


All times are GMT -5. The time now is 02:27.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi