How to make use of data from rostopic in robot
Hello Everyone
I will make this question as clear as possible I have a py program in my PC which gives me coordinates x and y as goalx ang goaly which i am sending to my robot using roslibpy - host and port of the robot.
I can successfully get the data printed in a topic $rostopic echo /chatter as
data "686.75456, 426.85168"
------
data "685.78564, 424.54165"
------
data "684.43565, 422.24769"
I have a small py script in my robot which gets IMU data as well Ideally i want to use the data available in the /chatter to my code in the robot
This is my code is my PC publishing data to the topic /chatter with host 10.0.0.1 the robot
import time
import roslibpy
import localisation.shedrobot_localisation as loc
client = roslibpy.Ros(host='10.0.0.1', port=9090)
client.run()
talker = roslibpy.Topic(client, '/chatter', 'std_msgs/float32')
while client.is_connected:
loc.tracking_robot()
goal = str(loc.output)[1:-1] # loc.output comes from another program which provides me the x and y coordinate
goalx = str(loc.output[0])[0:-1]
goaly = str(loc.output[1])[0:-1]
talker.publish(roslibpy.Message({'data': goal })) # prints both x and y side by side
# talker.publish(roslibpy.Message({'data': goalx})) #prints x coordinate
# talker.publish(roslibpy.Message({'data': goaly})) # prints y coordinate
print('Sending message to ROBOT from PC...')
print('x : ',loc.output[0])
print('y : ',loc.output[1])
print('ROBOT :',goal)
time.sleep(0.1)
talker.unadvertise()
client.terminate()
How do i call the goalx and goaly in my py script in my robot, I understand i need to do something like this first?
listener = roslibpy.Topic(client, '/chatter', 'std_msgs/String')
Please let me know Thanks in advance.