Go to Post What really drove us was not our achievements, but our failures. - BEEKMAN [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-04-2009, 15:38
drhall drhall is offline
Winner 2009 West Michigan Regional
FRC #0216 (RoboDawgs OTL)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: Grandville, MI
Posts: 32
drhall is an unknown quantity at this point
Send a message via AIM to drhall
Trouble programming Digital I/O toggle switches in C++

We are having some trouble trying to get toggle switches to work for switching between autonomous modes. The switches are mounted directly to our robot and connected to digital I/O ports 1,2, and 3. We are progamming in Wind River using C++ and I just can't get the code to work. We hooked up a multimeter to the switches (which we have hooked up as ground, signal and power) and we are getting the expected 5V one way and 0 the other.

Here's the code, any help is greatly appreciated!!!

Code:
	{
		m_disabledPeriodicLoops = 0;			// Reset the loop counter for disabled mode
		ClearSolenoidLEDsKITT();
		// Move the cursor down a few, since we'll move it back up in periodic.
		printf("\x1b[2B");
		
		
		DriveDirection = 1;
		DriveSpeed = 1;
		if (Switch1->Get() == 0) {
	
			// stuff to do if Switch1 (left) is on
			// Set direction to positive 1 for left
			DriveDirection = 1.0;
			DriveSpeed = 1.0;
		}
		else  if (Switch2->Get() == 0) 
		{
			//not yet
		}
		else  if (Switch3->Get() == 0) {
			// stuff to do if Switch3 (right) is on
			// Set direction to negative 1 for right
			DriveDirection = -1.0;
			DriveSpeed = 1.0;
		}

	}
That is what's in void DisabledInit. We are then using the DriveDirection variable in AutonomousPeriodic.

Thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 01-04-2009, 15:49
Cuse's Avatar
Cuse Cuse is offline
Registered User
AKA: Matt Mancuso
FRC #0175 (Buzz Robotics)
Team Role: Alumni
 
Join Date: Mar 2007
Rookie Year: 2005
Location: Enfield, CT
Posts: 22
Cuse is an unknown quantity at this point
Re: Trouble programming Digital I/O toggle switches in C++

Have you ever been able to read the switches?

You're certain that the code is reading the correct ports, etc.?
__________________


Last edited by Cuse : 01-04-2009 at 15:53.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-04-2009, 16:12
drhall drhall is offline
Winner 2009 West Michigan Regional
FRC #0216 (RoboDawgs OTL)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: Grandville, MI
Posts: 32
drhall is an unknown quantity at this point
Send a message via AIM to drhall
Re: Trouble programming Digital I/O toggle switches in C++

We aren't sure if we have been able to read switches. We are in the process of doing that right now. What kind of code would you reccomend we write to test this?

Thanks!
Reply With Quote
  #4   Spotlight this post!  
Unread 01-04-2009, 16:19
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Trouble programming Digital I/O toggle switches in C++

My best suggestion would be to check when you instantiate the switches. If you use the simpler constructor for them, they might use a 'default' slot on the cRio that you do not expect.

I forget the exact function signature, but you might be doing
Switch1 = new DigitalInput(1); // initializes it to use channel 1 on slot pi

If you're doing that, try using the constructor that explicitly sets the slot to the cRio slot that you're using:
Switch1 = new DigitalInput(4,1); // uses slot 4, channel 1 (might use slot 1, channel 4. Check the DigitalInput.h file)
Reply With Quote
  #5   Spotlight this post!  
Unread 01-04-2009, 16:28
drhall drhall is offline
Winner 2009 West Michigan Regional
FRC #0216 (RoboDawgs OTL)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2005
Location: Grandville, MI
Posts: 32
drhall is an unknown quantity at this point
Send a message via AIM to drhall
Re: Trouble programming Digital I/O toggle switches in C++

Alright we were just able to read the switch in teleop. Now we are working on getting it going for autonomous. Thank you for the help!
Reply With Quote
  #6   Spotlight this post!  
Unread 02-04-2009, 22:43
reversed_rocker's Avatar
reversed_rocker reversed_rocker is offline
Alumni
AKA: Ken Condon
FRC #0706 (Cyberhawks)
Team Role: College Student
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Hartland
Posts: 69
reversed_rocker is on a distinguished road
Re: Trouble programming Digital I/O toggle switches in C++

if you arent sure that the program is reading the toggle switch then i suggest:

printf("toggleswitch = %f \n",Switch1);

now if you go into the console it should give you a read out of the toggle switch if the program is actually recognizing it (while the code is running).

the code up above is assuming that you defined the switch as a float, which it looks like you should have because if you're reading a voltage it's on an analog input. if im wrong and for some reason the switch needs to be an int, change that %f to a %d. for the record, the structure for print statements goes:

printf("whateveryouwanttocallyourvariable = %f \n", variablename);

as i said before, %f changes to %d if the variable you're printing is an int rather than a float, bools also fall under %d
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming toggle switches to DS for different autonomous routines? grosh NI LabVIEW 9 30-03-2009 20:42
Programming Toggle Switches in Labview seanl Programming 1 16-02-2009 13:02
Question about wiring digital switches. DemonYawgmoth Electrical 3 08-02-2007 17:57
3 way toggle switch programming LeadRiccardoT Programming 3 17-02-2003 02:02
Wiring custom toggle switches into operator interface DanL Electrical 9 13-02-2002 17:13


All times are GMT -5. The time now is 10:01.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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