Go to Post If enough students "get it," the team will begin to. And if enough students "get it," the smart ones will seek out all the extra help they can get. That's how I found Chiefdelphi... - Joe G. [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 06-03-2014, 03:20
Kyle Chan's Avatar
Kyle Chan Kyle Chan is offline
Registered User
FRC #0368 (Kika Mana)
Team Role: Programmer
 
Join Date: May 2013
Rookie Year: 2012
Location: Honolulu
Posts: 7
Kyle Chan is an unknown quantity at this point
Grabbing subsystem data to use in another subsystem in Command Based

Just as the title states, how would I retrieve a variable from one subsystem to implement in another subsystem? For example, if I had a dedicated sensor subsystem, is there any way that I could call a method (which returned the sensor value) from within the sensor subsystem to be used in a method in another subsystem (for example, the collector)?
Reply With Quote
  #2   Spotlight this post!  
Unread 06-03-2014, 04:57
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,170
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: Grabbing subsystem data to use in another subsystem in Command Based

This is really just a classic C++ question. If a method or member in one class is public any other code (in the same space that has a handle/pointer to the class) can access the member or call the method. In practice it is wiser to keep everything things private and add public methods to access your private data. This way your data (or devices) controlled by the object have only carefully defined external interfaces, making your objects more "coherent".

HTH
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #3   Spotlight this post!  
Unread 06-03-2014, 07:55
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: 189
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: Grabbing subsystem data to use in another subsystem in Command Based

Keeping with the intent of the Command Based programming approach the only way to accomplish what you are asking is in commands. All commands inherit CommandBase and CommandBase contains static instances of each subsystem. In your command you could get the value of a sensor from your sensor subsystem and then based on it's value call different methods in your collector subsystem. This year we had a DistanceSensor subsystem. It essentially provided the distance we were from the goal in feet via a getDistance method. Our shooter had a setDistance method. In a command called AutoSetShooter we did the following. shooter->setDistance(distanceSensor->getDistance());

Depending on the application it might be better to restructure your subsystems so that the corresponding sensors for your collector are in your collector subsystem. The best example of this is limit switches and pots. They belong in the same subsystem that the actuator is in.

Kyle
__________________
"May the coms be with you"

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

Reply With Quote
  #4   Spotlight this post!  
Unread 06-03-2014, 13:26
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Grabbing subsystem data to use in another subsystem in Command Based

Yes, you can access other subsystems to get information; depending on how strictly you want to adhere to the command based approach, this may be 'cheating' a little, but for read only access it doesn't do any harm.

The Robot class has static instances of all subsystems, so you can access them from anywhere that includes Robot.h (just as is done in commands).

The syntax is as follows:
Code:
bool ShooterPiston::Fire()
{
    bool returnValue = false;
    
    if ((Robot::shooterWheels->IsUpToSpeed() == true) &&
        (Robot::shooterArm->IsOnTarget() == true) &&
         ....
    {
        firingSolenoid->Set(DoubleSolenoid::kReverse);
        returnValue = true;
    }
    return returnValue;
}
Reply With Quote
  #5   Spotlight this post!  
Unread 12-03-2014, 14:08
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Grabbing subsystem data to use in another subsystem in Command Based

Quote:
Originally Posted by kylelanman View Post
All commands inherit CommandBase and CommandBase contains static instances of each subsystem.
Quote:
Originally Posted by DjScribbles View Post
The Robot class has static instances of all subsystems, so you can access them from anywhere that includes Robot.h (just as is done in commands).
In case anyone is confused, both Kyle and Joe are correct, depending on how you started your project. Currently, if you build your build your project with the Windriver plugins, you get a CommandBase that contains all subsystems. If you use RobotBuilder, the Robot class contains all subsystems.
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 14:09.

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