Re: wander.cpp position update


First of all, your code is after a 'run' so won't get called until the
robot has disconnected (ie you hit control C or reset the
microcontroller)... thats why you're always getting the same
position...  If you put in a 'runAsync' instead of a 'run' you'd get
more like the behavior your expect...  

You also shouldn't have a (time % 125) in there... just have your
sleep sleep for 125 and don't have the % 125 in there... since if you
really slept for 50 ms you'd never hit the 125 cycle... apparently it
is, but I don't know how (it should hit maybe every 250... but thats
the wrong way to approach timing).

The easier way to do all of this is to make a user task... you can see
a good example of how to do this in examples/simpleUserTask, you could
also just have a global function with an ArGlobalFunctor if you wanted
a simpler start.

User tasks get called every robot cycle... which is of course when you
want your data.  Unless you're getting into threading stuff you're
probably better off going with a user task... its also a lot easier to
combine different user tasks than it is loops like the one you have
below... ie you can make your code more modular so you can use
different bits and pieces together.

Matt LaFary
Activmedia Robotics


On Tue, Mar 19, 2002 at 12:26:36PM -0800, Aumack Steven wrote:
> I want to modify the wander.cpp file so that i can
> ouput (to a file) the X,Y,Th position, and time during
> the execution of this demo.  here is some of the code
> that I wrote so far.  it is not working properly.  any
> suggestions?
> 
> Thanks a lot,
> 
> i have included fstream.h and iomanip.h
> 
> i made sure to also write...so that is not a problem.
> 
> ArTime start;
> ArRobot robot;
> double PosX, PosY, PosTh;
> int time;
> 
> 
> 
> 
>   // add these actions
>   robot.addAction(&recover, 100);
>   robot.addAction(&bumpers, 75);
>   robot.addAction(&avoidFrontNear, 50);
>   robot.addAction(&avoidFrontFar, 49);
>   robot.addAction(&constantVelocity, 25);
>   
>   // start the robot running, true so that if we lose
> connection the run stops
>   robot.run(true);
> 
> 
> 
>   start.setToNow();
> 
>   f << "Wandering Around Aimlessly/n";
>   f << setw(11) << "X" << setw(11) << "Y" << setw(11)
> << "Th" << setw(11) << "T" << endl;
> 
>   int i = 0;
> 
>   while(1)
>   {
> 	  robot.lock();
> 	  time = start.mSecSince();
> 	  if ( (time % 125) == 0)
> 	  {
> 		  PosX = robot.getX();
> 		  PosY = robot.getY();
> 		  PosTh = robot.getTh();
> 		  time = start.mSecSince();
> 		  f << setw(11) << PosX << setw(11) << PosY <<
> setw(11) << PosTh << setw(11) << time << endl;
> 	  }
> 	  robot.unlock();
> 	  ArUtil::sleep(50);
>   }
> 
>   f.close;       //closes file
> 	  
>   // now exit
>   Aria::shutdown();
>   return 0;
> }
> 
> 
> 
> and here is a sample output...
> 
> 
> Wandering Around Aimlessly
>           X          Y         Th          T
>     1456.41          0          0          0
>     1456.41          0          0        125
>     1456.41          0          0        250
>     1456.41          0          0        375
>     1456.41          0          0        500
>     1456.41          0          0        625
>     1456.41          0          0        750
>     1456.41          0          0        875
>     1456.41          0          0       1000
>     1456.41          0          0       1125
>     1456.41          0          0       1250
>     1456.41          0          0       1375
>     1456.41          0          0       1500
>     1456.41          0          0       1625
>     1456.41          0          0       1750
>     1456.41          0          0       1875
>     1456.41          0          0       2000
> 
> as you can see, positions are not updating every 125
> ms.
> 
> what is wrong?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值