Stage: segmentation fault using blobfinder

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Stage: segmentation fault using blobfinder

renato
Hi
I'm using player 3.0.2 and stage 3.2.2. When I run my client application, my simulation ends randomly with segmentation fault when gets the GetStatus function in my code.
I’m new with player/stage and I’m struggling trying to discover what’s the problem with my code which is resulting the segmentation fault. Someone could you please help me to solve that?
Follow my code bellow:

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <libplayerc++/playerc++.h>

using namespace PlayerCc;

void GetStatus(int *status, BlobfinderProxy &bfp)
{
    playerc_blobfinder_blob_t blob;
    blob = bfp[0];

          if(blob.color == 65280)                
                  {    
            *status = 1;
                return;
          }
}    

int main(int argc, char *argv[])
{    
     
      /*need to do this line in c++ only*/
      using namespace PlayerCc;
   
      PlayerClient    robot("localhost", 6665);

      Position2dProxy p2dProxy(&robot,0);
      BlobfinderProxy blobProxy(&robot,0);
      GripperProxy    griProxy(&robot,0);
     
      SimulationProxy simProxy(&robot,0);  
     
      int status;
      int cont = 0;
      srand(time(NULL));
   
      //enable motors
      p2dProxy.SetMotorEnable(1);

      //request geometries
      p2dProxy.RequestGeom();
      sonarProxy.RequestGeom();
         
      robot.Read();

  while(true)
      {        
      robot.Read();
       
    if(blobProxy.GetCount() == 0)
    {
    p2dProxy.GoTo(0.8, 2.4, dtor(180));
    sleep(14);
    robot.Read();
    if(blobProxy.GetCount() == 0)
        {
          p2dProxy.GoTo(0.1, 0.2, dtor(-90));
          sleep(11);
          p2dProxy.GoTo(0.1, 0.2, dtor(80));    
          sleep(10);
        }    
    }

    if(blobProxy.GetCount() != 0)
          {
                  p2dProxy.SetSpeed(0.5, 0);
          }

    if(griProxy.GetBeams() != 0)
      {
        p2dProxy.SetSpeed(0, 0);
        griProxy.Close();
        sleep(1);
        robot.Read();    
       }
   
     if(griProxy.GetState() == 2 && cont == 0)
        {
        p2dProxy.GoTo(1.9, 3.4, dtor(90));
        sleep(13);
        cont = 1;    
        }    

     if(griProxy.GetState() == 2 && cont == 1)
        {
        GetStatus(&status, blobProxy);
        if (status = 1)        
          {  
             p2dProxy.GoTo(1.9, 4.13, dtor(90));    
             sleep(5);
             griProxy.Open();    
                   p2dProxy.SetSpeed(-0.5, dtor(0));
             sleep(1.97);
             robot.Read();
             p2dProxy.SetSpeed(0, dtor(0));
             sleep(10);
             cont++;
          }    
        }
     
      }
}
Reply | Threaded
Open this post in threaded view
|

Re: Stage: segmentation fault using blobfinder

Rich Mattes-2
On 06/05/2014 07:29 PM, renato wrote:

> Hi
> I'm using player 3.0.2 and stage 3.2.2. When I run my client application, my
> simulation ends randomly with segmentation fault when gets the GetStatus
> function in my code.
> I’m new with player/stage and I’m struggling trying to discover what’s the
> problem with my code which is resulting the segmentation fault. Someone
> could you please help me to solve that?
> Follow my code bellow:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <time.h>
> #include <libplayerc++/playerc++.h>
>
> using namespace PlayerCc;
>
> void GetStatus(int *status, BlobfinderProxy &bfp)
> {
>      playerc_blobfinder_blob_t blob;
>      blob = bfp[0];
>
>            if(blob.color == 65280)
>                    {
>              *status = 1;
>                  return;
>            }
> }
>


You should check and make sure that bfp.GetCount() > 0 before trying to
access bfp[0].  If there are no blobs in the blobfinder proxy, accessing
bfp[0] will be accessing unallocated space, which could cause a segfault.

Rich

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Playerstage-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/playerstage-users
Reply | Threaded
Open this post in threaded view
|

Re: Stage: segmentation fault using blobfinder

renato
Thanks Rich!!!

You were right, the  bfp[0] was accessing unallocated space because there was no blob detected by the blobfinder proxy at the time I was using it.

I really appreciated your prompt help.

Thanks again.

Renato