Advertisement
Guest User

test.cc

a guest
Feb 2nd, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include "stage.hh"
  2. using namespace Stg;
  3.  
  4. class Robot {
  5.     private:
  6.         Model* model;
  7.         ModelRanger* ranger;
  8.     public:
  9.         Robot(Model* model);
  10.         static int update(Model* model, Robot* robot);
  11.         static int updateRanger(ModelRanger* model, Robot* robot);
  12.         void Enable(Stg::Model* model);
  13. };
  14.  
  15. inline Robot::Robot(Model* model)
  16. :model(model),
  17. //ranger( (ModelRanger*)model->GetChild( "ranger:0" ))
  18. ranger((ModelRanger*)model->GetUnusedModelOfType( "ranger" ))
  19.  
  20. {
  21.     std::cout << "Enter decleration" << std::endl;
  22.     //Robot* nBot = this;
  23.     model->AddCallback( Model::CB_UPDATE, (model_callback_t)update, this );
  24.     //ranger->AddCallback( Model::CB_UPDATE, (model_callback_t)updateRanger, this );
  25.     std::cout << "before model subscribe" << std::endl;
  26.     model->Subscribe();
  27.     std::cout << "after model subscribe" << std::endl;
  28.     //Enable((Stg::Model*)ranger);
  29.     std::cout << "before ranger subscribe" << std::endl;
  30.     ranger->Subscribe();
  31.     std::cout << "after ranger subscribe" << std::endl;
  32. }
  33.  
  34. inline int Robot::update(Model* model, Robot* robot)
  35. {
  36.     //robot->ranger->Subscribe();
  37.     std::cout << "Enter update function" << std::endl;
  38.    
  39.     //const std::vector<ModelRanger::Sensor>& scan = robot->ranger->GetSensors();
  40.     const std::vector< meters_t > & scan = robot->ranger->GetRanges();
  41.    
  42.     uint32_t sample_count = scan.size();
  43.     std::cout << sample_count << std::endl;
  44. /**
  45.     for (int i=0; i<scan.size(); i++)
  46.     {
  47.         std::cout << "sesor" << i << ": " << std::endl;
  48.         std::cout << scan[i] << std::endl;
  49.         std::cout << std::endl;
  50.     }
  51. **/
  52.     std::cout << "exit update function" << std::endl;
  53.     return 0;
  54. }
  55.  
  56. inline int Robot::updateRanger(ModelRanger* model, Robot* robot)
  57. {
  58.     return 0;
  59. }
  60. inline void Robot::Enable( Stg::Model* model)
  61. {
  62.     model->Subscribe();
  63. }
  64. extern "C" int Init( Model* mod, CtrlArgs* args )
  65. {  
  66.     std::cout << "In Init" << std::endl;
  67.   new Robot((ModelPosition*)mod);
  68.  
  69.   return 0; //ok
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement