Go to Post Upon entering FIRST you immediately apply Murphy's Laws. - A_Reed [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 13-02-2015, 12:24
techplex's Avatar
techplex techplex is offline
Blake B
AKA: Blake
FRC #4909 (The Bionics)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2007
Location: Massachusetts
Posts: 95
techplex is just really nicetechplex is just really nicetechplex is just really nicetechplex is just really nice
What is the purpose of RobotMap.java in CommandBased?

Q: What is the purpose of RobotMap.java in CommandBased?

I understand that the actuators, motor controllers, and sensors are all instantiated within. But I feel like it would be more logical to instantiate them in their respective subsystems?

I have tried instantiating the motor actuators etc, in the subsystem and the code does work as expected.

I guess what I am really wondering is what principle of Object Oriented Design, (or any other reason) does RobotBuilder scaffold the code in this way? Does it make the code more maintainable somehow?
__________________
Blake
Electrical, Programming and Design

Creator FRC Q&A 2017
Mass FRC Team 4909: The Bionics
Maine FRC Team 5122: The RobOTies (2014-2015)
Maine FRC Team 2648: Infinite Loop (2008-2011)
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2015, 12:29
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 947
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: What is the purpose of RobotMap.java in CommandBased?

We use RobotMap to store all "robot-wide" constants - i.e. any values that the entire robot would care about.

Stuff like wiring channels (can't double-book a PWM channel), robot-wide deadzone values, etc.

It gives an added benefit of one easy place anyone wiring/inspecting wiring of the robot to look to see how things should be, or were in the past.

This year we also started using static subclasses in RobotMap to make things more readable, especially with the new PD monitoring features.

Ex. we now do

RobotMap.PWMChannels.FRONT_LEFT_DRIVE
RobotMap.PDChannels.FRONT_LEFT_DRIVE

instead of

RobotMap.FRONT_LEFT_DRIVE_PWM_CHANNEL
RobotMap.FRONT_LEFT_DRIVE_PD_CHANNEL

Last edited by BigJ : 13-02-2015 at 12:31.
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2015, 12:30
Fauge7 Fauge7 is offline
Head programmer
FRC #3019 (firebird robotics)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Scottsdale
Posts: 195
Fauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to all
Re: What is the purpose of RobotMap.java in CommandBased?

you are not supposed to instantiate anything! it is meant to hold all the constants of the code, like pwm ports or dio ports.
Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2015, 12:31
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: What is the purpose of RobotMap.java in CommandBased?

It centralizes the allocation of ports in one location, so that you don't need to look everywhere in your code to figure out whether a port is allocated.

In OO-speak, it hides the concern of port mapping in one location in your code, so that the subsystems don't have to know how you have things wired up.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2015, 12:32
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,725
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: What is the purpose of RobotMap.java in CommandBased?

Quote:
Originally Posted by Fauge7 View Post
you are not supposed to instantiate anything! it is meant to hold all the constants of the code, like pwm ports or dio ports.
RobotBuilder does this automatically unfortunately. But I agree, this class should only be used for robot constants like device channels.
Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2015, 12:39
techplex's Avatar
techplex techplex is offline
Blake B
AKA: Blake
FRC #4909 (The Bionics)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2007
Location: Massachusetts
Posts: 95
techplex is just really nicetechplex is just really nicetechplex is just really nicetechplex is just really nice
Re: What is the purpose of RobotMap.java in CommandBased?

I feel like pulling the port numbers out makes a bit more sense than instantiating the actuators etc. in RobotMap.

Either way, you are breaking the separation of concerns and making it harder to transfer the subsystem to a different codebase.
__________________
Blake
Electrical, Programming and Design

Creator FRC Q&A 2017
Mass FRC Team 4909: The Bionics
Maine FRC Team 5122: The RobOTies (2014-2015)
Maine FRC Team 2648: Infinite Loop (2008-2011)
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2015, 12:48
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,725
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: What is the purpose of RobotMap.java in CommandBased?

Quote:
Originally Posted by Techwiz View Post
I feel like pulling the port numbers out makes a bit more sense than instantiating the actuators etc. in RobotMap.

Either way, you are breaking the separation of concerns and making it harder to transfer the subsystem to a different codebase.
By RobotBuilder doing it the way it does it is actually breaking the principle of Encapsulation by giving other objects access to the devices of another subsystem.
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2015, 12:48
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
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);
and have a method like this:

