From: Adam R. <ra...@au...> - 2005-08-26 17:29:46
|
I'm trying to communicate a robot's position and sonar range values using MComProxy. Since the message data must be a character string, I need to convert the robot's position and sonar ranges (double variables) to character strings. I have seen the <playermcomtypes.h> file and saw that MCOM_MSG_POSITION uses a structure that defines {x,y,theta} as int32_t and uint16_t variables. However, I'm still not sure how to get a double variable into this data type. Any help is greatly appreciated. Thanks, adam |
From: Brian G. <br...@ge...> - 2005-08-31 17:29:52
|
On Aug 26, 2005, at 10:29 AM, Adam Ray wrote: > I'm trying to communicate a robot's position and sonar range values > using MComProxy. Since the message data must be a character string, I > need to convert the robot's position and sonar ranges (double > variables) > to character strings. I have seen the <playermcomtypes.h> file and > saw > that MCOM_MSG_POSITION uses a structure that defines {x,y,theta} as > int32_t and uint16_t variables. However, I'm still not sure how to > get > a double variable into this data type. Any help is greatly > appreciated. I'm not familiar with that use of mcom, but if what you want to do is convert a double to an int, you need to pick a precision, multiply by the appropriate scale factor, then round off and cast to an int. For example, to convert a double in meters to an int in millimeters: double foo_m; int32_t foo_mm; foo_mm = (int32_t)rint(foo_m * 1e3); brian. -- Brian Gerkey br...@ge... http://gerkey.org |