View Single Post
  #5   Spotlight this post!  
Unread 02-20-2012, 01:02 AM
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 152
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Changing parameters on the fly?

Alright folks,

I've got answers....

Indeed - we agree that SmartDashboard::GetInstance()->GetDouble("name") does not work...however, we did find that GetString() **DOES** work. So, here's an iterative solution...

1) You **MUST** use the smartdashboard app on a separate computer due to the fact that hitting ENTER will disable the robot.

2) You must retrieve your "double values" as strings and then convert them to double/float values... see below...

3) When in operation, you simply tune your PID values by entering a new value into one of the boxes and hitting ENTER (on the 2nd laptop....see #1) and the new value will be put into the PIDController immediately so you can see the difference. When you're happy with the results, record your P,I, and D and put those into your real code. Tada.

Bob...

Code:
PIDController pid(0.00, 0.00, 0.00, &encoder, &motor);
SmartDashboard* smarty=SmartDashboard::GetInstance();
// Initially gotta put some value in order to get SmartDashboard 
// to create a textbox for the value...
// Simply calling GetString() will not produce a box...
smarty->PutString("P-value", "0.0");
smarty->PutString("D-value", "0.0");
smarty->PutString("D-value", "0.0");

std::string tempstring;
float p, i, d;

// Initialize the pid...these values I cannot tell you .... 
// They depend on your situation
pid.SetInputRange(.....);
pid.SetOutputRange(.....);
pid.SetSetpoint(.....);
pid.Enable();

while (IsOperatorControl())
{
  tempstring = smarty->GetString("P-value");
  sscanf(tempstring.c_str(), "%f", &p);

  tempstring = smarty->GetString("I-value");
  sscanf(tempstring.c_str(), "%f", &i);

  tempstring = smarty->GetString("D-value");
  sscanf(tempstring.c_str(), "%f", &d);

  pid.SetPID(p, i, d);
}
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote