-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wpimath] Make a class for a bound vector #7542
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel general enough to belong in wpimath. It's the internal representation of something for a specific tool. I don't see where else one could use this.
* Constructs a vector with the specified position and component vectors. | ||
* | ||
* @param position The position of the vector. | ||
* @param components The X/Y component vectors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "component vectors" here? This variable is poorly named. The two fields in a Translation2d are scalars, not vectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A scalar only has a magnitude while a vector has both direction and magnitude right? The direction can be just the sign of a number, and isn't necessarily an angle. Translation2d.getX()
and Translation2d.getY()
would be vectors in their respective axes. This needs to be made more clear though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translation2d is a 2D vector represented by <x, y>. We don't consider the elements x and y to also be vectors. If we did, what we actually have is a matrix (rank-2 tensor).
x and y in this case represent the magnitudes of the î and ĵ unit vectors.
import edu.wpi.first.util.struct.StructSerializable; | ||
import java.util.Objects; | ||
|
||
/** Represents a bound vector in a vector field. Has an origin, and x/y component vectors. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be defining a lot more terms. What's a "bound vector"? What are "component vectors"? When would someone use this class in their robot code?
wpimath/src/main/java/edu/wpi/first/math/geometry/BoundVector2d.java
Outdated
Show resolved
Hide resolved
wpimath/src/main/java/edu/wpi/first/math/geometry/BoundVector2d.java
Outdated
Show resolved
Hide resolved
* | ||
* @return The X component of the vector. | ||
*/ | ||
public double getXComponent() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really saving much typing over getComponents().getX()
. At least Pose2d.getX()
is a lot shorter than Pose2d.getTranslation().getX()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think we should still include this, it saves a little bit of typing even if it isn't much.
wpimath/src/main/java/edu/wpi/first/math/geometry/BoundVector2d.java
Outdated
Show resolved
Hide resolved
It feels generic enough, as it’s a standard geometry/physics/engineering thing? https://en.m.wikipedia.org/wiki/Vector_quantity |
We already have a type for vectors: https://github.com/wpilibsuite/allwpilib/blob/main/wpimath/src/main/java/edu/wpi/first/math/Vector.java BoundVector2d on the other hand has very limited uses; I can only think of the specific one the OP already mentioned. It belongs in a library published by, say, AdvantageScope, not in wpimath. Lack of general applicability is why several of the utilities SysId uses haven't been moved into wpimath either. |
A bound vector is not a vector. |
It's a vector and point of action, which (1) is only useful for this specific situation, and (2) doesn't interoperate with the other geometry types at all. That's probably why C++'s Eigen and Rust's nalgebra don't have one in their collection of geometry types. |
I still think this is not great.
When would someone need to do that though? If there is an application, is that the most convenient way to accomplish that?
They're useful for trajectory region constraints and bounds checks for robot actions or triggers. |
PathPlanner's swerve setpoint generator and maple-sim both use something like this (a force with a start point) to represent force applied from a swerve module to the ground.
TBH, I'm not 100% sure if it is the most convenient way, but I personally think its up there in terms of convenience to have both the vector and the start point of that vector in one place. I'm not against rewriting this if it means a better way to accomplish the goal. |
It doesn't look like they do. They just have lists of module locations and force magnitudes. I'm also not seeing where a BoundVector type would clean anything up. https://github.com/mjansen4857/pathplanner/blob/main/pathplannerlib/src/main/java/com/pathplanner/lib/util/swerve/SwerveSetpointGenerator.java
If you like it, then put it in the source code of your app that uses it. It doesn't belong in wpimath though. |
The new names are an improvement. |
In AdvantageScope, you can visualize a vector in a vector field by using a
Pose2d
and setting its visualization mode to "Arrow". However, you cannot change the length or color of the arrow, making vector field visualizations usingPose2d
arrays cluttered and hard to read.BoundVector2d
, which this PR adds, is intended for use in vector field visualizations by having both a position relative to origin, and component vectors relative to the position. This class can also be used to represent a force applied on a mechanism, offset from the center of that mechanism.TODO: