On Wed, 27 August, 2008 11:38 am, Thayne (Mech Stu) wrote:
> This is my modified program from the one inside the libplayer++
> when i run the program it gave me "segmentation fault" for the GetRange.
> Can anyone help me?
This is then a very bad modification of it. And shows that you first need to
learn c++ (sorry).
> PlayerClient robot(gHostname, gPort);
> Position2dProxy pp(&robot, gIndex);
> LaserProxy lp(&robot, gIndex);
> LaserProxy Read();
The example has nothing like that above. That line above tells the compiler
that you will somewhere define a function called Read that will return a
LaserProxy (this is called a declaration, even a forward declaration in that
case, IIRC). What the example has is, in the loop below, a call to the Read()
method of the class PlayerClient through one of its instances, namely robot,
created above. This is the "robot.Read()" of the example.
> std::cout << robot << std::endl;
> pp.SetMotorEnable (true);
> double newspeed = 0;
> double newturnrate = 0;
> std::cout<< "points in scan: " << lp.GetCount() <<std::endl;
> std::cout<< "Max Range(m): " << lp.GetMaxRange() <<std::endl;
> std::cout<< "Resolution(D): " << rtod(lp.GetScanRes()) <<std::endl;
> std::cout<< "Range(mm): " << lp.GetCount() <<std::endl<<std::endl;
> std::cout<< lp.GetRange(1) <<std::endl;
On top of that, your loop does not terminate (and the indentations are awful ;-).
As I also said in one of my posts on the lms200 driver is that you may have to
Read() until something is indeed read (lp.GetCount() > 0).
May I suggest that you first read a good book on c++ (just to name one,
Josutti's "object oriented programming in c++" is very good). This would save
you, and others on the list, a lot of time.
Sorry if my answer sounds a bit harsh, but this list is not supposed to be
about teaching c++ (or any programming language) but about using player/stage.
Hope this helps.