Skip to content
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

Steering angle rate check #56

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions rb_ws/src/buggy/scripts/validation/steering_angle_rate_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# A script to log battery data to a .txt file

import csv
import rospy
from std_msgs.msg import Float64,Bool # Callback function to print the subscribed data on the terminal

file = open('steering_data.txt', 'w', newline='')
writer = csv.writer(file)
writer.writerow(["Time", "steering_angle", "steering_angle_rate"])

class SteeringAngleRateChecker:
def __init__(self):
self.last_time_stamp = rospy.Time.now()
self.steering_data_rate = 0
self.last_steering_data = 0
# threshold value and steering angle r in degree per second
self.threshold_steering_data_rate = 100
self.velocity_publisher = rospy.Publisher("SteeringAngleRate",
Float64, queue_size=10)
self.flag_publisher = rospy.Publisher("SteeringAngleRateFlag",
Bool, queue_size=10)
rospy.Subscriber("/SC/buggy/input/steering", Float64,
self.callback_steering_angle)

def callback_steering_angle(self, steering_data):
current_time = rospy.Time.now()
self.steering_data_rate = (steering_data.data-self.last_steering_data) \
/ rospy.Time.to_sec(current_time-self.last_time_stamp)
self.steering_data_rate_flag = bool((abs(self.steering_data_rate) > \
self.threshold_steering_data_rate))
self.last_time_stamp = current_time
self.last_steering_data = steering_data.data
self.steering_steering_data_rate_publisher()
writer.writerow([current_time, steering_data.data,
self.steering_data_rate])

def steering_steering_data_rate_publisher(self):
velocity_message = Float64()
velocity_message.data = self.steering_data_rate
self.velocity_publisher.publish(velocity_message)

flag_message = Bool()
flag_message.data = self.steering_data_rate_flag
self.flag_publisher.publish(flag_message)

if __name__ == '__main__':
try:
rospy.init_node("steering_data_rate", anonymous=False)
steering_data_rate_check = SteeringAngleRateChecker()
rospy.spin()
except rospy.ROSInterruptException:
pass
Loading
Loading