-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented specific functions of DrivetrainSubsystem, added SwerveOd…
…ometryCalculator
- Loading branch information
1 parent
d438116
commit 935014c
Showing
7 changed files
with
157 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/frc846/cpp/frc846/robot/swerve/odometry/swerve_odometry_calculator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "frc846/robot/swerve/odometry/swerve_odometry_calculator.h" | ||
|
||
namespace frc846::robot::swerve::odometry { | ||
|
||
SwerveOdometryCalculator::SwerveOdometryCalculator() {} | ||
|
||
SwerveOdometryOutput SwerveOdometryCalculator::calculate( | ||
SwerveOdometryInputs inputs) { | ||
auto module_diffs = inputs.drive_pos - previous_module_positions_; | ||
previous_module_positions_ = inputs.drive_pos; | ||
|
||
frc846::math::Vector2D displacement{0_ft, 0_ft}; | ||
|
||
for (int i = 0; i < 4; i++) { | ||
displacement += | ||
frc846::math::Vector2D{inputs.drive_pos[i], inputs.steer_pos[i], true}; | ||
} | ||
displacement.rotate(inputs.bearing, true); | ||
|
||
last_position_ += displacement; | ||
|
||
return {last_position_}; | ||
} | ||
|
||
} // namespace frc846::robot::swerve::odometry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/frc846/include/frc846/robot/swerve/odometry/swerve_odometry_calculator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include <units/angle.h> | ||
#include <units/length.h> | ||
|
||
#include <array> | ||
|
||
#include "frc846/math/calculator.h" | ||
#include "frc846/math/vectors.h" | ||
|
||
namespace frc846::robot::swerve::odometry { | ||
|
||
struct SwerveOdometryConstants {}; | ||
|
||
struct SwerveOdometryInputs { | ||
units::degree_t bearing; | ||
std::array<units::degree_t, 4> steer_pos; | ||
frc846::math::VectorND<units::inch, 4> drive_pos; | ||
}; | ||
|
||
struct SwerveOdometryOutput { | ||
frc846::math::Vector2D position; | ||
}; | ||
|
||
class SwerveOdometryCalculator | ||
: public frc846::math::Calculator<SwerveOdometryInputs, | ||
SwerveOdometryOutput, SwerveOdometryConstants> { | ||
public: | ||
SwerveOdometryCalculator(); | ||
|
||
SwerveOdometryOutput calculate(SwerveOdometryInputs inputs) override; | ||
|
||
private: | ||
frc846::math::VectorND<units::inch, 4> previous_module_positions_; | ||
|
||
frc846::math::Vector2D last_position_; | ||
}; | ||
|
||
} // namespace frc846::robot::swerve::odometry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ BasedOnStyle: Google, AccessModifierOffset: -2, AlignAfterOpenBracket: DontAlign, AlignConsecutiveAssignments: false, AlignConsecutiveDeclarations: false, AlignEscapedNewlines: Left, AlignOperands: true, AlignTrailingComments: true, AllowAllParametersOfDeclarationOnNextLine: true, AllowShortBlocksOnASingleLine: true, AllowShortCaseLabelsOnASingleLine: true, AllowShortEnumsOnASingleLine: true, AllowShortFunctionsOnASingleLine: true, AllowShortIfStatementsOnASingleLine: true, AllowShortLambdasOnASingleLine: Inline, AllowShortLoopsOnASingleLine: false, AlwaysBreakAfterReturnType: None, AlwaysBreakBeforeMultilineStrings: false, AlwaysBreakTemplateDeclarations: false, BinPackArguments: true, BinPackParameters: true, BreakAfterJavaFieldAnnotations: false, BreakBeforeBinaryOperators: None, BreakBeforeBraces: Attach, BreakBeforeConceptDeclarations: false, BreakBeforeTernaryOperators: true, BreakConstructorInitializersBeforeComma: false, ColumnLimit: 80, CompactNamespaces: false, ConstructorInitializerAllOnOneLineOrOnePerLine: true, ConstructorInitializerIndentWidth: 4, ContinuationIndentWidth: 4, Cpp11BracedListStyle: true, DeriveLineEnding: true, DerivePointerAlignment: true, DisableFormat: false, FixNamespaceComments: false, IndentAccessModifiers: false, IndentCaseLabels: false, IndentExternBlock: AfterExternBlock, IndentPPDirectives: None, IndentWidth: 2, InsertTrailingCommas: None, KeepEmptyLinesAtTheStartOfBlocks: false, MacroBlockBegin: "", MacroBlockEnd: "", MaxEmptyLinesToKeep: 1, NamespaceIndentation: None, PenaltyBreakAssignment: 2, PenaltyBreakBeforeFirstCallParameter: 19, PenaltyBreakComment: 300, PenaltyBreakFirstLessLess: 120, PenaltyBreakString: 1000, PenaltyExcessCharacter: 1000000, PenaltyReturnTypeOnItsOwnLine: 60, PointerAlignment: Left, ReflowComments: true, SortIncludes: true, SortUsingDeclarations: true, SpaceAfterCStyleCast: false, SpaceAfterLogicalNot: false, SpaceAfterTemplateKeyword: true, SpaceAroundPointerQualifiers: Default, SpaceBeforeAssignmentOperators: true, SpaceBeforeCaseColon: false, SpaceBeforeCpp11BracedList: false, SpaceBeforeCtorInitializerColon: true, SpaceBeforeInheritanceColon: true, SpaceBeforeParens: ControlStatements, SpaceBeforeRangeBasedForLoopColon: true, SpaceBeforeSquareBrackets: false, SpaceInEmptyBlock: false, SpaceInEmptyParentheses: false, SpacesBeforeTrailingComments: 2, SpacesInAngles: false, SpacesInCStyleCastParentheses: false, SpacesInContainerLiterals: false, SpacesInParentheses: false, SpacesInSquareBrackets: false, Standard: Auto, TabWidth: 2, UseCRLF: false, UseTab: Never } | ||
{ BasedOnStyle: Google, AccessModifierOffset: -2, AlignAfterOpenBracket: DontAlign, AlignConsecutiveAssignments: false, AlignConsecutiveDeclarations: false, AlignEscapedNewlines: Left, AlignOperands: true, AlignTrailingComments: true, AllowAllParametersOfDeclarationOnNextLine: true, AllowShortBlocksOnASingleLine: true, AllowShortCaseLabelsOnASingleLine: true, AllowShortEnumsOnASingleLine: true, AllowShortFunctionsOnASingleLine: true, AllowShortIfStatementsOnASingleLine: true, AllowShortLambdasOnASingleLine: Inline, AllowShortLoopsOnASingleLine: false, AlwaysBreakAfterReturnType: None, AlwaysBreakBeforeMultilineStrings: false, AlwaysBreakTemplateDeclarations: false, BinPackArguments: true, BinPackParameters: true, BreakAfterJavaFieldAnnotations: false, BreakBeforeBinaryOperators: None, BreakBeforeBraces: Attach, BreakBeforeConceptDeclarations: false, BreakBeforeTernaryOperators: true, BreakConstructorInitializersBeforeComma: false, ColumnLimit: 80, CompactNamespaces: false, ConstructorInitializerAllOnOneLineOrOnePerLine: true, ConstructorInitializerIndentWidth: 4, ContinuationIndentWidth: 4, Cpp11BracedListStyle: true, DeriveLineEnding: true, DerivePointerAlignment: true, DisableFormat: false, FixNamespaceComments: false, IndentAccessModifiers: false, IndentCaseLabels: false, IndentExternBlock: AfterExternBlock, IndentPPDirectives: None, IndentWidth: 2, InsertTrailingCommas: None, KeepEmptyLinesAtTheStartOfBlocks: false, MacroBlockBegin: "", MacroBlockEnd: "", MaxEmptyLinesToKeep: 1, NamespaceIndentation: None, PenaltyBreakAssignment: 2, PenaltyBreakBeforeFirstCallParameter: 19, PenaltyBreakComment: 300, PenaltyBreakFirstLessLess: 120, PenaltyBreakString: 1000, PenaltyExcessCharacter: 1000000, PenaltyReturnTypeOnItsOwnLine: 60, PointerAlignment: Left, ReflowComments: true, SortIncludes: true, SortUsingDeclarations: true, SpaceAfterCStyleCast: false, SpaceAfterLogicalNot: false, SpaceAfterTemplateKeyword: true, SpaceAroundPointerQualifiers: Default, SpaceBeforeAssignmentOperators: true, SpaceBeforeCaseColon: false, SpaceBeforeCpp11BracedList: false, SpaceBeforeCtorInitializerColon: true, SpaceBeforeInheritanceColon: true, SpaceBeforeParens: ControlStatements, SpaceBeforeRangeBasedForLoopColon: true, SpaceBeforeSquareBrackets: false, SpaceInEmptyBlock: false, SpaceInEmptyParentheses: false, SpacesBeforeTrailingComments: 2, SpacesInAngles: false, SpacesInCStyleCastParentheses: false, SpacesInContainerLiterals: false, SpacesInParentheses: false, SpacesInSquareBrackets: false, Standard: Auto, TabWidth: 2, UseCRLF: false, UseTab: Never } |