Society of Robots - Robot Forum
Software => Software => Topic started by: Hasan999 on February 01, 2010, 01:13:06 PM
-
Using Webbot Library, on Axon 1.... programming for sensor (Sharp GP2D12) not working...
#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)
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...
-
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);
-
Using Webbot Library, on Axon 1.... programming for sensor (Sharp GP2D12) not working...
#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)
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.
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.
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.
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.
-
Working WebbotLib Sharp IR code can be found in the Axon II example programs. 8)