Go to Post Is that severed hand legal? I think it's a COTS assembly from previous years. - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 13-02-2009, 16:30
z2daj z2daj is offline
Registered User
FRC #2836 (Team Beta)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Bethlehem, CT
Posts: 15
z2daj is an unknown quantity at this point
Send a message via AIM to z2daj
Inputs on Driver Station

I've been trying to work this out for a few days now. How do we get digital/analog inputs from the driver station in C++? We're going to use a rotary encoder as a knob to have a fine adjustment with our turret. Any ideas? A quick response would be greatly appreciated
__________________
There is nothing to fear, but fear itself
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2009, 17:25
Redneck's Avatar
Redneck Redneck is offline
Hacker Hick
AKA: Jamie (2.0) Moran
FRC #0599 (Robodox)
Team Role: Engineer
 
Join Date: Aug 2004
Rookie Year: 2004
Location: California
Posts: 90
Redneck is just really niceRedneck is just really niceRedneck is just really niceRedneck is just really nice
Send a message via AIM to Redneck
Re: Inputs on Driver Station

The DriverStation class has GetAnalogIn() and GetDigitalIn() methods for that.
Complete reference available here
__________________


Which badges can you claim?
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2009, 17:45
z2daj z2daj is offline
Registered User
FRC #2836 (Team Beta)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Bethlehem, CT
Posts: 15
z2daj is an unknown quantity at this point
Send a message via AIM to z2daj
Re: Inputs on Driver Station

thanks for your quick repsonse, however we're a rookie team so when i took a look at that along with the other programmer, we both got headaches could you explain just a little?
__________________
There is nothing to fear, but fear itself
Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2009, 19:59
Redneck's Avatar
Redneck Redneck is offline
Hacker Hick
AKA: Jamie (2.0) Moran
FRC #0599 (Robodox)
Team Role: Engineer
 
Join Date: Aug 2004
Rookie Year: 2004
Location: California
Posts: 90
Redneck is just really niceRedneck is just really niceRedneck is just really niceRedneck is just really nice
Send a message via AIM to Redneck
Re: Inputs on Driver Station

Sure. In your code, you'll need to have something like this:

Code:
class MyRobot : public SimpleRobot{
    
    // Member variables (DigitalInputs, Joysticks, Jaguars, etc)
    DriverStation *ds;

    // Default constructor
    MyRobot(){
         // Initializations for all your other variables
         ds = DriverStation::GetInstance();

    }


    void OperatorControl(){
         float a_variable; 
  
         while ( IsOperatorControl() ){
               OtherFunctionCalls();
               a_variable = ds->GetAnalogIn(1); // returns value of whatever's connected to analog input 1 of the DS
 
               if(ds->GetDigitalIn(2)) { // checks state of DS digital input 2
                    DoSomething();
               }
               else{
                    DoSomethingElse();
               }
         }
    }


};
Does that clear things up a bit?

It'll be slightly different if you're using the IterativeRobot template instead of SimpleRobot, but the Driver Station function calls are the same.
__________________


Which badges can you claim?
Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2009, 20:12
Sentient's Avatar
Sentient Sentient is offline
Registered User
FRC #0639 (Code Red)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Ithaca
Posts: 21
Sentient is on a distinguished road
Re: Inputs on Driver Station

