diff --git a/config/esw.yaml b/config/esw.yaml index f0a78c30f..cff8e0030 100644 --- a/config/esw.yaml +++ b/config/esw.yaml @@ -1,5 +1,5 @@ imu_driver: - port: "/dev/imu" + port: "/dev/tty.usbmodem101" baud: 115200 frame_id: "imu_link" diff --git a/launch/auton.launch b/launch/auton.launch new file mode 100644 index 000000000..3d63c02b6 --- /dev/null +++ b/launch/auton.launch @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launch/auton_sim.launch b/launch/auton_sim.launch new file mode 100644 index 000000000..49b224d10 --- /dev/null +++ b/launch/auton_sim.launch @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launch/localization.launch b/launch/localization.launch index f9491cafa..2f14c13ae 100644 --- a/launch/localization.launch +++ b/launch/localization.launch @@ -30,4 +30,6 @@ + + \ No newline at end of file diff --git a/src/esw/imu_driver.py b/src/esw/imu_driver.py index 1921e8bef..6b7bde5de 100755 --- a/src/esw/imu_driver.py +++ b/src/esw/imu_driver.py @@ -4,7 +4,7 @@ from sensor_msgs.msg import Temperature, Imu, MagneticField from geometry_msgs.msg import Quaternion, Vector3, PoseWithCovarianceStamped, PoseWithCovariance, Vector3Stamped, Pose from std_msgs.msg import Header -from mrover.msg import CalibrationStatus, ImuAndMag +from mrover.msg import ImuAndMag, CalibrationStatus from tf.transformations import quaternion_about_axis, quaternion_multiply, rotation_matrix, quaternion_from_matrix from typing import Tuple, List from copy import deepcopy diff --git a/src/localization/tip_detection.py b/src/localization/tip_detection.py new file mode 100755 index 000000000..a6d6415a9 --- /dev/null +++ b/src/localization/tip_detection.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 + +import tf2_ros +import numpy as np +import rospy +from std_msgs.msg import Bool +from util.SE3 import SE3 +import time + + +class TipDetection: + hit_count: int + orientation_threshold: float + hit_count_threshold: int + reset_hit_count_threshold: int + time_counter: time + current_time: time + tip_publisher: rospy.Publisher + + def __init__(self): + self.tip_publisher = rospy.Publisher("tipping", Bool, queue_size=1) + + self.hit_count = 0 + self.orientation_threshold = 0.8 + self.hit_count_threshold = 10 + self.reset_hit_count_threshold = 3 + self.time_counter = time.time() + self.current_time = time.time() + + self.buffer = tf2_ros.Buffer() + self.tf_listener = tf2_ros.TransformListener(self.buffer) + self.world_frame = rospy.get_param("world_frame") + self.rover_frame = rospy.get_param("rover_frame") + time.sleep(2) + self.in_loop() + + def in_loop(self): + rate = rospy.Rate(10.0) + while not rospy.is_shutdown(): + try: + # extract yaw + self.old = SE3.from_tf_tree(self.buffer, self.world_frame, self.rover_frame).rotation.rotation_matrix() + + # multiply yaw by the z vector [0, 0, 1] to get new transform + self.transform = np.dot(np.array([0, 0, 1]), self.old) + + # compare this new transform with our threshold to see if it's tipping, if so increment hit_count + if self.transform[2] <= self.orientation_threshold: + self.hit_count += 1 + + self.check_for_hit_count(self.hit_count) + + except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException) as e: + print(e) + rate.sleep() + # reset the hit count time + self.current_time = time.time() + self.reset_hit_count_time(self.reset_hit_count_threshold, self.time_counter) + + # check if hit_count is too big + def check_for_hit_count(self, hit_count): + # if hit_count exceeds threshold + if hit_count > self.hit_count_threshold: + # publishing into tip_publisher that rover is tipping, True + self.tip_publisher.publish(True) + else: # else publish False + self.tip_publisher.publish(False) + + # reset hit_count each reset_hit_count_threshold seconds + def reset_hit_count_time(self, reset_hit_count_threshold, time_counter): + # if the amount of time that's passed since last reset > threshold, reset hit_count + if time.time() - self.time_counter > self.reset_hit_count_threshold: + self.hit_count = 0 + self.time_counter = time.time() + + +def main(): + rospy.init_node("tip_detection") + TipDetection() + + rospy.spin() + + +if __name__ == "__main__": + main() diff --git a/starter_project/autonomy/AutonomyStarterProject.cmake b/starter_project/autonomy/AutonomyStarterProject.cmake index 4b84c75af..d8873b08a 100644 --- a/starter_project/autonomy/AutonomyStarterProject.cmake +++ b/starter_project/autonomy/AutonomyStarterProject.cmake @@ -8,7 +8,7 @@ add_message_files( DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/msg FILES - #add new messages here + StarterProjectTag.msg ) # Collect all cpp files in the src subdirectory to be used for perception diff --git a/starter_project/autonomy/launch/starter_project.launch b/starter_project/autonomy/launch/starter_project.launch index d169e1c61..f130a0d34 100644 --- a/starter_project/autonomy/launch/starter_project.launch +++ b/starter_project/autonomy/launch/starter_project.launch @@ -29,7 +29,7 @@ Perception ========== --> - +