Author Topic: webbotlib distance conversion  (Read 684 times)

0 Members and 1 Guest are viewing this topic.

Offline michaelghayesTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
webbotlib distance conversion
« 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
« Last Edit: January 24, 2010, 03:24:51 PM by michaelghayes »

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: webbotlib distance conversion
« Reply #1 on: January 24, 2010, 04:26:09 PM »
DISTANCE_TYPE is a define, which the pre-processor changes to a unsinged integer (short).

Code: [Select]
sensors\distance\_distance_common.h(25): #define DISTANCE_TYPE uint16_t
you can use it as an integer for computations.

The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: webbotlib distance conversion
« Reply #2 on: January 24, 2010, 10:09:42 PM »
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.

 


Get Your Ad Here