View unanswered posts | View active topics It is currently Fri Sep 19, 2014 10:03 pm






Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Last minute problems with sonar 
Author Message
Rookie

Joined: Wed Feb 18, 2009 4:06 pm
Posts: 12
Post Last minute problems with sonar
Bother.

Our robot has a line follower algorithm (which uses 3 sensors connected through the Hitechnic prototype board). The light sensors work great.

The idea is that the robot follows the line until the sonar distance is below a threshold (ie. it's near the center).

The problem (captured with the datalogging function) is that the sensor often returns nonsense values (either low or high), which causes the robot to either overshoot or underrun.

We have tried various techniques to filter out bad values (which does not work). For example, we tried reading three values in a row and picking the center value. What we found is that once it is in this mode all the reads return the same incorrect value. A stand alone program which puts the sonar sensor values on the display works fine. We also tried a second sonar sensor.

I'm wondering if use of the hitechnic board driver is interferring with the sonar sensor reads? Or is the fact that all the motors are running somehow interrering?

We have no other sensors connected.

Thanks


Thu Feb 26, 2009 4:22 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Last minute problems with sonar
whose sonar sensor are you using?

As to motor interference, I've seen this myself before. Try routing wires away from motors. Worse case only take sonar readings while the motors are off. See if that improves things.

Try putting the robot on a cart or something (don't change height of sonar off ground very much) and push the robot around with the motors off. This might help you prove if its an "electrical" issue or a "physics" issue.

It could also be the sensor itself. Some brands of sonar are notoriously bad at false readings while moving. Also beware that some sonars have "deadzones" that don't change value properly.


Thu Feb 26, 2009 5:18 pm
Profile
Rookie

Joined: Wed Feb 18, 2009 4:06 pm
Posts: 12
Post Re: Last minute problems with sonar
thanks,

The sonar is the lego provided ultrasonic sensor (which I call sonar).

As far as pushing the robot around, we have a program that displays the sonar reading whicle we push the robot around (no motors running), this works fine.

However, the hitechnic protoytpe board is also not running. so I'm guessing either motor interference or software problems with the hitechnic prototype board driver.

Peter


Thu Feb 26, 2009 7:37 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Last minute problems with sonar
yes, the lego sonar would fall under the category of "notoriously bad" at false readings. In fact the lego sonar is one of the worse sonars I've ever seen.

Also beware it has a large "deadband" between 10in and 20in where there is a high probability of it giving false readings of 20in.

I personally recommend the sonars from www.maxbotix.com. These sonars are the same price and much better value. They various beam widths available and I've had very good results with them.

It sounds like you have another problem though. I've used the HTPB driver along with other sensors without any motor interference problems so it could be a software problem. If you can give some more detail on your setup and problem we can probably help get it fixed.


Mon Mar 02, 2009 11:53 am
Profile
Rookie

Joined: Wed Feb 18, 2009 4:06 pm
Posts: 12
Post Re: Last minute problems with sonar
Thanks for any help. This is a big problem for us at this point. The routine below is our line follower algorithm which is used to move to the center during autonomous mode. The line follower works fine until the very end (where it should stop based on the sonar reading getting below the "dist" threshold). The threshold is around 30.

We have another kick out routine which is unrealiable (this one relies on all the sensors returning black which occurs because the black curtain in front of the robot folds under (this cannot be easily explained)) (the curtain is also in place to shield out ambient light).

The log file typically returns values of around 1004, which makes no sense?

BTW. This routine is called after the robot has turned onto the line (which also works reliably).

Also, the robot has three sensors in a row (spaced about .8 inches apart) interspaced with 4 LED illuminators.

Lastly, a stand alone sonar sensor program which simply reads the sonar values and displays them on the front panel of the NXT works fine.

void LineFollow(int dist)
{
int adcVal1=0;
int adcVal3=0;
int SensValue=200;
int SensValue1=0;
int SensValue2=0;
int SensValue3=0;

nMotorEncoder[motorD] = 0;
/* turn motors on straight */
motor[motorD] = -100;
motor[motorE] = 100;
motor[motorB]=100; //start belt

// loop until we hit distance

while ( SensValue >= dist )
//while (1)
{
while((HTPBReadADC(HTPB,2,8)*22) >750) {
// keep going straight
motor[motorD] = -100;
motor[motorE] = 100;
SensValue=SensorValue[sonarSensor];
if(SensValue < dist) break;
}
motor[motorD] = 0;
motor[motorE] = 0;
wait1Msec(50);
adcVal1 = HTPBReadADC(HTPB,1,8)*19;
adcVal3 = HTPBReadADC(HTPB,3,8)*10;
//offline - correct back onto line
//unless we're at end
if((adcVal1<400)&& (adcVal3<400)) {
// PlayTone(700,10);
break;
}
if(adcVal1 > adcVal3) TurnUntilLine(0);
else TurnUntilLine(1);
//update sonar sensor
SensValue=SensorValue[sonarSensor];
AddToDatalog(SensValue);

}

motor[motorD] = 0;
motor[motorE] = 0;

}


Mon Mar 02, 2009 12:59 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Last minute problems with sonar
2 really quick things and I'll look more in depth later.

1. Which version of the HTPB driver do you use? There is a super secret version 0.4 (which is mislabeled in the header as 0.3) that has a HTPBReadAllADC()
http://www.breigh.com/xander/i2c-testprograms.zip

This probably isn't your problem but its alot cleaner and more efficient. The I2C calls to the HTPB are very slow (with respect to everything else).

2. I don't see your pragma header? I'm assuming you have one. Just double check that you're setting the sensor type correctly...I think it matters.


Mon Mar 02, 2009 1:43 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Last minute problems with sonar
Haha, super secret. Nothing I write is super secret. However, some of my drivers could do with a bit of better versioning and certainly better documentation. Fear not, I am in the process of overhauling all of my drivers and the documentation that goes along with them. I will be coming out with a suite of drivers for all HiTechnic devices, supporting their less frequently used functionality as well as the more commonly used things.

I will keep the forums posted, of course.

I'll upload the fixed HTPB drivers to my Google Code page in a few hours and will amend this post when it is done.

You can find my currently posted drivers here: [LINK].

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 02, 2009 2:19 pm
Profile WWW
Rookie

Joined: Wed Feb 18, 2009 4:06 pm
Posts: 12
Post Re: Last minute problems with sonar
This is the top of the autonomous program. Note that I commented out the #pragma line and added the const tSensors below (line 9). I did this because it is how the sample code provided worked. (of course, I tried it both ways with no difference in the results). Of course, I coudn't find any documentation on any of this.

The driver version is 0.3 described in the include?

#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Sensor, S2, HTPB, sensorI2CCustom9V)
//#pragma config(Sensor, S3, sonar25, sensorSONAR)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, PIDControl)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, PIDControl)
#pragma config(Servo, servo1, arm1, tServoNormal)
#pragma config(Servo, servo2, arm2, tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
const tSensors sonarSensor = (tSensors) S3; //sensorSONAR //*!!!!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Autonomous Mode Code Template
//
// This file contains a template for simplified creation of an autonomous program for an FTC
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
#include "HTPB-driver-0_3.c"
#include "brooks_subroutines.c"


Mon Mar 02, 2009 2:27 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Last minute problems with sonar
xander,
be assured it wasn't meant to be a slam just a joke. :)
Personally, I ran across the new version by accident and got confused by the version numbers.

pbesen,
How long before your next event?

I you have time (and want to) get a maxbotix sensor, you could easily hook it into the HTPB (it has an analog output which is how I use them).

Either way, I think I can test out your setup. I have an extra HTPB and LEGO Sonar. I personally never used them at the same time so I'll give it a shot and let you know what I find.


Mon Mar 02, 2009 3:02 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Last minute problems with sonar
chadgeorge wrote:
xander,
be assured it wasn't meant to be a slam just a joke. :)
Personally, I ran across the new version by accident and got confused by the version numbers.

Oh no worries, I didn't take it as such :)

Anyway, as promised, check out my post in the 3rd party sensor driver forum: viewtopic.php?f=41&t=1283

I hope you like the new documentation style :)

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 02, 2009 3:26 pm
Profile WWW
Rookie

Joined: Wed Feb 18, 2009 4:06 pm
Posts: 12
Post Re: Last minute problems with sonar
Our second and final contest is this weekend.

BTW. In the latest HTPB driver - version 0.4, I noticed the new function "clearI2CBus" in response to RobotC bug entry 222? Is the bug log actually available to anyone? The link at robotc.net to bug entries is dead.

(excerpt from HTPB driver version 0.4)
/
*
=============================================================================
This function allows conversion of an unsigned byte to a signed int.
This is a work-around for RobotC bug entry 222
http://www.education.rec.ri.cmu.edu/too ... php?id=222

*/
int ubyteToInt(byte _byte) {
return (_byte & 0x80) ? (_byte & 0x7F) + 0x80 : _byte;
}

void clearI2CBus(tSensors _link) {
ubyte _tmp = 0;
while (nI2CBytesReady[_link] > 0)
readI2CReply(_link, _tmp, 1);
}


Mon Mar 02, 2009 4:10 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Last minute problems with sonar
I think they reorganized the website and forgot to update the link.

http://www.robotc.net/mantis/my_view_page.php


Mon Mar 02, 2009 4:15 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Last minute problems with sonar
None of the bugs I have submitted so far have been fixed in any of the public releases of RobotC.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 02, 2009 4:19 pm
Profile WWW
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Last minute problems with sonar
okay. download xander's new driver that he posted and try this sample code.
I verified it works with the HTPB and a LEGO sonar at the same time.

Your #pragma section didn't work for me so I changed it. Maybe thats your problem. I didn't try to verify your actual Line Following code yet. Lets make sure your sensors work 100% then the rest will be easy.

Code:
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Sensor, S2, HTPB, sensorI2CCustomFast9V)
#pragma config(Sensor, S3, sonarSensor, sensorSONAR)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, PIDControl)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, PIDControl)
#pragma config(Servo, servo1, arm1, tServoNormal)
#pragma config(Servo, servo2, arm2, tServoNormal)

#include "HTPB-driver.h"

void simpleTest()
{
  tBuffer buff;
  int sonar;

  workAround(HTPB);

  while(true)
  {
    /* you were using only 8 bits..why not use all 10? */
    HTPBReadAllADC(HTPB, buff, 10);
    sonar = SensorValue[sonarSensor];

    nxtDisplayTextLine(1, "Sonar: %d", sonar);
    nxtDisplayTextLine(2, "A/D 1: %d", buff.arr[0]);
    nxtDisplayTextLine(3, "A/D 2: %d", buff.arr[1]);
    nxtDisplayTextLine(4, "A/D 3: %d", buff.arr[2]);

    wait1Msec(50); // Sonar is actually only updated at 20Hz
  }
}

task main()
{
  simpleTest();
}


Mon Mar 02, 2009 4:52 pm
Profile
Rookie

Joined: Wed Feb 18, 2009 4:06 pm
Posts: 12
Post Re: Last minute problems with sonar
Thanks,

I actually have a day job, so I won't be able to get to this until this evening.

Will report results in ~5-6 hours.

Peter


Mon Mar 02, 2009 4:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.