|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: What is the purpose of RobotMap.java in CommandBased?
Generally, when using the command-based framework, you instantiate things like speed controllers in the owning subsystem, so that they can be kept hidden from other subsystems. This makes it easier to reason about the subsystem, because you know that all of the logic impacting the motor is in front of you in one file.
3081 commonly creates a special SensorSubsystem that is the owner of nearly all of the sensors on the robot. SensorSubsystem has methods on it that allow other subsystems and commands to read sensor values. For example, suppose your elevator has a limit switch when your traveler is at the lowest desired position. In the SensorSubsystem, you'd say something like (note C++ here, not Java): Code:
this->elevatorLowLimit = new DigitalInput(ELEVATOR_LIMIT_LOW); Code:
bool SensorSubsystem::IsElevatorAtLowLimit() {
return this->towerLowLimit->Get();
}
Code:
if (sensorSubsystem->IsElevatorAtLowLimit() {
// turn off motor, or whatever
}
|
|
#2
|
||||
|
||||
|
Re: What is the purpose of RobotMap.java in CommandBased?
Quote:
|
|
#3
|
|||||
|
|||||
|
Re: What is the purpose of RobotMap.java in CommandBased?
That is the route we take. Subsystems have access to each other so we put accessor methods in each of the subsystems for the values needed.
|
|
#4
|
|||
|
|||
|
Re: What is the purpose of RobotMap.java in CommandBased?
That can be a valid approach, too, if the limit switch is exclusively part of one subsystem. In the past, we've gotten in situations where there's a tangle of subsystem references, only to get access to sensor state. The SensorSubsystem prevents that.
Having one subsystem referencing another also makes it easier to accidentally command the referenced subsystem. This breaks the "requires" model in the command-based framework, which is present to help you reason about where commanding might be coming from. You can certainly produce a correct program by doing so, but it is harder to think about. We deliberately design our robot program so that it is easy to think about. |
|
#5
|
||||
|
||||
|
Re: What is the purpose of RobotMap.java in CommandBased?
Historically we never use a RobotMap class. We have a class that contains all the objects (Talons, Joysticks, etc.) statically so we can do Storage.someTalon.set(1.0) (or just someTalon.set(1.0) since we can import static now). However, this year we do have a RobotMap class to hold constants, and we have all praised its usefulness, especially for when the electronics team needs a port ID. I do agree that RobotMap should just be used for holding constants, not the actual objects, which you should have a separate Storage class for.
|
|
#6
|
|||
|
|||
|
Re: What is the purpose of RobotMap.java in CommandBased?
Quote:
I did a quick look to see if Java provides similar, but it looks like perhaps not. I'm trying to think if the idea of sharing a sensor between two subsystems perhaps indicates that a better subsystem configuration is possible. I'm not sure I like collecting *all* sensors into a globally accessible sensor class-- one subsystem may reset an encoder and mess up code in another for example. I guess I prefer the idea of making access functions in a subsystem that owns a sensor better, but I think it could use further discussion. I suspect perhaps that code in a subsystem that needs a sensor from another subsystem might better be coded in a command that requires both subsystems. But I think I can also think of counterexample where that won't work well. Can you give a good concrete example where two subsystems require a single sensor so we can kick around various approaches to resolve it within the command based paradigm? |
|
#7
|
|||||
|
|||||
|
Re: What is the purpose of RobotMap.java in CommandBased?
Quote:
You can accidentally control any subsystem from any command, not sure how its any less easy with a sensor subsystem. Quote:
Last edited by notmattlythgoe : 13-02-2015 at 15:56. |
|
#8
|
|||
|
|||
|
Re: What is the purpose of RobotMap.java in CommandBased?
Craig's notion of using static methods to expose the sensors is another approach that's worth considering. Note that we don't expose the sensor object directly in our sensor subsystem; we have getter methods that return higher level states, based on the sensor state.
notmattlythgoe's example is a good one. In general, one category is where you have two subsystems that occupy the same space, and one subsystem wants to verify that the other subsystem isn't present. Another example might be a sonar that points out of the front of the robot. The robot's drive train uses the sonar as an input to slow down as it approaches an object. The robot might also have a light that flashes that indicates an object is close. Or your elevator keeps track of the number of totes in the elevator, and you change drive train behavior based on the number of totes. |
|
#9
|
|||||
|
|||||
|
Re: What is the purpose of RobotMap.java in CommandBased?
If that works for you, fine, but it's not O-O. The sensors and actuators that work together should be part of the same subsystem. In particular, limit switches, encoders, and potentiometers whose purpose is to provide feedback on a particular actuator should be in the same subsystem with that actuator.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|