|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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
![]() |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
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();
}
}
}
};
It'll be slightly different if you're using the IterativeRobot template instead of SimpleRobot, but the Driver Station function calls are the same. |
|
#5
|
||||
|
||||
|
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.
|
|
#6
|
|||
|
|||
|
Re: Inputs on Driver Station
that would work great, however we have to rotate all the way around for our turret
|
|
#7
|
|||
|
|||
|
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? Last edited by z2daj : 13-02-2009 at 20:14. Reason: code was hard to read |
|
#8
|
||||
|
||||
|
Re: Inputs on Driver Station
Quote:
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. Last edited by Redneck : 15-02-2009 at 02:02. |
|
#9
|
|||
|
|||
|
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
![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |