|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Driver Station I/O in C++
Hello all,
I'm trying to read buttons from the cypress board to fire relays on the 'bot. My code so far (just for the relays and dsio) is: Code:
class RobotDemo : public SimpleRobot
{
Relay barrel1;
Relay barrel2;
Relay barrel3;
DriverStation ds;
public:
RobotDemo(void):
barrel1(3),
barrel2(4),
barrel3(5),
ds()
{
GetWatchdog().SetExpiration(0.1);
}
void OperatorControl(void)
{
GetWatchdog.SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
if (ds.GetDigitalIn(3)) {
barrel1.Set(Relay::kOn)
} else {
barrel1.Set(Relay::kOff)
}
}
}
}
Thanks in advance, Andrew D. |
|
#2
|
||||
|
||||
|
Re: Driver Station I/O in C++
If I did not know WPILib, your question is already answered (that is where you put the parens). However, I do know WPILib, and you are initializing the ds wrong (because you are getting an error you did not post, which are helpful, no matter how odd it may seem to you). The DS is a singleton, and so you need to initialize it based on the singleton. If you looked at the WPILib docs, you would notice the constructor is private.
Code:
..
Relay barrel3;
DriverStation &ds;
public:
RobotDemo(void):
barrel1(3),
barrel2(4),
barrel3(5),
ds(*(DriverStation::GetInstance()))
{
GetWatchdog().SetExpiration(0.1);
}
void OperatorControl(void)
...
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|