Changeset 136 in flair-src


Ignore:
Timestamp:
02/13/17 15:02:54 (7 years ago)
Author:
Sanahuja Guillaume
Message:

vrpn: improved timeout

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/CircleFollower/uav/src/CircleFollower.cpp

    r135 r136  
    4242    Uav* uav=GetUav();
    4343
    44                 VrpnClient* vrpnclient=new VrpnClient("vrpn", uav->GetDefaultVrpnAddress(),10000, 80);
     44                VrpnClient* vrpnclient=new VrpnClient("vrpn", uav->GetDefaultVrpnAddress(),80);
    4545                uavVrpn = new MetaVrpnObject(uav->ObjectName());
    4646                getFrameworkManager()->AddDeviceToLog(uavVrpn);
  • trunk/demos/SimpleFleet/uav/src/SimpleFleet.cpp

    r135 r136  
    5353    Uav* uav=GetUav();
    5454               
    55         VrpnClient* vrpnclient=new VrpnClient("vrpn", uav->GetDefaultVrpnAddress(),10000, 80);
     55        VrpnClient* vrpnclient=new VrpnClient("vrpn", uav->GetDefaultVrpnAddress(),80);
    5656        uavVrpn = new MetaVrpnObject(uav->ObjectName());
    5757        getFrameworkManager()->AddDeviceToLog(uavVrpn);
  • trunk/lib/FlairSensorActuator/src/VrpnClient.cpp

    r122 r136  
    3737       
    3838VrpnClient::VrpnClient(string name,
    39                        string address, uint16_t us_period, uint8_t priority)
     39                       string address, uint8_t priority)
    4040    : Thread(getFrameworkManager(), name, priority) {
    4141        if (singleton != NULL) {
     
    4545
    4646  singleton = this;
    47   pimpl_ = new VrpnClient_impl(this, name, address, us_period);
     47  pimpl_ = new VrpnClient_impl(this, name, address);
    4848}
    4949
  • trunk/lib/FlairSensorActuator/src/VrpnClient.h

    r122 r136  
    4949  * \param name name
    5050  * \param address server address
    51   * \param us_period Thread period in us
    5251  * \param priority priority of the Thread
    5352  */
    5453  VrpnClient(std::string name,
    55              std::string address, uint16_t us_period, uint8_t priority);
     54             std::string address, uint8_t priority);
    5655
    5756  /*!
  • trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp

    r15 r136  
    4242
    4343VrpnClient_impl::VrpnClient_impl(VrpnClient *self, std::string name,
    44                                  std::string address, uint16_t us_period) {
    45   this->us_period = us_period;
     44                                 std::string address) {
    4645  this->self = self;
    4746  serialport = NULL;
     47        isConnected=false;
    4848
    4949  mutex = new Mutex(self, name);
     
    162162
    163163void VrpnClient_impl::Run(void) {
     164        struct timeval timeout;
     165        timeout.tv_sec=0;
     166        timeout.tv_usec=100000;
     167                       
    164168  while (!self->ToBeStopped()) {
    165169    if (UseXbee()) {
     
    200204              t.quat[i] = quat[i];
    201205            if (fabs(pos[0] > 10) || fabs(pos[1] > 10) || fabs(pos[2] > 10)) {
    202               printf("prob pos %f %f %f\n", pos[0], pos[1], pos[2]);
     206              Printf("prob pos %f %f %f\n", pos[0], pos[1], pos[2]);
    203207            } else {
    204208              // self->Printf("%i %f %f %f
     
    210214        }
    211215      }
    212     } else {
    213       connection->mainloop();
    214       mutex->GetMutex();
    215       for (unsigned int i = 0; i < trackables.size(); i++)
    216         trackables.at(i)->mainloop();
    217       mutex->ReleaseMutex();
    218 
    219       self->SleepUS(us_period);
     216    } else {//!UseXbee()
     217                        if(connection->connected()==vrpn_true && !isConnected) {
     218                                isConnected=true;
     219                                Printf("VRPN connected\n");
     220                        }
     221                        if(connection->connected()==vrpn_false && isConnected) {
     222                                isConnected=false;
     223                                Printf("VRPN disconnected\n");
     224                        }
     225                       
     226                        //timeout in mainloop is not well handled if not connected...
     227                        if(isConnected) {
     228                                //this is when trackables callbacks are called:
     229                                if(connection->mainloop(&timeout)!=0) {
     230                                        self->Warn("connection dropped\n");
     231                                }
     232                                //printf("%lld\n",GetTime()/(1000*1000));
     233                                mutex->GetMutex();
     234                                for (unsigned int i = 0; i < trackables.size(); i++)
     235                                        trackables.at(i)->mainloop();
     236                                mutex->ReleaseMutex();
     237                        } else {
     238                                connection->mainloop();
     239                                self->SleepMS(10);
     240                        }
    220241    }
    221242  }
  • trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h

    r16 r136  
    4747public:
    4848  VrpnClient_impl(flair::sensor::VrpnClient *self, std::string name,
    49                   std::string address, uint16_t us_period);
     49                  std::string address);
    5050  VrpnClient_impl(flair::sensor::VrpnClient *self, std::string name,
    5151                  flair::core::SerialPort *serialport, uint16_t us_period);
     
    7777  flair::core::OneAxisRotation *rotation_1, *rotation_2;
    7878  flair::core::SerialPort *serialport;
     79        bool isConnected;//only for ip connection, not for xbee
    7980};
    8081
Note: See TracChangeset for help on using the changeset viewer.