Commit f7c311ad authored by levi's avatar levi
Browse files

Merge branch 'master' of gitlab.au.dk:desktop_robotti/drobotti-processing-and-control

parents a07b2299 1184f12f
......@@ -100,14 +100,14 @@ class RabbitMQPublisher(Node):
message["time"] = timestamp
message_json = json.dumps(message)
print(f"sending message {message}")
self.get_logger().info(f"sending message {message}")
self.publish_to_rmq(message_json)
else:
for fname, fvalue in values_to_forward.items():
message = {"time": timestamp, fname: fvalue}
message_json = json.dumps(message)
print(f"sending message {message}")
self.get_logger().info(f"sending message {message}")
self.publish_to_rmq(message_json)
def publish_to_rmq(self, msg):
......@@ -116,7 +116,7 @@ class RabbitMQPublisher(Node):
)
def init_rabbitmq(self):
print("Initializing Connection")
self.get_logger().info("Initializing Connection")
for i in range(5):
try:
self.rmq_connection = pika.BlockingConnection(
......@@ -125,12 +125,12 @@ class RabbitMQPublisher(Node):
self.rmq_channel = self.rmq_connection.channel()
print("Declaring exchange")
self.get_logger().info("Declaring exchange")
self.rmq_channel.exchange_declare(
exchange="fmi_digital_twin", exchange_type="direct"
)
print("Creating queue")
self.get_logger().info("Creating queue")
result = self.rmq_channel.queue_declare(queue="", exclusive=True)
queue_name = result.method.queue
......@@ -145,15 +145,15 @@ class RabbitMQPublisher(Node):
except Exception as err:
if i == 0:
print("RabbitMQ Initialization failed. Is rabbitmq running?")
print(err)
print(f"Retrying... (try {i+1} out of 5)")
self.get_logger().info("RabbitMQ Initialization failed. Is rabbitmq running?")
self.get_logger().info(err)
self.get_logger().info(f"Retrying... (try {i+1} out of 5)")
time.sleep(1)
else:
print("RabbitMQ Initialization Complete!")
self.get_logger().info("RabbitMQ Initialization Complete!")
break
else:
print("Exiting")
self.get_logger().info("Exiting")
exit()
......
......@@ -43,12 +43,12 @@ class RabbitMQSubscriber(Node):
def on_msg_received(self, channel, method, properties, body):
print("Received message from rmq:")
self.get_logger().info("Received message from rmq:")
rmq_msg_json = body.decode('UTF-8')
# msg_json = msg_json.replace(".","__")
rmq_msg_json = rmq_msg_json.replace('"{','{')
rmq_msg_json = rmq_msg_json.replace('}"','}')
print(rmq_msg_json)
self.get_logger().info(rmq_msg_json)
rmq_msg = json.loads(rmq_msg_json)
for topic_name, topic_config in self.forward_this.items():
......@@ -56,9 +56,9 @@ class RabbitMQSubscriber(Node):
field_list = topic_config["fields"]
if any(key.startswith(topic_name) for key in rmq_msg.keys()):
print(f"Message fits config for topic {topic_name}")
self.get_logger().info(f"Message fits config for topic {topic_name}")
print("Converting to ros-message...")
self.get_logger().info("Converting to ros-message...")
ros_msg = topic_msg_type()
for field_name in field_list:
field_key = f"{topic_name}.{field_name}"
......@@ -69,8 +69,8 @@ class RabbitMQSubscriber(Node):
field_value = rmq_msg[field_key]
setattr(ros_msg, field_name, field_value)
print(f"Publishing ros-message on topic /{topic_name}:")
print(ros_msg)
self.get_logger().info(f"Publishing ros-message on topic /{topic_name}:")
self.get_logger().info(str(ros_msg))
self.topic_publishers_[topic_name].publish(ros_msg)
......@@ -78,7 +78,7 @@ class RabbitMQSubscriber(Node):
# print(" [x] %r:%r consumed" % (method.routing_key, body))
def start_consumer(self):
print("Initializing Connection")
self.get_logger().info("Initializing Connection")
try:
self.rmq_connection = pika.BlockingConnection(
pika.ConnectionParameters(self.get_parameter('server_hostname').get_parameter_value().string_value)
......@@ -101,10 +101,10 @@ class RabbitMQSubscriber(Node):
auto_ack=True)
except Exception as err:
print("RabbitMQ Initialization failed. Is rabbitmq running?")
print(err)
self.get_logger().info("RabbitMQ Initialization failed. Is rabbitmq running?")
self.get_logger().info(err)
else:
print("RabbitMQ Initialization Complete!")
self.get_logger().info("RabbitMQ Initialization Complete!")
self.rmq_channel.start_consuming()
def init_rabbitmq(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment