Society of Robots - Robot Forum
Software => Software => Topic started by: michaelghayes on January 24, 2010, 03:14:50 PM
-
I am very new to programing and know very little c, but I am trying to use the webbotlib and I want to get an int value from my sharp IR sensor, instead the I only seem to be able to get a value of type DISTANCE_TYPE, is there a simple way to convert this to an int, or get an int value back from the sensor instead
right now I am using distanceRead(sensor); to get the value but this is the only method i could find in the webbotlib pdf
-
DISTANCE_TYPE is a define, which the pre-processor changes to a unsinged integer (short).
sensors\distance\_distance_common.h(25): #define DISTANCE_TYPE uint16_t
you can use it as an integer for computations.
-
I know it may seem odd, but type DISTANCE_TYPE is actually better than int. Type int just means its 8 bit, but type DISTANCE_TYPE is in centimeters (as far as the programmer should be concerned).
The advantage is that you don't need to be concerned with the returned file types of different sensors. For one sensor its not that big a deal, but when you have say five sensors, it could get confusing.
For example, lets say your robot has a sharp IR and a sonar, and you need to compare distances . . . well, they both will return a value in DISTANCE_TYPE, meaning the final result for both is in centimeters. You don't need to worry about unit conversions, or one sensor being 16 bit while the other is 8 bit, or what type to output with rprintf, etc.