generated from athackst/vscode_ros2_workspace
-
Notifications
You must be signed in to change notification settings - Fork 2
Updated physics engine to use wind sensor #429
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
Closed
arynrosh
wants to merge
3
commits into
main
from
user/arynrosh/update-physics-eng-to-use-wind-sensor-426
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -110,8 +110,9 @@ def __init_private_attributes(self): | |
self.__rudder_angle = 0 | ||
self.__sail_trim_tab_angle = 0 | ||
self.__desired_heading = None | ||
self._wind_sensor = WindSensor() | ||
self.__boat_state = BoatState( | ||
0.5, 1, np.array([[0.5, 0.5, 0.5], [0.0, 0.5, 0.5], [0.0, 0.0, 0.5]], dtype=np.float32) | ||
0.5, Constants.BOAT_PROPERTIES.mass, Constants.BOAT_PROPERTIES.inertia | ||
) | ||
self.__wind_generator = FluidGenerator( | ||
generator=MVGaussianGenerator(np.array([5, 5]), np.array([[2, 1], [1, 2]])) | ||
|
@@ -120,6 +121,12 @@ def __init_private_attributes(self): | |
generator=MVGaussianGenerator(np.array([1, 1]), np.array([[2, 1], [1, 2]])) | ||
) | ||
|
||
def __update_wind_sensor(self): | ||
"""Updates the wind sensor with the latest wind data from the wind generator.""" | ||
wind_data = self.__wind_generator.next() | ||
self.__wind_sensor.speed.speed = wind_data[0] | ||
self.__wind_sensor.direction = wind_data[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def __declare_ros_parameters(self): | ||
"""Declares ROS parameters from the global configuration file that will be used in this | ||
node. This node will monitor for any changes to these parameters during execution and will | ||
|
@@ -279,6 +286,7 @@ def __init_timer_callbacks(self): | |
# PUBLISHER CALLBACKS | ||
def __publish(self): | ||
"""Synchronously publishes data to all publishers at once.""" | ||
self.__update_wind_sensor() | ||
self.__update_boat_state() | ||
# TODO Get updated boat state and publish (should this be separate from publishing?) | ||
# TODO Get wind sensor data and publish (should this be separate from publishing?) | ||
|
@@ -307,16 +315,16 @@ def __publish_gps(self): | |
def __publish_wind_sensors(self): | ||
"""Publishes mock wind sensor data.""" | ||
# TODO Update to publish real data | ||
windSensor1 = WindSensor() | ||
windSensor1.speed.speed = 0.0 | ||
windSensor1.direction = 0 | ||
# windSensor1 = WindSensor() | ||
# windSensor1.speed.speed = 0.0 | ||
# windSensor1.direction = 0 | ||
|
||
windSensor2 = WindSensor() | ||
windSensor2.speed.speed = 0.0 | ||
windSensor2.direction = 0 | ||
# windSensor2 = WindSensor() | ||
# windSensor2.speed.speed = 0.0 | ||
# windSensor2.direction = 0 | ||
|
||
msg = WindSensors() | ||
msg.wind_sensors = [windSensor1, windSensor2] | ||
msg.wind_sensors = [self.__wind_sensor] * 2 # Accounts for two sensors with identical data | ||
|
||
self.wind_sensors_pub.publish(msg) | ||
self.get_logger().info( | ||
|
@@ -562,7 +570,8 @@ def __update_boat_state(self): | |
sail_trim_tab_angle. | ||
""" | ||
self.__boat_state.step( | ||
self.__wind_generator.next(), | ||
self.__wind_sensor, | ||
# self.__wind_generator.next(), | ||
self.__current_generator.next(), | ||
self.__rudder_angle, | ||
self.__sail_trim_tab_angle, | ||
|
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.
I just happened to stumble upon this. You shouldn't have to assign the private members in this way. The update method is there to help you out, and you get additional functionality with noise/delays if you want. Try
self.update(wind=wind_data[0])
?See the wind sensor tests for an example of this type of call.