Skip to content

Commit

Permalink
arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiger9406 committed Apr 9, 2024
1 parent 694bc93 commit f9eea8d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 44 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/SET2023.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 25 additions & 44 deletions DataHandling/LIDARDataPublisher.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
#Tiger Cao
#1/15/2024

import rospy

from sensor_msgs.msg import PointCloud, Point32

import math

def lidar_publisher():
#Initialize ROS node
rospy.init_node('lidar_publisher')


#create Publisher
lidar_pub=rospy.Publisher('/lidar_scan')

#define publishing rate
rate=rospy.Rate(10) #10 Hz


def main():
#main loop
while not rospy.is_shutdown():
while True:
#calls method to get data
lidar_data=get_parsed_lidar()

#instantiates point cloud message to publish later
lidar_msg=PointCloud()


#fill headers of point cloud message
lidar_msg.header.stamp=rospy.Time.now()
lidar_msg.header.frame_id="placeholder" #replace with SET Robot base link

#for points in lidar_data retrieved, convert to x y
for point in lidar_data:
x = point * math.cos(0) # replace 0 with angle given in parsed data
y = point * math.sin(0) # replace 0 with angle given in parsed data
z=0.0
#populate point cloud message with points
lidar_msg.points.append(Point32(x=x, y=y, z=z))

#pulish
lidar_pub.publish(lidar_msg)

#sleep to match publishing rate
rate.sleep()
output=process.stdout.readline().decode('utf-8').strip()
if output:
print("Received:", output)


# #fill headers of point cloud message
# lidar_msg.header.stamp=rospy.Time.now()
# lidar_msg.header.frame_id="placeholder" #replace with SET Robot base link
#
# #for points in lidar_data retrieved, convert to x y
# for point in lidar_data:
# x = point * math.cos(0) # replace 0 with angle given in parsed data
# y = point * math.sin(0) # replace 0 with angle given in parsed data
# z=0.0
# #populate point cloud message with points
# lidar_msg.points.append(Point32(x=x, y=y, z=z))
#
# #pulish
# lidar_pub.publish(lidar_msg)
#
# #sleep to match publishing rate
# rate.sleep()



Expand All @@ -54,8 +38,5 @@ def get_parsed_lidar():


if __name__ == '__main__':
try:
lidar_publisher()
except rospy.ROSInterruptException:
pass
main()

32 changes: 32 additions & 0 deletions DataHandling/arduino.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import serial
import math

# Configure the serial port. Change the port and baud rate as needed.
# 50 units is equal to 1 CM
ser = serial.Serial('/dev/cu.usbmodem101', 9600) # COM3 is an example, you need to specify your port

try:
distance = True
while True:
data = ser.readline().decode().strip()
if distance:
print("Distance:", data/50)
distance = not distance
else:
print("Strength:", data)
distance = not distance
except KeyboardInterrupt:
ser.close() # Close the serial port on Ctrl+C


def convert_xy(angle, distance):
angle_radians = math.radians(angle)

# Calculate the relative x and y coordinates
x = distance * math.cos(angle_radians)
y = distance * math.sin(angle_radians)

return x, y



0 comments on commit f9eea8d

Please sign in to comment.