Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Problems with MessageDeserializer when implementing service

Discussion in 'Robotics' started by Nitsan448, Feb 6, 2022.

  1. Nitsan448

    Nitsan448

    Joined:
    Aug 22, 2019
    Posts:
    14
    Hello, I am implementing a LoadMap service, And I am getting bugs in the Read method of MessageDeserializer when trying to send the service message.
    I have attached screenshots of the errors and where they happen in the code. They only happen once in a while. Screenshot 2022-02-06 122959.png Screenshot 2022-02-06 173658.png Screenshot 2022-02-06 174000.png


    And these are my scripts implementing the service:

    Code (CSharp):
    1. public class MapUnityService : MonoBehaviour
    2. {
    3.     private ROSConnection _rosConn;
    4.  
    5.     void Start()
    6.     {
    7.         _rosConn = ROSConnection.GetOrCreateInstance();
    8.         _rosConn.ImplementService<LoadMapRequest, LoadMapResponse>("/map_server/load_map", GetLoadMap);
    9.     }
    10.  
    11.     private LoadMapResponse GetLoadMap(LoadMapRequest request)
    12.     {
    13.         LoadMapResponse loadMapResponse = new LoadMapResponse();
    14.  
    15.         return loadMapResponse;
    16.     }
    17. }
    Code (CSharp):
    1. public class MapServiceCall : MonoBehaviour
    2. {
    3.     private ROSConnection _rosConn;
    4.     private HeightMap _heightMap;
    5.     private string _path;
    6.  
    7.     private void Start()
    8.     {
    9.         _rosConn = ROSConnection.GetOrCreateInstance();
    10.         _rosConn.RegisterRosService<LoadMapRequest, LoadMapResponse>("/map_server/load_map");
    11.         _heightMap = FindObjectOfType<HeightMap>();
    12.         _path = "/mnt/" + Application.dataPath + "/Saved_Runtime_Data/height_map.yaml";
    13.         _path = _path.Replace("C:", "c");
    14.         //_path = "//wsl$/Ubuntu-20.04/home/nitsan/raya2_ws/src/simulator_navigation2";
    15.         MiniMapTexture.mapUpdated += SendMessage;
    16.         WriteToFile();
    17.     }
    18.  
    19.     private void SendMessage()
    20.     {
    21.         //Called when the map jpg updates.
    22.  
    23.         LoadMapRequest loadMapRequest = new LoadMapRequest();
    24.         loadMapRequest.map_url = _path;
    25.         _rosConn.SendServiceMessage<LoadMapResponse>("/map_server/load_map", loadMapRequest, Callback);
    26.     }
    27.  
    28.     private void Callback(LoadMapResponse response)
    29.     {
    30.     }
    31.  
    32.     private void WriteToFile()
    33.     {
    34.         //StreamWriter writer = new StreamWriter(_path);
    35.         StreamWriter writer = new StreamWriter(Application.dataPath + "/Saved_Runtime_Data/height_map.yaml");
    36.  
    37.         string imagePath = _path.Replace("yaml", "jpg");
    38.         writer.WriteLine(string.Format("image: {0}", imagePath));
    39.         writer.WriteLine(string.Format("resolution: {0}", _heightMap.resolution));
    40.         writer.WriteLine(string.Format("origin: [{0}, {1}, 0.0]", _heightMap.mapOrigin.x, _heightMap.mapOrigin.z));
    41.         //writer.WriteLine(string.Format("origin: [0.0, 0.0, 0.0]"));
    42.         writer.WriteLine("occupied_thresh: 0.65");
    43.         writer.WriteLine("free_thresh: 0.65");
    44.         writer.WriteLine("negate: 0");
    45.         writer.Close();
    46.     }
    47.  
    48.     private void OnDisable()
    49.     {
    50.         MiniMapTexture.mapUpdated -= SendMessage;
    51.     }
    52. }
    Any help will be very appreciated!
     
  2. LaurieUnity

    LaurieUnity

    Unity Technologies

    Joined:
    Oct 23, 2020
    Posts:
    77
    Have you tried this with the new release version 0.7.0? There was a bug in ROS2 serialization when dealing with zero length arrays, not sure if this is the same issue or not.
     
    Nitsan448 likes this.
  3. Nitsan448

    Nitsan448

    Joined:
    Aug 22, 2019
    Posts:
    14
    I just updated and it seems to work now, thank you!