Quote:
Originally Posted by z2daj
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.