I have to take input from the driver station in form of a string for use of switching between auto modes. Then I need to take said string and execute the auto mode accordingly. Something like the following:
string autoMode = *input from driver station*;
if (autoMode == ctrs)
{
*auto code*;
}
else if (autoMode == rs)
{
*other auto code*;
}
else if (autoMode == crs)
{
*even more auto code*
}
else if (autoMode == no)
{
*final auto code*;
}
else
*do nothing*;
So what I need is an example of how to get a string from the driver station using the SmartDashboard::GetString().
Thanks!!!
ps the ctrs, rs, etc are the short hand names for our auto modes.
I’m going to warn you up front; I don’t use C++, I use Java. That being said, I believe the correct way to get your string would be “autoMode = SmartDashboard::GetString(“Auto”, “Default”);”. The first argument is the key you are reading from (on SmartDashboard it should be the title next to the text field) and the second argument is the default that will be used if there is no data.
A better solution would be to use a SenableChooser. The following is for command based but sendable chooser uses void* so the sky is the limit as to what you send. You can send a command, number, or some other pointer.
class Robot : public IterativeRobot
{
private:
SendableChooser* autoChooser;
void RobotInit {
autoChooser = new SendableChoose();
autoChooser->AddDefault("Auto 1", new Auto1Command());
autoChooser->AddObject("Auto 2", new Auto2Command());
autoChooser->AddObject("Auto 3", new Auto3Command());
SmartDashboard::PutData"Auto Chooser", autoChooser;
}
void AutonomousInit() {
Command* auton = (Command*)autoChooser->GetSelected();
if (auton) {
auto->Start();
}
}
void TeleopInit() {
if (auton) {
auto->Cancel();
}
}
};