Code:
bool SensorSubsystem::IsElevatorAtLowLimit() { 
	return this->towerLowLimit->Get(); 
}
Then code in other subsystems/commands would say:

Code:
if (sensorSubsystem->IsElevatorAtLowLimit() {
	// turn off motor, or whatever
}
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2015, 13:04
techplex's Avatar
techplex techplex is offline
Blake B
AKA: Blake
FRC #4909 (The Bionics)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2007
Location: Massachusetts
Posts: 95
techplex is just really nicetechplex is just really nicetechplex is just really nicetechplex is just really nice
Re: What is the purpose of RobotMap.java in CommandBased?

Quote:
Originally Posted by MrRoboSteve View Post
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.
Why not put the sensor (limit switch from your example) in your "lift" subsystem. If other subsystems need the value, just provide an accessor?
__________________
Blake
Electrical, Programming and Design

Creator FRC Q&A 2017
Mass FRC Team 4909: The Bionics
Maine FRC Team 5122: The RobOTies (2014-2015)
Maine FRC Team 2648: Infinite Loop (2008-2011)
Reply With Quote
  #10   Spotlight this post!  
Unread 13-02-2015, 13:06
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,725
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: What is the purpose of RobotMap.java in CommandBased?

Quote:
Originally Posted by Techwiz View Post
Why not put the sensor (limit switch from your example) in your "lift" subsystem. If other subsystems need the value, just provide an accessor?
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.
Reply With Quote
  #11   Spotlight this post!  
Unread 13-02-2015, 13:39
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
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.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #12   Spotlight this post!  
Unread 13-02-2015, 14:32
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 403
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
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.
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
2017 - Team 5817: Return of the bench grinder


Reply With Quote
  #13   Spotlight this post!  
Unread 13-02-2015, 15:04
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: What is the purpose of RobotMap.java in CommandBased?

Quote:
Originally Posted by MrRoboSteve View Post
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.
I'm a C++ guy and I think one could solve the problem of subsystems driving other subsystems by making all motor driving functions non-const and all sensor reading functions const. This way one could provide only a const pointer to the other subsystems but non-const pointers to the commands allowing commands to drive the subsystems but not allow the other subsystems to, yet allow both access to sensor readings.

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?
Reply With Quote
  #14   Spotlight this post!  
Unread 13-02-2015, 15:53
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,725
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: What is the purpose of RobotMap.java in CommandBased?

Quote:
Originally Posted by cstelter View Post
I'm a C++ guy and I think one could solve the problem of subsystems driving other subsystems by making all motor driving functions non-const and all sensor reading functions const. This way one could provide only a const pointer to the other subsystems but non-const pointers to the commands allowing commands to drive the subsystems but not allow the other subsystems to, yet allow both access to sensor readings.

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?
Here is an example this year. We have a command that runs a gripper on top of an elevator. I want to be able to do certain things with that gripper, but only when that elevator is below a certain height. The sensor is also used to run a controller that sets the elevator at a different height. Both subsystems want access to the sensor, but the sensor is mainly used with the elevator.

You can accidentally control any subsystem from any command, not sure how its any less easy with a sensor subsystem.

Quote:
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.
I strongly disagree with the second part of this statement, and its the same reason our team does not use the RobotBuilder system. Look up programming principles like Data Hiding and Encapsulation. By putting all of the devices in a storage class you are breaking those principles.

Last edited by notmattlythgoe : 13-02-2015 at 15:56.
Reply With Quote
  #15   Spotlight this post!  
Unread 13-02-2015, 17:20
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 581
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
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.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
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 18:04.

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