Go to Post Here's some food for thought: Does your FRC program need the students, or do the students need your FRC program? - sanddrag [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 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
  #2   Spotlight this post!  
Unread 02-20-2012, 01:18 AM
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,168
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
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
__________________
Fast, cheap or working - pick any two!

Last edited by wireties : 02-20-2012 at 01:44 AM.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-20-2012, 01:30 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?

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
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #4   Spotlight this post!  
Unread 02-20-2012, 01:55 AM
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,168
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Changing parameters on the fly?

Quote:
Originally Posted by bob.wolff68 View Post
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
Yep, wtx console and host shell are both C interpreters. I never use netconsole but I assume it is also. If netconsole is the resident shell accessed via telnet, it definitely is a C interpreter also.

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
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #5   Spotlight this post!  
Unread 02-20-2012, 02:03 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?

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
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #6   Spotlight this post!  
Unread 02-20-2012, 10:00 AM
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,168
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Changing parameters on the fly?

Quote:
Originally Posted by bob.wolff68 View Post
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
This feature is one of the most productive things about Wind River's setup. Remember that it is 'C' interpreter, not C++. To get your symbols into the symbol table (and thus accessible) in a usable format (not mangled by the C++ compiler), be sure to put them inside a extern "C" clause.

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!
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #7   Spotlight this post!  
Unread 02-20-2012, 10:16 AM
rzoeller rzoeller is offline
MN GOFIRST Recruitment Officer
AKA: Ryan Zoeller
FRC #2169 (RI3D 'Snow Problem; KING TeC)
Team Role: Alumni
 
Join Date: Nov 2009
Rookie Year: 2007
Location: Savage, MN
Posts: 111
rzoeller is a jewel in the roughrzoeller is a jewel in the roughrzoeller is a jewel in the rough
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?
__________________
Ri3D - 'Snow Problem Programmer
MN GOFIRST Recruitment Officer
FRC 2169 Alumni
Reply With Quote
  #8   Spotlight this post!  
Unread 02-20-2012, 10:28 AM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,000
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Changing parameters on the fly?

Quote:
Originally Posted by rzoeller View Post
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?
from the original post:

Quote:
Originally Posted by DjScribbles View Post
I've thought about attempting fopen or something like that, but that still requires me to filezilla something down there ( or SSH/terminal somehow into the robot)

Reply With Quote
  #9   Spotlight this post!  
Unread 02-20-2012, 04:30 PM
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Changing parameters on the fly?

Quote:
Originally Posted by wireties View Post
This feature is one of the most productive things about Wind River's setup. Remember that it is 'C' interpreter, not C++. To get your symbols into the symbol table (and thus accessible) in a usable format (not mangled by the C++ compiler), be sure to put them inside a extern "C" clause.
Can you access members of a structure? For example:
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
__________________
Reply With Quote
  #10   Spotlight this post!  
Unread 02-20-2012, 10:03 PM
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,168
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Changing parameters on the fly?

Quote:
Originally Posted by mikets View Post
Can you access members of a structure?

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
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #11   Spotlight this post!  
Unread 02-20-2012, 10:35 PM
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
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
Reply With Quote
  #12   Spotlight this post!  
Unread 03-04-2012, 03:03 PM
pafwl pafwl is offline
Franciose
AKA: Frank Larkin
FRC #0272 (Cyber Crusaders)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 1998
Location: Lansdale, Pennsylvania
Posts: 108
pafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud ofpafwl has much to be proud of
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.
Reply With Quote
  #13   Spotlight this post!  
Unread 03-05-2012, 02:31 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?

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
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #14   Spotlight this post!  
Unread 03-05-2012, 01:28 PM
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,033
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #15   Spotlight this post!  
Unread 03-06-2012, 01:46 AM
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Changing parameters on the fly?

Quote:
Originally Posted by bob.wolff68 View Post
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
Have you filed trackers for these issues? If they aren't tracked we don't know about them and are less likely to fix them.

http://firstforge.wpi.edu/sf/tracker....wpilib_c_bugs

Thanks,
-Joe
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 09:38 AM.

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