-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot_point_publisher.py
30 lines (30 loc) · 1.27 KB
/
robot_point_publisher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
#Initialization of libraries
import rospy
#importing Point type msg from the package
from geometry_msgs.msg import Point
#function definition to publish current point coordinates
def robot_point_pub(user_coords):
#creating a topic 'robot/point' for publishing current point axis
pub = rospy.Publisher("robot/point", Point, queue_size =10)
print ("Publishing")
rate = rospy.Rate(1)
#until system is in running state
while not rospy.is_shutdown():
#publihsing three dimensional coordinates of the current robot point
pub.publish(Point(x=user_coords[0], y=user_coords[1], z=user_coords[2]))
rate.sleep()
#main function of the script
if __name__ =="__main__":
try:
#initializing publisher node
rospy.init_node("robot_point_pub_node")
user_x = input("What is your current x-coordinate?: ")
user_y = input("What is your current y-coordinate?: ")
user_z = input("What is your current z-coordinate?: ")
#concatinating three coordinates into an array
user_coords = [float(user_x), float(user_y), float(user_z)]
robot_point_pub(user_coords)
#if any error/exception occurs during program running
except rospy.ROSInterruptException:
print("Exception Occured")