Re: lms200 segfault on GetRange() - player 2.1.1
here is the program that doesnt work when i put it in the real laser
#include <libplayerc++/playerc++.h>
#include <iostream>
#include "args.h"
#include <stdlib.h> // for atof()
#include <unistd.h>
#include <math.h>
#include <string>
#define RAYS 32
int
main(int argc, char **argv)
{
parse_args(argc,argv);
// we throw exceptions on creation if we fail
try
{
using namespace PlayerCc;
PlayerClient robot(gHostname, gPort);
Position2dProxy pp(&robot, gIndex);
LaserProxy lp(&robot, gIndex);
std::cout << robot << std::endl;
for(iii=0; iii<2; iii++) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
robot.Read();
pp.SetMotorEnable (true);
// go into read-think-act loop
for(;;)
{
double newspeed = 0;
double newturnrate = 0;
// this blocks until new data comes; 10Hz by default
robot.Read();
double minR = lp.GetMinRight();
double minL = lp.GetMinLeft();
std::cout <<lp.GetRange(1)<< std::endl;
// laser avoid (stolen from esben's java example)
// std::cout << "minR: " << minR <<std::endl
// << "minL: " << minL
// << std::endl;
double l = (1e5*minR)/500-100;
double r = (1e5*minL)/500-100;
if (l > 100)
l = 100;
if (r > 100)
r = 100;
newspeed = (r+l)/1e3;
newturnrate = (r-l);
newturnrate = limit(newturnrate, -40.0, 40.0);
newturnrate = dtor(newturnrate);
// std::cout << "speed: " << newspeed
// << "turn: " << newturnrate
// << std::endl;
// write commands to robot
pp.SetSpeed(newspeed, newturnrate);
}
}
catch (PlayerCc::PlayerError e)
{
std::cerr << e << std::endl;
return -1;
}
}
This Program Gives The GetRange reading beautifully when in simulation however when it is applied to real
Sick laser it just frezee the simulation along with playerV.
but when i erase:
for(iii=0; iii<2; iii++) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
robot.Read();
and replace this std::cout <<lp.GetRange(1)<< std::endl;
(i replace this because of the segmentation error)
with this std::cout << lp << std::endl;
and run it again in simulation with playerV it does gives me the real reading from the laser
(from outputting "lp" but not GetRange).
my goal here is to do GetRange() on the real laser and use it on my potential field program..
any ideas?
Thanks
sorry for any wrong terminology(noobie)