Exercise 3.12 - Getting error when comparing service message response with a float

Hi all,

I created a custom service message (MyCustomServiceMessage.srv) defining the answer as a float32. After disperse particles and move robot, I request the particles covariance, that is a correct value. But when I try to check if covariance is less than threshold defined(0.65) I get this error: “while(covariance > 0.65): TypeError: ‘>’ not supported between instances of ‘MyCustomServiceMessageResponse’ and ‘float’”. To avoid this error I converted the service response (“message: 0.37408336997032166”) to string, take only the positions of this string that contain numbers and then convert it again to float so I can compare it. I think this is not very elegant way to do it and I want to know if there is more direct way?

Thanks in advance.

you should accesto to the property of the response, not the object of the response. MyCustomServiceMessageResponse.answer

1 Like

I realized that I did not generate the message correctly. By the way, I saw that creating a subscriber instead of a service it is not necessary to create a custom message and this solved the problem. Thanks for the quick reply!