one sensor multiple subsystems

What is the best way to use a gyro or rangefinder sensor in multiple subsystems? For example we have a gyro from KOP and have subsystems for chassis and cannon turret how do we get the data for both subsystems? I have a couple ideas but was wondering how others did it.

Also wasn’t sure on the best way to structure this. Here is what we are doing:

  • we have a drive subsystem and turret subystem (and others)
  • gyro is part of our drive (chassis) subsystem
  • we have a Command call SetTurretAngle
  • SetTurretAngle requires the turret subystem
  • SetTurretAngle does NOT require the drive subystem. I don’t want it to prevent commands that require the drive subsystem from running. We are accessing the gyro thru the drive subsytem but we are not actuating anything within the drive so I feel that it is safe. I don’t think there are multi-threading issues because I think the scheduler is a single thread.

This is what the implementation of the SetTurretAngle Command looks like:

void SetTurretAngleCommand::Execute() {
	turretSubsystem->SetTurretAngle(-1.0 * driveSubsystem->GetHeading());
}

In a similar vein. I wasn’t sure where to put my Compressor object. I considered making a pneumatics subystem. The solenoid valves that actually actuate things will be part of their respective subsytem though. I decided the pneumatics are like the battery, just a source of energy that all the subystems could use. Ended up making the compressor a member CommandBase and will allocate the Solenoids to their respective subsystems.

Our team just created a gyro subsystem and then called it in the classes we needed.

If the sensor isn’t truly part of a subsystem, I don’t make it part of one. I just declare it as public static final in CommandBase and access it from there.

Most of my raw hardware things are declared this way in CommandBase; It seemed more elegant to me to give CAN/DIO/AIO IDs or SpeedController objects to subsystems’ constructors. This way CommandBase basically acts like RobotMap (I deleted RobotMap).