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.
And these are my scripts implementing the service:
public class MapUnityService : MonoBehaviour
{
private ROSConnection _rosConn;
void Start()
{
_rosConn = ROSConnection.GetOrCreateInstance();
_rosConn.ImplementService<LoadMapRequest, LoadMapResponse>("/map_server/load_map", GetLoadMap);
}
private LoadMapResponse GetLoadMap(LoadMapRequest request)
{
LoadMapResponse loadMapResponse = new LoadMapResponse();
return loadMapResponse;
}
}
public class MapServiceCall : MonoBehaviour
{
private ROSConnection _rosConn;
private HeightMap _heightMap;
private string _path;
private void Start()
{
_rosConn = ROSConnection.GetOrCreateInstance();
_rosConn.RegisterRosService<LoadMapRequest, LoadMapResponse>("/map_server/load_map");
_heightMap = FindObjectOfType<HeightMap>();
_path = "/mnt/" + Application.dataPath + "/Saved_Runtime_Data/height_map.yaml";
_path = _path.Replace("C:", "c");
//_path = "//wsl$/Ubuntu-20.04/home/nitsan/raya2_ws/src/simulator_navigation2";
MiniMapTexture.mapUpdated += SendMessage;
WriteToFile();
}
private void SendMessage()
{
//Called when the map jpg updates.
LoadMapRequest loadMapRequest = new LoadMapRequest();
loadMapRequest.map_url = _path;
_rosConn.SendServiceMessage<LoadMapResponse>("/map_server/load_map", loadMapRequest, Callback);
}
private void Callback(LoadMapResponse response)
{
}
private void WriteToFile()
{
//StreamWriter writer = new StreamWriter(_path);
StreamWriter writer = new StreamWriter(Application.dataPath + "/Saved_Runtime_Data/height_map.yaml");
string imagePath = _path.Replace("yaml", "jpg");
writer.WriteLine(string.Format("image: {0}", imagePath));
writer.WriteLine(string.Format("resolution: {0}", _heightMap.resolution));
writer.WriteLine(string.Format("origin: [{0}, {1}, 0.0]", _heightMap.mapOrigin.x, _heightMap.mapOrigin.z));
//writer.WriteLine(string.Format("origin: [0.0, 0.0, 0.0]"));
writer.WriteLine("occupied_thresh: 0.65");
writer.WriteLine("free_thresh: 0.65");
writer.WriteLine("negate: 0");
writer.Close();
}
private void OnDisable()
{
MiniMapTexture.mapUpdated -= SendMessage;
}
}
Any help will be very appreciated!