Society of Robots - Robot Forum

Software => Software => Topic started by: Ryltar on April 03, 2011, 08:06:14 PM

Title: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 03, 2011, 08:06:14 PM
Hello,

I am having a problem with my Sharp GP2D12. I have it connected to my Axon and I'm using webbotlib with it. I built the base of the program using Project Designer and webbotlib 2.02. The problem is that my sensor is outputting the same value no matter what the range is.

I'm using the following code in my main loop. I'm working on a app for working with the robot so I removed all the locomotion code while I get the basics sensor readings set up.

Code: [Select]
// This is the main loop
TICK_COUNT appControl( LOOP_COUNT loopCount, TICK_COUNT loopStart ) {

// -------- Start Sparkfun Razor-------
// Read the Sparkfun Razor and store results
imuRead( razor_imu );
/*
razor_imu.imu.x_axis_degrees_per_second
razor_imu.imu.y_axis_degrees_per_second
razor_imu.imu.z_axis_degrees_per_second
razor_imu.imu.x_axis_mG
razor_imu.imu.y_axis_mG
razor_imu.imu.z_axis_mG
razor_imu.imu.bearingDegrees
razor_imu.imu.pitchDegrees
razor_imu.imu.rollDegrees
*/
// -------- End Sparkfun Razor-------

// -------- Start Sharp GP2-------
// Read the Sharp GP2 and store the result in top.distance.cm
distanceRead( top );
// -------- End Sharp GP2-------

// -------- Start Maxbotix EZ1 sonar-------
// Read the Maxbotix EZ1 sonar and store the result in sonar.distance.cm
distanceRead( sonar );
// -------- End   Maxbotix EZ1 sonar-------

// -------- Start GPS NMEA-------
// Process incoming messages
gpsNMEAprocess( &gps_main );
// -------- End GPS NMEA-------

/** Output every second **/
if( clockHasElapsed( lastOutputTime, outputWaitPeriod ) ) {

USE_BLUETOOTH();

// JSON Formatted Output, semicolon signifies end of line
if( gps_main.info.valid ) {

rprintf( "{'imu': {'gyro': {'x': %d,'y': %d,'z': %d},'accel': {'x': %d,'y': %d,'z': %d},'yaw': %d,'pitch': %d,'roll': %d},'sharp': %u,'sonar': %d,'gps': {'satellites': %d,'longitude': %d,'latitude': %d,'altitude': %d,'speed': %d,'time': %d}};",
razor_imu.imu.x_axis_degrees_per_second,
razor_imu.imu.y_axis_degrees_per_second,
razor_imu.imu.z_axis_degrees_per_second,
razor_imu.imu.x_axis_mG,
razor_imu.imu.y_axis_mG,
razor_imu.imu.z_axis_mG,
razor_imu.imu.bearingDegrees,
razor_imu.imu.pitchDegrees,
razor_imu.imu.rollDegrees,

top.distance.cm,

sonar.distance.cm,

gps_main.info.numSatellites,
( gps_main.info.longitude * 180 / M_PI * 1000 ),
( gps_main.info.latitude * 180 / M_PI * 1000 ),
( gps_main.info.altitude * 1000 ),
( gps_main.info.speed * 1000 ),
( gps_main.info.fixTime * 1000 )
);
} else {

rprintf( "{'imu': {'gyro': {'x': %d,'y': %d,'z': %d},'accel': {'x': %d,'y': %d,'z': %d},'yaw': %d,'pitch': %d,'roll': %d},'sharp': %u,'sonar': %d,'gps': {}};",
razor_imu.imu.x_axis_degrees_per_second,
razor_imu.imu.y_axis_degrees_per_second,
razor_imu.imu.z_axis_degrees_per_second,
razor_imu.imu.x_axis_mG,
razor_imu.imu.y_axis_mG,
razor_imu.imu.z_axis_mG,
razor_imu.imu.bearingDegrees,
razor_imu.imu.pitchDegrees,
razor_imu.imu.rollDegrees,

top.distance.cm,

sonar.distance.cm
);
}

// Update last output time
lastOutputTime = clockGetus();
}

return 20;//us delay

When I watch the sensor values, I only see the sharp being listed as '65535 '. If I use %d instead of %u, then I see -1.

I know the rail is fine, I have a sonar sensor on it that is working fine. I believe the Sharp should be working fine as well, I have gotten proper data from it in the past. Additionally, I tried another sharp ir sensor in its place and the reported values were the same. According to the webbotlib documentation and the example.txt file that is generated by the project designer, I am using the variables correctly.

Any suggestions to get it running?
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: waltr on April 03, 2011, 08:21:23 PM
Did you measure the voltage in to the Sharp and measure the output voltage at the Sharp and at the Axon's ADC input pin?
It could be just a bad connection.
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Webbot on April 03, 2011, 08:53:02 PM
Have you tried dumping the sharp sensor on its own:
distanceDump(top) ;

If that works on its own, then it may be there is some nested issue in your large rprintf where format strings dont match the data types.
If not then let me know!
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 03, 2011, 09:41:30 PM
I haven't measured the voltage on the Sharp. I was planning to take it to lab tomorrow and test it. Sadly, I do not even have a decent multimeter to test equipment anymore.

Using the distanceDump( top ); results in 65535 being outputted.
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Admin on April 04, 2011, 06:45:43 AM
Do this alone outside of that long rprintf:
rprintf("%d",top.distance.cm);
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 04, 2011, 07:05:09 AM
Adding distanceDump( top ); rprintf("%d",top.distance.cm); and rprintf("%u",top.distance.cm);, each cycle now outputs:

Code: [Select]
(65535 cm)
-1
65535
{'imu': {'gyro': {'x': -1,'y': 0,'z': 0},'accel': {'x': 62,'y': -3,'z': 1009},'yaw': 198,'pitch': 20,'roll': 353},'sharp': 65535,'sonar': 108,'gps': {}};

I also did a test with out the sonar, but that didn't change the output of the ir sensor. Removing the large rprintf results in the same values for the ir sensor.
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Webbot on April 04, 2011, 09:00:22 AM
Ooops, found a silly bug introduced into the V2 code stream for the Sharp IR devices. Missed out one character !

I changed the Sharp stuff so that it didn't bring in the whole floating point math library and just used integer maths instead.

PM me your e-mail address and I'll send you a new ATMega640.a compiled library

Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 04, 2011, 10:06:19 AM
Will do, thanks!
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 04, 2011, 02:35:57 PM
The new compiled library is working sporadically. Perhaps 10-15% are the correct range. The rest are wildly off, somewhere in the tens of thousands or reading 65535.
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Webbot on April 04, 2011, 02:52:03 PM
Ok, so I need to take a closer look, which will take a little while to get everything set up, debug ,test etc.

By the way: The 65535 value means that the reading is beyond the range of the IR sensor so effectively means 'nothing in sight'

Will get back
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 04, 2011, 03:08:24 PM
Okay, sorry for the trouble on finding an annoying bug.

I'll switch to 1.3 for the time being, I don't really need 2.x functions yet.
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Webbot on April 04, 2011, 04:53:58 PM
No worries - just sent you another 2.x version. Works for me.
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Ryltar on April 04, 2011, 05:00:29 PM
That one did it. IR is working great again. Thanks :)
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Admin on April 08, 2011, 08:36:14 PM
I've noticed a problem with v2 that I never saw in v1.3, which may or may not be related to this. My I2C sensor, which returns floats, on occasion gives me crazy values.

Did this in any way involve the float library, or the rprintf library, or how pressure/temperature variable types could get returned?
Title: Re: WebbotLib / Axon / Sharp GP2D12
Post by: Webbot on April 09, 2011, 08:06:12 AM
No - it was a fix to some code that is only ever used by the Sharp GP2 devices

Edit: Fix released in version 2.03