Skip to content
Snippets Groups Projects
Commit d97ab23f authored by Marko Guberina's avatar Marko Guberina
Browse files

subsription works

parent eaa9f854
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import message_specs_pb2 ...@@ -5,6 +5,7 @@ import message_specs_pb2
import time import time
from agents_test.msg import Command from agents_test.msg import Command
import rospy import rospy
from functools import partial
...@@ -18,8 +19,8 @@ def getArgs(): ...@@ -18,8 +19,8 @@ def getArgs():
return args return args
def callback(c): def callback(comm_socket, c):
print("received callback") #print("received callback")
position = [c.goal.position.x, c.goal.position.y, c.goal.position.z] position = [c.goal.position.x, c.goal.position.y, c.goal.position.z]
orientation = [c.goal.orientation.w, c.goal.orientation.x, c.goal.orientation.y, c.goal.orientation.z] orientation = [c.goal.orientation.w, c.goal.orientation.x, c.goal.orientation.y, c.goal.orientation.z]
position_vel = [c.goal_dot.position.x, c.goal_dot.position.y, c.goal_dot.position.z] position_vel = [c.goal_dot.position.x, c.goal_dot.position.y, c.goal_dot.position.z]
...@@ -28,7 +29,7 @@ def callback(c): ...@@ -28,7 +29,7 @@ def callback(c):
pb2_msg.position.extend(position) pb2_msg.position.extend(position)
pb2_msg.rotation.extend(orientation) pb2_msg.rotation.extend(orientation)
pb2_msg.velocity.extend(position_vel + orientation_vel) pb2_msg.velocity.extend(position_vel + orientation_vel)
print(pb2_msg) #print(pb2_msg)
msg_length = pb2_msg.ByteSize() msg_length = pb2_msg.ByteSize()
msg_serialized = pb2_msg.SerializeToString() msg_serialized = pb2_msg.SerializeToString()
msg = _VarintBytes(msg_length) + msg_serialized msg = _VarintBytes(msg_length) + msg_serialized
...@@ -49,7 +50,8 @@ if __name__ == "__main__": ...@@ -49,7 +50,8 @@ if __name__ == "__main__":
print("NETWORKING_SERVER: accepted a client", comm_addr) print("NETWORKING_SERVER: accepted a client", comm_addr)
# ros subscriber # ros subscriber
rospy.Subscriber("/robot_command", Command, callback) callback_part = partial(callback, comm_socket)
rospy.Subscriber("/robot_command", Command, callback_part)
rospy.spin() rospy.spin()
comm_socket.close() comm_socket.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment