I am trying to simulate a double Ackermann mobile robot using IsaacSim 2023.1.1. And, I am constrained to se Ubuntu 20, ROS 1.
I wrote my own ROS msg package, compiled successfully.
Now the things left are write a ROS 1 Subscribe DoubleAckermann and a DoubleAckermann Drive node.
Bellow is the code of the Subcriber Node.
"""
This is the implementation of the OGN node defined in ROS1SubscribeDAckermaanDrive.ogn
"""
import sys
sys.path.append('{PATH_TO_WS}/noetic_ws/devel/lib/python3/dist-packages/d_ackermann_msgs/msg')
sys.path.append('{PATH_TO_WS}/noetic_ws/devel/lib/python3/dist-packages')
# Array or tuple values are accessed as numpy arrays so you probably need this import
import numpy as np
import omni
import rospy
import rosgraph
from omni.wheeled_robots.d_ackermann_steering.ogn.ROS1SubscribeDAckermaanDriveDatabase import ROS1SubscribeDAckermaanDriveDatabase
# from _DAckermannDrive import DAckermannDrive
from d_ackermann_msgs.msg import DAckermannDrive
from omni.isaac.core_nodes import BaseResetNode
import omni.graph.core as og
from omni.isaac.core import World
class ROS1SubscribeDAckermaanDriveInternalState(BaseResetNode):
def __init__(self, initialize=False):
print("call init")
self.initialized = False
self.subscription = None
self.front_steering_angle = None
self.rear_steering_angle = None
self.front_wheels_acceleration = None
self.rear_wheels_acceleration = None
self._timeline = None
super().__init__(initialize=initialize)
def listener_callback(self, msg):
self.front_steering_angle = msg.front_steering_angle
self.rear_steering_angle = msg.rear_steering_angle
self.front_wheels_acceleration = msg.front_wheels_acceleration
self.rear_wheels_acceleration = msg.rear_wheels_acceleration
def initialize_node(self):
try:
if not rospy.core.is_initialized():
try:
rosgraph.Master("/rostopic").getPid()
except:
print("No ROS master")
return False
rospy.init_node("DAK", anonymous=True, disable_signals=False, log_level=rospy.ERROR)
self.initialized = True
print("Node initialized successfully.")
except rospy.ROSException as e:
rospy.logerr("Node initialization failed: %s", e)
def create_subscriber(self):
if self.subscription is None:
print("call create subscriber")
self.subscription = rospy.Subscriber(
"/d_ackermann_cmd",
DAckermannDrive,
# self.listener_callback,
queue_size=10
)
print("Subscriber created successfully.")
def custom_reset(self):
if self.subscription:
self.subscription.unregister()
self.subscription = None
print("Subscriber unregistered successfully.")
self.front_steering_angle = None
self.rear_steering_angle = None
self.front_wheels_acceleration = None
self.rear_wheels_acceleration = None
self.initialized = False
rospy.signal_shutdown('Node is shutting down.')
print("Node shutdown initiated.")
class ROS1SubscribeDAckermaanDrive:
"""
ROS1 Subscribe Double Ackermann Drive
"""
@staticmethod
def internal_state():
return ROS1SubscribeDAckermaanDriveInternalState()
@staticmethod
def compute(db) -> bool:
"""Compute the outputs from the current input"""
state = db.internal_state
try:
if not state.initialized:
print("Initializing node")
state.initialize_node()
state.create_subscriber()
rospy.sleep(0.01)
if state.front_steering_angle is not None:
db.outputs.front_steering_angle = state.front_steering_angle
if state.rear_steering_angle is not None:
db.outputs.rear_steering_angle = state.rear_steering_angle
if state.front_wheels_acceleration is not None:
db.outputs.front_wheels_acceleration = state.front_wheels_acceleration
if state.rear_wheels_acceleration is not None:
db.outputs.rear_wheels_acceleration = state.rear_wheels_acceleration
except Exception as error:
db.log_error(str(error))
return False
return True
When I finish connecting the nodes and run the simulation, rostopic info /rosout return as follow. So roscore cannot detect my subscriber node.
$ rostopic info /rosout
Type: rosgraph_msgs/Log
Publishers: None
Subscribers:
/rosout (http://:46227$USER/)
This is my Action Graph