|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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);
}
|
|
#2
|
||||
|
||||
|
Re: Changing parameters on the fly?
The shell provided for the operating system is really a C interpreter. So you can define a global in your code then simply change its value from the command line.
in your C++ code: extern "C" { float iMyPidGain; } then from the VxWorks shell: % iMyPidGain = 0.001 Last edited by wireties : 02-20-2012 at 01:44 AM. |
|
#3
|
||||
|
||||
|
Re: Changing parameters on the fly?
Keith,
Are you talking about the terminal console via the VxWorks menu (ie. Netconsole output) ?? I've never heard of this...can you point to some documentation on it? bob |
|
#4
|
||||
|
||||
|
Re: Changing parameters on the fly?
Quote:
Help->Help Contents->Wind River Documentation->Guides->Host Tools->Wind River Workbench Host Shell Users Guide->Part 1->Using C Interpreter with VxWorks 6.X |
|
#5
|
||||
|
||||
|
Re: Changing parameters on the fly?
This is really big news that I believe VERY few people know of...if I have 'external' access (on the fly) to my program's variables in an interpretive way, well...the possibilities are HUGE.
I'll be trying this with my programmers tomorrow for sure! bob - Team 1967 Mentor - The Janksters |
|
#6
|
||||
|
||||
|
Re: Changing parameters on the fly?
Quote:
We use this all the time: to turn on/off the collection of data, play with operating params (like PID constants), enable/disable features while debugging etc. It definitely works! Good luck! |
|
#7
|
|||
|
|||
|
Re: Changing parameters on the fly?
I personally use LV, so this problem is trivial for us, but would it be possible to have a CSV file stored on the robot that it reads from? So that if you modify the values, it's behavior will change?
|
|
#8
|
||||
|
||||
|
Re: Changing parameters on the fly?
Quote:
Quote:
|
|
#9
|
||||
|
||||
|
Re: Changing parameters on the fly?
Quote:
Code:
in your C++ code:
extern "C" {
typedef struct _PIDConst
{
float Kp;
float Ki;
float Kd;
} PIDConst;
PIDConst iMyPidGain;
}
then from the VxWorks shell:
% iMyPidGain.Kp = 0.001
|
|
#10
|
||||
|
||||
|
Re: Changing parameters on the fly?
No - can't do that directly. The interpreter does not have the benefit of things the compiler/preprocessor would know. Constants are also of no use. If you know the offsets into the structure you can do it manually with the memory modify commands. HTH |
|
#11
|
|||
|
|||
|
Re: Changing parameters on the fly?
Wow - I just tried it and it certainly works. Really cool.
If only there was an inverse of c++filt... The debugger also provides a nice way to do this, but with more complex multithreaded applications debugging's bound to get tricky... SmartDashboard is the future though. Once they can actually get it working, that is ![]() |
|
#12
|
|||
|
|||
|
Re: Changing parameters on the fly?
We do this all the time. We have many variables that we can adjust all the time.
you can see the code as part of our 2010 code. http://www.frc272.com/seminar/Archive/. We call the LCConfig.cpp. You can change the config file, save it via FTP to the Crio, press a button and have it read in to the running code then have it apply the new settings. Once you like them leave it there. The config is read in when we boot up. Very flexible. |
|
#13
|
||||
|
||||
|
Re: Changing parameters on the fly?
Well - we gave a shot at the interactive input on SmartDashboard with no luck. It all works on a separate computer as we've all noted, but otherwise...sigh. We tried to also put a button on the SmartDashboard so we could interactively click on the button ... no go...
So, SmartDashboard::GetInstance()->GetDouble() doesn't work... so we use GetString() and then sscanf() to turn it into a double. Also, using Preferences::GetInstance()->PutString() doesn't work, but PutDouble() and PutInt() work just fine. bob |
|
#14
|
||||
|
||||
|
Re: Changing parameters on the fly?
You should check out the SendablePIDController, which is part of the SmartDashboard. I'm not sure if it works in C++ because of the double issue... but it works for me in python
![]() And, before there was SmartDashboard, there was WebDMA, which does the same thing as SmartDashboard except with a webserver on your robot. ![]() |
|
#15
|
|||
|
|||
|
Re: Changing parameters on the fly?
Quote:
http://firstforge.wpi.edu/sf/tracker....wpilib_c_bugs Thanks, -Joe |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|