Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondaming committed Dec 12, 2023
1 parent 4e0921c commit 1ff14eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ The locations for the modules must be relative to the center of the robot. Posit
from wpimath.kinematics import SwerveDrive4Kinematics
# Locations for the swerve drive modules relative to the robot center.
m_frontLeftLocation = Translation2d(0.381, 0.381)
m_frontRightLocation = Translation2d(0.381, -0.381)
m_backLeftLocation = Translation2d(-0.381, 0.381)
m_backRightLocation = Translation2d(-0.381, -0.381)
frontLeftLocation = Translation2d(0.381, 0.381)
frontRightLocation = Translation2d(0.381, -0.381)
backLeftLocation = Translation2d(-0.381, 0.381)
backRightLocation = Translation2d(-0.381, -0.381)
# Creating my kinematics object using the module locations
m_kinematics = SwerveDrive4Kinematics(
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation
kinematics = SwerveDrive4Kinematics(
frontLeftLocation, frontRightLocation, backLeftLocation, backRightLocation
)
Converting chassis speeds to module states
Expand Down Expand Up @@ -255,6 +255,6 @@ One can also use the kinematics object to convert an array of ``SwerveModuleStat
frontLeftState, frontRightState, backLeftState, backRightState)
# Getting individual speeds
double forward = chassisSpeeds.vx
double sideways = chassisSpeeds.vy
double angular = chassisSpeeds.omega
forward = chassisSpeeds.vx
sideways = chassisSpeeds.vy
angular = chassisSpeeds.omega
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,31 @@ The fourth optional argument is the starting pose of your robot on the field (as
from wpimath.geometry import Pose2d
from wpimath.geometry import Rotation2d
# Locations for the swerve drive modules relative to the robot center.
m_frontLeftLocation = Translation2d(0.381, 0.381)
m_frontRightLocation = Translation2d(0.381, -0.381)
m_backLeftLocation = Translation2d(-0.381, 0.381)
m_backRightLocation = Translation2d(-0.381, -0.381)
# Creating my kinematics object using the module locations
m_kinematics = SwerveDrive4Kinematics(
m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation
)
# Creating my odometry object from the kinematics object and the initial wheel positions.
# Here, our starting pose is 5 meters along the long end of the field and in the
# center of the field along the short end, facing the opposing alliance wall.
m_odometry = SwerveDrive4Odometry(
m_kinematics, m_gyro.getRotation2d(),
(
m_frontLeftModule.getPosition(),
m_frontRightModule.getPosition(),
m_backLeftModule.getPosition(),
m_backRightModule.getPosition()
),
Pose2d(5.0, 13.5, Rotation2d()))
class MyRobot:
def robotInit(self):
# Locations for the swerve drive modules relative to the robot center.
self.frontLeftLocation = Translation2d(0.381, 0.381)
self.frontRightLocation = Translation2d(0.381, -0.381)
self.backLeftLocation = Translation2d(-0.381, 0.381)
self.backRightLocation = Translation2d(-0.381, -0.381)
# Creating my kinematics object using the module locations
kinematics = SwerveDrive4Kinematics(
frontLeftLocation, frontRightLocation, backLeftLocation, backRightLocation
)
# Creating my odometry object from the kinematics object and the initial wheel positions.
# Here, our starting pose is 5 meters along the long end of the field and in the
# center of the field along the short end, facing the opposing alliance wall.
odometry = SwerveDrive4Odometry(
kinematics, gyro.getRotation2d(),
(
frontLeftModule.getPosition(),
frontRightModule.getPosition(),
backLeftModule.getPosition(),
backRightModule.getPosition()
),
Pose2d(5.0, 13.5, Rotation2d()))
Updating the robot pose
-----------------------
Expand Down Expand Up @@ -144,12 +146,12 @@ This ``update`` method must be called periodically, preferably in the ``periodic
def periodic(self):
# Get the rotation of the robot from the gyro.
gyroAngle = m_gyro.getRotation2d()
gyroAngle = gyro.getRotation2d()
# Update the pose
m_pose = m_odometry.update(gyroAngle,
m_frontLeftModule.getPosition(), m_frontRightModule.getPosition(),
m_backLeftModule.getPosition(), m_backRightModule.getPosition()
self.pose = odometry.update(gyroAngle,
frontLeftModule.getPosition(), frontRightModule.getPosition(),
backLeftModule.getPosition(), backRightModule.getPosition()
)
Resetting the Robot Pose
Expand Down

0 comments on commit 1ff14eb

Please sign in to comment.