generated from athackst/vscode_ros2_workspace
-
Notifications
You must be signed in to change notification settings - Fork 2
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
404 Complete Boat State Class #432
Open
stevenxu27
wants to merge
41
commits into
main
Choose a base branch
from
user/stevenxu27/404-Complete-Boat-State-Class
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
5c82f48
Migrate changes for issue 306
DFriend01 f2ae1b7
Controller implementation fixes
stevenxu27 89895c4
New controller implementation changes, need to test more
stevenxu27 301687f
Finished optimization objectives for controller implementation
stevenxu27 99e722e
Test cases almost completed
stevenxu27 60bf855
Finish actuation testing for sail and rudder controller
stevenxu27 b045eac
Testing and controller fixes
stevenxu27 4e2756e
Constant.py clarification
stevenxu27 4e44354
taking running _error out of init
stevenxu27 59db804
Controller Clean-up
stevenxu27 d8e0d19
Quick fixes
stevenxu27 0d1ca0e
Reset called upon class initialization
stevenxu27 2a57520
Made setpoint function private
stevenxu27 02a6f13
Test case fixes
stevenxu27 6461bbe
Start
stevenxu27 ade6f19
Pull from main
stevenxu27 35ac17a
Model Testing
stevenxu27 50874ae
Model Calculations
stevenxu27 5cad061
Sail and Rudder Lengths
stevenxu27 00f5803
ndarray implementation
stevenxu27 f8470e0
Refactor
stevenxu27 d220f62
Merge branch 'main' into user/stevenxu27/404-Complete-Boat-State-Class
stevenxu27 19869b5
Working on torque calculations
stevenxu27 57d53f1
Torque Calculations with Placeholders
stevenxu27 28e67af
Torque Calculations with Placeholders
stevenxu27 534994d
Declaring Constants
stevenxu27 36de344
Created test file
stevenxu27 b37fd9c
Dot Product error
stevenxu27 90d9b58
Testing changes
stevenxu27 dc85627
Merge branch 'main' of https://github.com/UBCSailbot/sailbot_workspac…
stevenxu27 b6697d5
Tentative testing complete
stevenxu27 39dd77f
Rerun tests
stevenxu27 51ba15f
Syntax fixes
stevenxu27 af195a3
Merge branch 'main' of https://github.com/UBCSailbot/sailbot_workspac…
stevenxu27 cc40293
Assertion for zero velocity vector error
stevenxu27 94f684f
Reverted prototype_wingsail_controller.ipynb
stevenxu27 98b481b
Revert "Reverted prototype_wingsail_controller.ipynb"
stevenxu27 94f3df9
Revert Controller Prototype Notebook
stevenxu27 b95ed26
Delete settings.json
stevenxu27 a94ee9b
Trying to fix environment test cases
stevenxu27 6a4d9ec
Merge branch 'main' of https://github.com/UBCSailbot/sailbot_workspac…
stevenxu27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
86 changes: 84 additions & 2 deletions
86
src/boat_simulator/tests/unit/nodes/physics_engine/test_model.py
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,5 +1,87 @@ | ||
"""Tests classes and functions in boat_simulator/nodes/physics_engine/model.py""" | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
class TestBoatState: | ||
pass | ||
from boat_simulator.common.constants import BOAT_PROPERTIES | ||
from boat_simulator.nodes.physics_engine.model import BoatState | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"rel_wind_vel, rel_water_vel, rudder_angle_deg, trim_tab_angle, timestep", | ||
[ | ||
(np.array([1, 2]), np.array([1, 2]), 45, 45, 1), | ||
(np.array([1, 2]), np.array([1, 2]), 45, 45, 1), | ||
(np.array([4, 5]), np.array([7, 8]), 30, 60, 2), | ||
(np.array([10, 20]), np.array([15, 25]), 90, 120, 1), | ||
(np.array([0, 1]), np.array([1, 1]), 0, 90, 3), | ||
(np.array([-1, -2]), np.array([-1, -2]), 180, 270, 2), | ||
(np.array([3.5, 4.5]), np.array([1.5, 2.5]), 15, 75, 4), | ||
(np.array([100, 200]), np.array([300, 200]), 0, 45, 2), | ||
# cannot use 0 vector, or will error | ||
], | ||
) | ||
def test_compute_net_force_torque( | ||
rel_wind_vel, | ||
rel_water_vel, | ||
rudder_angle_deg, | ||
trim_tab_angle, | ||
timestep, | ||
): | ||
|
||
current_state = BoatState(timestep) | ||
net_force = current_state._BoatState__compute_net_force_and_torque( | ||
rel_wind_vel, rel_water_vel, rudder_angle_deg, trim_tab_angle | ||
) | ||
|
||
app_wind_vel = np.subtract(rel_wind_vel, current_state.relative_velocity[0:2]) | ||
app_water_vel = np.subtract(rel_water_vel, current_state.relative_velocity[0:2]) | ||
|
||
wind_angle = np.arctan2(app_wind_vel[1], app_wind_vel[0]) | ||
trim_tab_angle_rad = np.radians(trim_tab_angle) | ||
main_sail_angle = wind_angle - trim_tab_angle_rad | ||
rudder_angle_rad = np.radians(rudder_angle_deg) | ||
|
||
test_sail_force = current_state._BoatState__sail_force_computation.compute( | ||
app_wind_vel, trim_tab_angle | ||
) | ||
test_rudder_force = current_state._BoatState__rudder_force_computation.compute( | ||
app_water_vel, rudder_angle_deg | ||
) | ||
|
||
hull_drag_force = current_state.relative_velocity[0:2] * BOAT_PROPERTIES.hull_drag_factor | ||
|
||
total_drag_force = test_sail_force[1] + test_rudder_force[1] + hull_drag_force | ||
total_force = test_sail_force[0] + test_rudder_force[0] + total_drag_force | ||
|
||
sail_drag = np.linalg.norm(test_sail_force[1], ord=2) | ||
sail_lift = np.linalg.norm(test_sail_force[0], ord=2) | ||
|
||
sail_lift_constant = ( | ||
BOAT_PROPERTIES.mast_position[1] | ||
- (BOAT_PROPERTIES.sail_dist * np.cos(main_sail_angle)) | ||
- BOAT_PROPERTIES.centre_of_gravity[1] | ||
) | ||
|
||
sail_drag_constant = BOAT_PROPERTIES.sail_dist * np.sin(main_sail_angle) | ||
|
||
sail_torque = np.add(sail_drag * sail_drag_constant, sail_lift * sail_lift_constant) | ||
|
||
rudder_drag = np.linalg.norm(test_rudder_force[1], ord=2) | ||
rudder_lift = np.linalg.norm(test_rudder_force[0], ord=2) | ||
|
||
rudder_drag_constant = BOAT_PROPERTIES.rudder_dist * np.sin(rudder_angle_rad) | ||
|
||
rudder_lift_constant = ( | ||
BOAT_PROPERTIES.rudder_dist * np.cos(rudder_angle_rad) | ||
+ BOAT_PROPERTIES.centre_of_gravity[1] | ||
) | ||
|
||
rudder_torque = np.add(rudder_lift * rudder_lift_constant, rudder_drag * rudder_drag_constant) | ||
|
||
total_torque = np.add(sail_torque, rudder_torque) | ||
|
||
final_torque = np.array([0, 0, total_torque]) | ||
|
||
assert np.allclose(total_force, net_force[0], 0.5) # checking force | ||
assert np.allclose(final_torque, net_force[1], 0.5) # checking torque |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please check if slicing (
[0:2]
) is still necessary after fluid generation update.