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.
Created depth sensor plugin that took the position of the plugin and published that negative value to the depth topic. Gaussian noise can be added to the measurements from the sensor to mimic real life inaccuracies . The depth sensor plugin is a model plugin, which is relevant because it connects the sensor at the model level. SDF values of the sensor include:
I would like to note that the noise_stddev has been set to 0 in sub9.urdf.xacro
Getting Measurement
Using the Entity Component Manager(ECM) we receive a pointer to a Pose component and using the Data() function we can access the location of the entity in 3d space. Then, we update the position gotten by adding the position and rotation of by the offset. A rotation given by the offset does not really matter since we are just measuring depth. The z axis position multiplied by -1 becomes our depth. The depth is in meters btw.
Gaussian Noise
Currently, I have a random seed for the random number generator, that may be something that could want to be changed. Essentially, the way the noise is created is by making a normal distribution from the mean and stddev gotten from the sdf and then getting random number from that distribution and adding that number to the depth. Currently, if the depth exceeds zero the depth gets turned to simply zero.
In the older mil repository mil_msg::DepthStamped was used for messages so for that reasons I added find_package(mil_msgs REQUIRED) to CMakeList.txt and dependency(mil_msgs) to package.xml.
Running this code
To run run the code in one terminal run from the mil2 directory:
colbuild
ros2 launch subjugator_bringup gazebo.launch.py
Then from another terminal run:
source ~/mil2/install/setup.bash
(you might get a message saying not found, but to my understanding it still helps.)
ros2 topic echo /depth
Make sure to click play on the simulator to see the depth messages and you should be good to go.
Photos


This first photo shows the sub floating on the surface with a stddev of 0.1:
This photo shows the sub also floating at the surface but with a stddev of 0: