Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/SimuImu.cpp

    r3 r15  
    3131using namespace flair::gui;
    3232
    33 namespace flair { namespace sensor {
     33namespace flair {
     34namespace sensor {
    3435
    35 SimuImu::SimuImu(const FrameworkManager* parent,string name,uint32_t dev_id,uint8_t priority) :Imu(parent,name),Thread(parent,name,priority) {
    36     data_rate=new SpinBox(GetGroupBox()->NewRow(),"data rate"," Hz",1,500,1,200);
    37     ahrsData=new AhrsData((Imu*)this);
     36SimuImu::SimuImu(const FrameworkManager *parent, string name, uint32_t dev_id,
     37                 uint8_t priority)
     38    : Imu(parent, name), Thread(parent, name, priority) {
     39  data_rate =
     40      new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 200);
     41  ahrsData = new AhrsData((Imu *)this);
    3842
    39     ostringstream dev_name;
    40     dev_name << "simu_imu_" << dev_id;
    41     shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(imu_states_t));
     43  ostringstream dev_name;
     44  dev_name << "simu_imu_" << dev_id;
     45  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
     46                        sizeof(imu_states_t));
    4247}
    4348
    44 SimuImu::SimuImu(const IODevice* parent,string name,uint32_t dev_id) :Imu(parent,name),Thread(parent,name,0) {
    45     data_rate=NULL;
     49SimuImu::SimuImu(const IODevice *parent, string name, uint32_t dev_id)
     50    : Imu(parent, name), Thread(parent, name, 0) {
     51  data_rate = NULL;
    4652
    47     ostringstream dev_name;
    48     dev_name << "simu_imu_" << dev_id;
    49     shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),sizeof(imu_states_t));
     53  ostringstream dev_name;
     54  dev_name << "simu_imu_" << dev_id;
     55  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
     56                        sizeof(imu_states_t));
    5057}
    5158
    5259SimuImu::~SimuImu() {
    53     SafeStop();
    54     Join();
     60  SafeStop();
     61  Join();
    5562}
    5663
    5764void SimuImu::UpdateFrom(const io_data *data) {
    58     if(data!=NULL) {
    59         cvmatrix *input=(cvmatrix*)data;
    60         imu_states_t state;
     65  if (data != NULL) {
     66    cvmatrix *input = (cvmatrix *)data;
     67    imu_states_t state;
    6168
    62         input->GetMutex();
    63         state.q0=input->ValueNoMutex(0,0);
    64         state.q1=input->ValueNoMutex(1,0);
    65         state.q2=input->ValueNoMutex(2,0);
    66         state.q3=input->ValueNoMutex(3,0);
    67         state.wx=input->ValueNoMutex(7,0);
    68         state.wy=input->ValueNoMutex(8,0);
    69         state.wz=input->ValueNoMutex(9,0);
    70         input->ReleaseMutex();
     69    input->GetMutex();
     70    state.q0 = input->ValueNoMutex(0, 0);
     71    state.q1 = input->ValueNoMutex(1, 0);
     72    state.q2 = input->ValueNoMutex(2, 0);
     73    state.q3 = input->ValueNoMutex(3, 0);
     74    state.wx = input->ValueNoMutex(7, 0);
     75    state.wy = input->ValueNoMutex(8, 0);
     76    state.wz = input->ValueNoMutex(9, 0);
     77    input->ReleaseMutex();
    7178
    72         shmem->Write((char*)&state,sizeof(imu_states_t));
    73     }
     79    shmem->Write((char *)&state, sizeof(imu_states_t));
     80  }
    7481}
    7582
    7683void SimuImu::Run(void) {
    77     imu_states_t state;
    78     ImuData* imuData;
    79     GetDatas(&imuData);
     84  imu_states_t state;
     85  ImuData *imuData;
     86  GetDatas(&imuData);
    8087
    81     if(data_rate==NULL) {
    82         Thread::Err("not applicable for simulation part.\n");
    83         return;
     88  if (data_rate == NULL) {
     89    Thread::Err("not applicable for simulation part.\n");
     90    return;
     91  }
     92
     93  SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
     94
     95  while (!ToBeStopped()) {
     96    WaitPeriod();
     97
     98    if (data_rate->ValueChanged() == true) {
     99      SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
    84100    }
    85101
    86     SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
     102    shmem->Read((char *)&state, sizeof(imu_states_t));
     103    ahrsData->SetQuaternionAndAngularRates(
     104        Quaternion(state.q0, state.q1, state.q2, state.q3),
     105        Vector3D(state.wx, state.wy, state.wz));
    87106
    88     while(!ToBeStopped()) {
    89         WaitPeriod();
     107    imuData->SetDataTime(GetTime());
     108    ahrsData->SetDataTime(GetTime());
    90109
    91         if(data_rate->ValueChanged()==true) {
    92             SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
    93         }
    94 
    95         shmem->Read((char*)&state,sizeof(imu_states_t));
    96         ahrsData->SetQuaternionAndAngularRates(Quaternion(state.q0,state.q1,state.q2,state.q3)
    97                                                ,Vector3D(state.wx,state.wy,state.wz));
    98 
    99         imuData->SetDataTime(GetTime());
    100         ahrsData->SetDataTime(GetTime());
    101 
    102         UpdateImu();
    103         ProcessUpdate(ahrsData);
    104     }
     110    UpdateImu();
     111    ProcessUpdate(ahrsData);
     112  }
    105113}
    106114
Note: See TracChangeset for help on using the changeset viewer.