Error : Failed to start subscriber for topic name /pose and message type std_msgs/Int32.【MATLAB Unity communication】

8 views (last 30 days)
I’m trying to do Unity MATLAB connection by using ROS.
I was able to communicate well with the PoseMsg structure, but not with others.
*******************************************************
I got an error when I run this script at MATLAB.
poseSub = rossubscriber('pose', 'DataFormat', 'struct')
Error message is below
Warning: Error occurred while shutting down the ROS subscriber.
Caused by:
Subscriber 2039 already stopped.
> In ros/Subscriber/delete (line 361)
In ros.Subscriber (line 216)
In rossubscriber (line 103)
Warning: Error occurred while removing the ROS subscriber.
Caused by:
Subscriber still active: 2039
> In ros/Subscriber/delete (line 368)
In ros.Subscriber (line 216)
In rossubscriber (line 103)
Failed to start subscriber for topic name /pose and message type std_msgs/Int32.
On the other hand, Unity C# script is below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Robotics.ROSTCPConnector;
using RosMessageTypes.Geometry;
using RosMessageTypes.Std;
using System;
public class RosPublisher : MonoBehaviour
{
ROSConnection ros;
public string topicName = "pose";
public GameObject obj;
public float publishMessagePeriod = 0.5f;
private float timeElapsed;
// Start is called before the first frame update
void Start()
{
ros = ROSConnection.GetOrCreateInstance();
ros.RegisterPublisher<Int32Msg>(topicName);
}
// Update is called once per frame
private void Update()
{
timeElapsed += Time.deltaTime;
if (timeElapsed > publishMessagePeriod)
{
Int32Msg pose = new Int32Msg(100);
// Finally send the message to server_endpoint.py running in ROS
ros.Publish(topicName, pose);
timeElapsed = 0;
}
}
}
  2 Comments
Hari Krishna Kakarla
Hari Krishna Kakarla on 6 Nov 2023
Hi MAKOTO,
Thanks for reaching out to us. I see that you are publishing a message of type std_msgs/Int32Msg but you are using topic name as /pose which is little confusing.
What I suspect is, you might be using the same topic for geometry_msgs/PoseMsg as well and the publiser of it is already running? May be that's why it is working for you for the PoseMsg and not for the others.
I am just assuming this by looking at your C# script. Your logic looks correct but topic name and object name is confusing. Please give some other topic name for this msg type Int32Msg and change the object name in the C# script as well. That should solve the problem.
If you are still getting the same error, please give me some more information, i.e. please share the C# scripts of your PoseMsg and Int32Msg and let me know what are all the things you are executing in Unity.
Thanks
Hari

Sign in to comment.

Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!