Go to Post Engineering is a big, big type of fishing to teach. Inspiring kids to study it in college might be more practical. - connor.worley [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 05-03-2015, 20:32
arichman1257's Avatar
arichman1257 arichman1257 is offline
VP, Control Systems Captain, Coach
AKA: Alan Richman
FRC #1257 (Parallel Universe)
Team Role: Electrical
 
Join Date: Dec 2014
Rookie Year: 2014
Location: Fanwood, New Jersey, USA, Earth...
Posts: 73
arichman1257 will become famous soon enougharichman1257 will become famous soon enough
Use of SmartDashboard::GetString()

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:

Code:
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 05-03-2015, 20:53
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liaison
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 83
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Use of SmartDashboard::GetString()

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.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-03-2015, 00:14
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 191
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: Use of SmartDashboard::GetString()

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.

Code:
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();
    }
}
};
There is more documentation here.
http://wpilib.screenstepslive.com/s/...smartdashboard
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

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


All times are GMT -5. The time now is 19:54.

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