Rather than using an encoder, it may be easier to just hook up a POT to in analog IO pins and use driverStation->GetAnalogIn(#) and turn this into a rotational value. The reason this may be easier is that to get a rotational value or really anything useful from the encoder in the driver station would take a bit of work. There is no Encoder class that can interface with the driver station as is.
Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2009, 20:16
z2daj z2daj is offline
Registered User
FRC #2836 (Team Beta)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Bethlehem, CT
Posts: 15
z2daj is an unknown quantity at this point
Send a message via AIM to z2daj
Re: Inputs on Driver Station

that would work great, however we have to rotate all the way around for our turret
__________________
There is nothing to fear, but fear itself
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2009, 20:13
z2daj z2daj is offline
Registered User
FRC #2836 (Team Beta)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Bethlehem, CT
Posts: 15
z2daj is an unknown quantity at this point
Send a message via AIM to z2daj
Re: Inputs on Driver Station

oh wow, ha. thank you so much! yea that clears things up a lot now here's one more question... how would we get rotary encoders working? we bought ours from digikey m/n EM14 - 14 ; since we were missing a key component to the ones supplied to us in the KoP. we're not too sure on the coding for the encoders, everything we have tried has ended with Red Error Messages of Demise (REMoD) and any console outputs are 0. this is what we have for our code:

Code:
#include "Encoder.h"

class RobotDemo : public SimpleRobot

{

		Encoder rotary;

public:

	RobotDemo(void):

		rotary(1, 2)

void Autonomous(void)

	{
		gyro.Reset();

		int display;
				
		
		while (IsAutonomous())

		{
		
			float anything;
			
			while(argument)

			{

				GetWatchdog().SetEnabled(false);	
			
				rotary = new Encoder(1,2);

				Wait(0.004);	
			
				display = rotary;

				printf (" %d \n ", display);

			}

           }

}

void OperatorControl(void)
{

}

};

any ideas?
__________________
There is nothing to fear, but fear itself

Last edited by z2daj : 13-02-2009 at 20:14. Reason: code was hard to read
Reply With Quote
  #8   Spotlight this post!  
Unread 15-02-2009, 01:57
Redneck's Avatar
Redneck Redneck is offline
Hacker Hick
AKA: Jamie (2.0) Moran
FRC #0599 (Robodox)
Team Role: Engineer
 
Join Date: Aug 2004
Rookie Year: 2004
Location: California
Posts: 90
Redneck is just really niceRedneck is just really niceRedneck is just really niceRedneck is just really nice
Send a message via AIM to Redneck
Re: Inputs on Driver Station

Quote:
Originally Posted by z2daj View Post
Code:
#include "Encoder.h"

class RobotDemo : public SimpleRobot

{

		Encoder rotary;

public:

	RobotDemo(void):

		rotary(1, 2)

void Autonomous(void)

	{
		gyro.Reset();

		int display;
				
		
		while (IsAutonomous())

		{
		
			float anything;
			
			while(argument)

			{

				GetWatchdog().SetEnabled(false);	
			
				rotary = new Encoder(1,2);

				Wait(0.004);	
			
				display = rotary;

				printf (" %d \n ", display);

			}

           }

}

void OperatorControl(void)
{

}

};

any ideas?
Ok, couple of things to fix here:

1)You need to add a call to the Encoder class's Start() function.
2)You're creating a new Encoder in the autonomous. You don't need that, you already created it at the constructor.

Here's how things should look:
Code:
#include "Encoder.h"

class RobotDemo : public SimpleRobot

{

		Encoder rotary;

public:

	RobotDemo(void):

		rotary(1, 2)
               {
               }


void Autonomous(void)

	{
		gyro.Reset();
                rotary.Start();

		int display;
		
		while (IsAutonomous())

		{
		
			float anything;
			
			while(argument)

			{

				GetWatchdog().SetEnabled(false);	
			

				Wait(0.004);	
			
				display = rotary.Get();

				printf (" %d \n ", display);

			}

           }

}

void OperatorControl(void)
{

}

};

EDIT: Also, keep in mind that this only works for digital encoders connected to one of the cRIO's digital sidecars. If what you want is a knob on the driver station, then as Sentient mentioned previously you'll need to get a potentiometer and use the DriverStation GetAnalogIn() function.
__________________


Which badges can you claim?

Last edited by Redneck : 15-02-2009 at 02:02.
Reply With Quote
  #9   Spotlight this post!  
Unread 16-02-2009, 04:12
z2daj z2daj is offline
Registered User
FRC #2836 (Team Beta)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Bethlehem, CT
Posts: 15
z2daj is an unknown quantity at this point
Send a message via AIM to z2daj
Re: Inputs on Driver Station

ok, you're in California? it's 4:11AM here, we've been at our workshop for over 50 hours straight and you sir, just saved us. we give you a round of applause, and we seriously did. our programming team of two people literall stopped what we were doing and clapped. thank you so much for everything, if there is ever anything you need, we owe you big time. thanks again. seriously, thank you so much
__________________
There is nothing to fear, but fear itself
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
using digital inputs from the driver station SL8 NI LabVIEW 2 04-02-2009 15:53
Trouble Reading Drivers Station Digital Inputs Mike Mahar C/C++ 3 03-02-2009 23:37
Programming Digital Inputs from Driver Station spooncwru Programming 8 01-02-2009 13:14
LabVIEW - Analog inputs from driver station lag? RedOctober45 NI LabVIEW 1 30-01-2009 10:39
Using driver station digital inputs Japper FRC Control System 6 19-01-2009 20:01


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

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