SonarProxy
Lana Eliason <[email protected]>
| Newsgroups | gmane.science.robotics.playerstage |
|---|---|
| Message-ID | <[email protected]> |
Hi guys,
I currently have a robot that I am trying to get to follow another one. It
has 3 sonars on the front for object detection going off in various angles.
However, I was reading up in the documentation and apparently the sonars
return distances in metres depending on how far away an obstacle is. I'm
currently outputting the data to the terminal (thanks to those who helped me
do that btw), but it's returning really weird numbers - was wondering if
anyone could tell me why. The robots are about 5m apart and as the srobot
gets closer it returns (sample of values):
-1073741824 1073165765 0 1074790400
-2147483648 1073010712 0 1074790400
-2147483648 1073010712 0 1074790400
-2147483648 1073010712 0 1074790400
-2147483648 1073010712 0 1074790400
-2147483648 1073010712 0 1074790400
The robots are obviously not that far apart.The code (which is looped
through repeatedly) that outputs this is as below (sorry, I can't format it
in my email client):
______________________________________________________________________________________
//----------------------------------------
// TARGET
//----------------------------------------
void TargetUAV(double *forwardSpeed, double *turnSpeed, \
BlobfinderProxy &bfp, SonarProxy &sp)
{
int i, centre;
playerc_blobfinder_blob_t blob;
//turns at 180 degrees/sec
int turningSpeed = 180;
//will avoid obstacles closer than 4m;
double avoidDistance = 4;
bool greenFound = false;
int noBlobs = bfp.GetCount();
//if no UAV in sight, halt UAV and exit function
if (noBlobs == 0)
{
*forwardSpeed = 0;
return;
}
/*number of pixels away from the image centre a blob
can be to be in front of the robot*/
int margin = 40;
int biggestBlobArea = 0;
int biggestBlob = 0;
//find the largest blob
for(i=0; i<noBlobs; i++)
{
//get blob from proxy
playerc_blobfinder_blob_t currBlob = bfp[i];
if(currBlob.area > biggestBlobArea)
{
biggestBlob = i;
biggestBlobArea = currBlob.area;
// if (currBlob.color == 00FF00)
//greenFound = true;
}
}
blob = bfp[biggestBlob];
// find centre of image
centre = bfp.GetWidth()/2;
// printf("sp[0] sp[1] sp[2] sp[3]\n");
// printf("---------------------------------\n");
if((sp[0] < avoidDistance) || (sp[1] < avoidDistance) || (sp[1] <
avoidDistance))
{
printf("%d %d %d %d \n", sp[0], sp[1], sp[2], sp[3]);
*forwardSpeed = 0;
*turnSpeed = 0;
// return;
}
//adjust turn to centre the blob in image
/*if the blob's centre is within some margin of the image
centre then move forwards, otherwise turn so that it is
centred. */
else
{
//blob to the left of centre
if(blob.x < centre-margin)
{
*forwardSpeed = 2;
//turn left
*turnSpeed = turningSpeed;
}
//blob to the right of centre
else if(blob.x > centre+margin)
{
*forwardSpeed = 2;
//turn right
*turnSpeed = -turningSpeed;
}
//otherwise go straight ahead
else
{
*forwardSpeed = 2;
*turnSpeed = 0;
}
return;
}
}
______________________________________________________________________________
If anyone could help, I'd really appreciate it :)
Thanks,
Lana
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Playerstage-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-developers