It only works sometimes because the simulator may take a little time
to actually execute the pose change. So if you set the pose and then
immediately get the pose, you may or not see the change. But you should
(eventually) see the change in the Stage GUI.
You can, for example, set the pose, and then get the pose in a loop until the
new pose is the one that you set.
By the way, you don't need to use TruthProxy::GetPose(). You can
instead read the current pose directly from the fields x, y, and a in the
TruthProxy. These are updated when you call PlayerClient::Read(). (Again,
you may have to Read() more than once after calling TruthProxy::SetPose()
before you see the new pose).
Also, you don't need to define pi. Instead, #include <math.h> and use
On Fri, 2 Jan 2004, Shing Yenn Tan wrote:
> I'm trying to make use of the teleporting ability of TruthProxy to set the
> robot's orientation with respect to its original position in the Stage
> model. For e.g. make it turn 90 deg everytime SetPose() is called. Would
> someone kindly let me know if it is possible? I tried with a simple code but
> it seems to work sometimes only. It seems like the line "theta = ptheta +
> PI/2;" doesn't really add PI/2 to theta.
> int main(int argc, char **argv)
> PlayerClient robot("localhost");
> TruthProxy tp(&robot,0,'a');
> double px, py, ptheta;
> double x, y, theta;
> const float PI = 3.142;
> bool startflag = true;
> if (robot.Read() < 0)
> x = px;
> y = py;
> theta = ptheta + PI/2;
> startflag = false;