Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Grabbing subsystem data to use in another subsystem in Command Based (http://www.chiefdelphi.com/forums/showthread.php?t=127544)

Kyle Chan 06-03-2014 03:20

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)?

wireties 06-03-2014 04:57

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

kylelanman 06-03-2014 07:55

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

DjScribbles 06-03-2014 13:26

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;
}


Joe Ross 12-03-2014 14:08

Re: Grabbing subsystem data to use in another subsystem in Command Based
 
Quote:

Originally Posted by kylelanman (Post 1354329)
All commands inherit CommandBase and CommandBase contains static instances of each subsystem.

Quote:

Originally Posted by DjScribbles (Post 1354547)
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.


All times are GMT -5. The time now is 12:11.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi