Author Topic: A small problem... (WebbotLib / Axon / Sharp_Distance_Sensor )  (Read 975 times)

0 Members and 1 Guest are viewing this topic.

Offline Hasan999Topic starter

  • Full Member
  • ***
  • Posts: 75
  • Helpful? 1
A small problem... (WebbotLib / Axon / Sharp_Distance_Sensor )
« on: February 01, 2010, 01:13:06 PM »
Using Webbot Library, on Axon 1.... programming for sensor (Sharp GP2D12) not working...

Code: [Select]
#include "sys/axon.h"
#include "uart.h"
#include "rprintf.h"
#include "servos.h"
#include "a2d.h"
#include "Sensors/Distance/Sharp/GP2D12.h"

Sharp_GP2D12 sensor = MAKE_Sharp_GP2D12(8);

//

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

distanceInit(sensor);
distanceRead(sensor);

rprintf("%d \r\n",sensor);

return 0;
}

as output, i get "1216" repeatedly, regardless of the sensing distance. (same with %u instead of %d)

If I use the same rprintf with sensor.distance.cm then it repeatedly displays "0" !

I tried different things, couldn't figure out the problem...

It works fine with the old library, when I use (once sensor.c is included)

Code: [Select]
int range = sharp_IR_interpret_GP2D12(a2dConvert8bit(8));
rprintf("%d \r\n",range);

it displays the range in cm directly !...

Need help making it work in WebbotLib...

Thanks...
« Last Edit: February 02, 2010, 09:19:52 AM by Hasan999 »

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: A small problem... (WebbotLib / Axon / Sharp_Distance_Sensor )
« Reply #1 on: February 01, 2010, 04:39:46 PM »
Hi looking at the document, it looks like you are supposed to use:
    sensor.distance.cm

i.e. have you tried:
rprintf("%d \r\n",sensor.distance.cm);





Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,136
  • Helpful? 109
Re: A small problem... (WebbotLib / Axon / Sharp_Distance_Sensor )
« Reply #2 on: February 01, 2010, 07:59:45 PM »
Using Webbot Library, on Axon 1.... programming for sensor (Sharp GP2D12) not working...

Code: [Select]
#include "sys/axon.h"
#include "uart.h"
#include "rprintf.h"
#include "servos.h"
#include "a2d.h"
#include "Sensors/Distance/Sharp/GP2D12.h"

Sharp_GP2D12 sensor = MAKE_Sharp_GP2D12(8);

//

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

distanceInit(sensor);
distanceRead(sensor);

rprintf("%d \r\n",sensor);

return 0;
}

as output, i get "1216" repeatedly, regardless of the sensing distance. (same with %u instead of %d)

If I use the same rprintf with sensor.distance.cm then it repeatedly displays "0" !

I tried different things, couldn't figure out the problem...

It works fine with the old library, when I use (once sensor.c is included)

Code: [Select]
int range = sharp_IR_interpret_GP2D12(a2dConvert8bit(8));
rprintf("%d \r\n",range);

it displays the range in cm directly !...

Need help making it work in WebbotLib...

Thanks...

Lots of mistakes in your code:

1.
Code: [Select]
Sharp_GP2D12 sensor = MAKE_Sharp_GP2D12(8);
I would have thought would give you a compilation warning. The parameter to the make command is an IO pin such as F0. A value of 8 is nonsense - read a2d.h in the manual. This MAKE error means that the device will never respond properly. And thats why you've always gotten a '0' when you are using rprintf with the correct parameters.

2.
Code: [Select]
distanceInit(sensor);
This is fine except that you are initialising the sensor every time around your main loop!! It should really be in appInitHardware instead so that it is called once at startup.

3.
Code: [Select]
rprintf("%d \r\n",sensor);

This will print the low byte of the memory address of your sensor. It will always be the same value  - and not what you want! See reply from KurtEck for correct answer (although you should use %u as the distance can never be -ve) or use the distanceDump macro.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: A small problem... (WebbotLib / Axon / Sharp_Distance_Sensor )
« Reply #3 on: February 02, 2010, 06:47:29 AM »
Working WebbotLib Sharp IR code can be found in the Axon II example programs. 8)

 


Get Your Ad Here