From: Julian H. <ju...@ne...> - 2005-05-02 08:14:01
|
>I am attempting to write some functions in C++ that will access and write to the position and laser proxies but they seem to return >unexpected data when accessed outside of the main function. I have included some basic code to help understand the problem. > >If I pass the proxy to the function as below, whenever I attempt to read data from the proxy, it returns the data as it was before the >function was called. >ie: proxy data is not being updated when inside the function. However, I can write to the proxy. ie: it does actually go around in >circles as intended. > >void circle(PlayerClient robot, PositionProxy pp){ > robot.Read(); > pp.SetSpeed(0.2,0.2); > pp.Print(); >} > >int main(int argc, char **argv){ > parse_args(argc,argv); > > PlayerClient robot(host,port); > PositionProxy pp(&robot,device_index,'a'); > LaserProxy lp(&robot,device_index,'a'); > > while(1){ > circle(robot,pp); > } >} > > >I have also tried opening a new socket within the function as below. > >void circle(){ > PlayerClient robot(host,port); > PositionProxy pp(&robot,device_index,'a'); > robot.Read(); > pp.SetSpeed(0.2,0.2); > pp.Print(); >} > >In the above case, veerLeft() is called with no arguments passed. This seems to work and is much faster, however I seem to get warnings >from player such as; "warning : 499 bytes leftover on write() to client" > > >Can anybody please explain to me what I am doing wrong? > >Cheers, The above "veerLeft()" should read "circle()". |