-
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.
Add components to metabox and fixed toDistance(), toAngle()
- Loading branch information
1 parent
2b7b9e0
commit 21a7deb
Showing
9 changed files
with
414 additions
and
234 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from pyfrc.physics import drivetrains | ||
import math | ||
|
||
|
||
class PhysicsEngine(object): | ||
''' | ||
Simulates a 4-wheel mecanum robot using Tank Drive joystick control | ||
''' | ||
|
||
def __init__(self, physics_controller): | ||
''' | ||
:param physics_controller: `pyfrc.physics.core.Physics` object | ||
to communicate simulation effects to | ||
''' | ||
|
||
self.physics_controller = physics_controller | ||
|
||
# Precompute the encoder constant | ||
# -> encoder counts per revolution / wheel circumference | ||
self.kEncoder = 100 / (0.5 * math.pi) | ||
self.distance = 0 | ||
|
||
|
||
def update_sim(self, hal_data, now, tm_diff): | ||
''' | ||
Called when the simulation parameters for the program need to be | ||
updated. | ||
:param now: The current time as a float | ||
:param tm_diff: The amount of time that has passed since the last | ||
time that this function was called | ||
''' | ||
|
||
# Simulate the drivetrain | ||
# -> Remember, in the constructor we inverted the left motors, so | ||
# invert the motor values here too! | ||
lr_motor = -hal_data['pwm'][6]['value'] | ||
rr_motor = hal_data['pwm'][5]['value'] | ||
lf_motor = -hal_data['pwm'][7]['value'] | ||
rf_motor = hal_data['pwm'][3]['value'] | ||
|
||
vx, vy, vw = drivetrains.mecanum_drivetrain(lr_motor, rr_motor, lf_motor, rf_motor) | ||
self.physics_controller.vector_drive(vx, vy, vw, tm_diff) | ||
|
||
# Update encoders | ||
self.distance += vy * tm_diff | ||
hal_data['encoder'][1]['count'] = int(self.distance * self.kEncoder) |
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
Oops, something went wrong.