Hi, has anyone created a custom ros action graph in Isaac Sim (ROS2) , I was following the tutorial for custom python action graph, but am stuck . If anyone has implemented the same can you please share a snippet for a ros2 subscription?
Below is my attached code .
import numpy
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import PoseStamped, Twist
# from omni.isaac.core_nodes import BaseWriterNode,
# global called
called = False
print(called)
class OgnRos2AMCL(Node):
"""
This node will subscribe to amcl_pose (ros2-node)
"""
#
def __init__(self):
super().__init__('amcl_subscriber_node')
self.called = False
def intialize_once(self):
if not self.called:
print('Initializing')
rclpy.init()
self.called = True
# called = True
# @staticmethod
def compute(self, db) -> bool:
"""Compute the outputs from the current input"""
global called
try:
# if not called:
# print("Initialized called",called)
# called = True
# print("Initialized called",called)
# rclpy.init()
# With the compute in a try block you can fail the compute by raising an exception
self.intialize_once()
topicName = db.inputs.topicName
print("Topic Name - ",topicName)
def callback(msg):
print(msg)
node = rclpy.create_node('amcl_subscriber')
# rclpy.spin(node)
sub = node.create_subscription(Twist, topicName,callback,10 )
print(sub)
rclpy.spin(node)
pass
except Exception as error:
db.log_error(error)
return False
# Even if inputs were edge cases like empty arrays, correct outputs mean success
return True
The problem is whenver I play and have this node in Isaac sim it gives an error saying
1, Cannot create a node (rclpy.init() must be called once)
2. Or rclypy.init() must be initialized only once
The error depends were I initialize the init() function. The latter error comes when I initialize the init() funtion in the compute() method.
The inputs for the node is - exec_in(type - execution), and topicName(type - string)
Outputs - orientation(quatd) and position(vectord)
The node is not been created and itis not able to subscribe
Can anyone please help me with what am I doing wrong