-
Notifications
You must be signed in to change notification settings - Fork 1
Spike monitoring #326
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
Open
emilyzucker1
wants to merge
16
commits into
main
Choose a base branch
from
spike_monitoring
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
Spike monitoring #326
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cf22a88
created monitoring node
emilyzucker1 85cdf0f
fixed monitoring node to publish accurate sensor data
emilyzucker1 5f27743
added data monitoring for acceleration in imu
emilyzucker1 1e8fd61
altered spike check
emilyzucker1 5cea841
fixed monitoring node
mohana-pamidi 3b5f980
testing
emilyzucker1 92a71aa
figuring out how why spike always detected
emilyzucker1 c36333c
further testing for spikes
emilyzucker1 9bf304a
fixed continuous spiking
emilyzucker1 41c5e73
cleaning up spikes
emilyzucker1 b034e71
pulling main
Carlosdc25 75a2265
fixed formatting
emilyzucker1 8280b97
Merge branch 'main' into spike_monitoring
zrzz-hq 800078c
publishes on sensor spike custom message
emilyzucker1 ec0c00f
added dvl spike monitoring
emilyzucker1 248ceb4
actually added dvl
emilyzucker1 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
154 changes: 154 additions & 0 deletions
154
src/subjugator/gnc/subjugator_sensor_monitoring/src/monitoring_subs.py
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 |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import rclpy | ||
| from nav_msgs.msg import Odometry | ||
| from rclpy.node import Node | ||
| from sensor_msgs.msg import Imu | ||
| from subjugator_msgs.msg import SensorSpike, SensorSpikeArray | ||
|
|
||
|
|
||
| class MonitoringNode(Node): | ||
| def __init__(self): | ||
| super().__init__("monitoring_node") | ||
| self.data = "" | ||
| self.pub_spike = self.create_publisher(SensorSpikeArray, "spike_monitoring", 10) | ||
| self.array_msg = SensorSpikeArray() | ||
|
|
||
| self.create_subscription(Odometry, "dvl/odom", self.dvl_odom_callback, 10) | ||
| self.create_subscription(Imu, "imu/data", self.imu_data_callback, 10) | ||
|
|
||
| self.imu_accelerationx_array = [] | ||
| self.imu_accelerationy_array = [] | ||
| self.imu_accelerationz_array = [] | ||
|
|
||
| self.dvl_accelerationx_array = [] | ||
| self.dvl_accelerationy_array = [] | ||
| self.dvl_accelerationz_array = [] | ||
|
|
||
| self.in_spike_state_imu_x = False | ||
| self.in_spike_state_imu_y = False | ||
| self.in_spike_state_imu_z = False | ||
|
|
||
| self.in_spike_state_dvl_x = False | ||
| self.in_spike_state_dvl_y = False | ||
| self.in_spike_state_dvl_z = False | ||
|
|
||
| def process_imu(self, value, array, spike_state_attr, axis_name): | ||
|
|
||
| if len(array) <= 20: | ||
| array.append(value) | ||
| else: | ||
| # Calculate average using sum and abs | ||
| avg = sum(abs(val) for val in array) / len(array) | ||
|
|
||
| # Calculate percent difference | ||
| percent_diff = ((abs(value) - avg) / avg) * 100 | ||
|
|
||
| # Check if within threshold | ||
| if -3000 < percent_diff < 3000: | ||
| array.append(value) | ||
| del array[0] | ||
| setattr(self, spike_state_attr, False) | ||
| else: | ||
| if not getattr(self, spike_state_attr): | ||
| # publish a SensorSpike message with details about the detected spike | ||
| msg = SensorSpike() | ||
| msg.header.stamp = self.get_clock().now().to_msg() | ||
| msg.header.frame_id = "imu" | ||
| msg.spike_detected = True | ||
| msg.sensor_type = axis_name | ||
| msg.measured_value = float(value) | ||
| self.array_msg.sensors_status.append(msg) | ||
| setattr(self, spike_state_attr, True) | ||
|
|
||
| def process_dvl(self, value, array, spike_state_attr, axis_name): | ||
| if len(array) <= 20: | ||
| array.append(value) | ||
| else: | ||
| # Calculate average using sum and abs | ||
| avg = sum(abs(val) for val in array) / len(array) | ||
|
|
||
| # Calculate percent difference | ||
| percent_diff = ((abs(value) - avg) / avg) * 100 | ||
|
|
||
| # Check if within threshold | ||
| if -3000 < percent_diff < 3000: | ||
| array.append(value) | ||
| del array[0] | ||
| setattr(self, spike_state_attr, False) | ||
| else: | ||
| if not getattr(self, spike_state_attr): | ||
| # publish a SensorSpike message with details about the detected spike | ||
| msg = SensorSpike() | ||
| msg.header.stamp = self.get_clock().now().to_msg() | ||
| msg.header.frame_id = "dvl" | ||
| msg.spike_detected = True | ||
| msg.sensor_type = axis_name | ||
| msg.measured_value = float(value) | ||
| self.array_msg.sensors_status.append(msg) | ||
| setattr(self, spike_state_attr, True) | ||
|
|
||
| def dvl_odom_callback(self, dmsg: Odometry): | ||
| # Process x-velocity | ||
| self.process_dvl( | ||
| dmsg.twist.twist.linear.x, | ||
| self.dvl_accelerationx_array, | ||
| "in_spike_state_dvl_x", | ||
| "dvl_vel_x", | ||
| ) | ||
|
|
||
| # Process y-velocity | ||
| self.process_dvl( | ||
| dmsg.twist.twist.linear.y, | ||
| self.dvl_accelerationy_array, | ||
| "in_spike_state_dvl_y", | ||
| "dvl_vel_y", | ||
| ) | ||
|
|
||
| # Process z-velocity | ||
| self.process_dvl( | ||
| dmsg.twist.twist.linear.z, | ||
| self.dvl_accelerationz_array, | ||
| "in_spike_state_dvl_z", | ||
| "dvl_vel_z", | ||
| ) | ||
|
|
||
| self.pub_spike.publish(self.array_msg) | ||
|
|
||
| def imu_data_callback(self, imsg: Imu): | ||
| # Process x-axis | ||
| self.process_imu( | ||
| imsg.linear_acceleration.x, | ||
| self.imu_accelerationx_array, | ||
| "in_spike_state_imu_x", | ||
| "lin_accel_x", | ||
| ) | ||
|
|
||
| # Process y-axis | ||
| self.process_imu( | ||
| imsg.linear_acceleration.y, | ||
| self.imu_accelerationy_array, | ||
| "in_spike_state_imu_y", | ||
| "lin_accel_y", | ||
| ) | ||
|
|
||
| # Process z-axis | ||
| self.process_imu( | ||
| imsg.linear_acceleration.z, | ||
| self.imu_accelerationz_array, | ||
| "in_spike_state_imu_z", | ||
| "lin_accel_z", | ||
| ) | ||
|
|
||
| self.pub_spike.publish(self.array_msg) | ||
|
|
||
|
|
||
| def main(args=None): | ||
| rclpy.init(args=args) | ||
| node = MonitoringNode() | ||
| rclpy.spin(node) | ||
| rclpy.shutdown() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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 |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
|
|
||
| std_msgs/Header header | ||
|
|
||
| SensorSpike[] sensorsStatus | ||
| SensorSpike[] sensors_status | ||
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.
The IMU callback function is way too redundant, consider writing private methods to abstract the logic.