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/SimuBldc.cpp

    r3 r15  
    2929using namespace flair::gui;
    3030
    31 namespace flair
    32 {
    33 namespace actuator
    34 {
     31namespace flair {
     32namespace actuator {
    3533
    36 SimuBldc::SimuBldc(const IODevice* parent,Layout* layout,string name,uint8_t motors_count,uint32_t dev_id) :Bldc(parent,layout,name,motors_count)
    37 {
    38     ostringstream dev_name;
    39     dev_name << "simu_bldc_" << dev_id;
    40     shmem=new SharedMem(this,dev_name.str().c_str(),motors_count*sizeof(float));
     34SimuBldc::SimuBldc(const IODevice *parent, Layout *layout, string name,
     35                   uint8_t motors_count, uint32_t dev_id)
     36    : Bldc(parent, layout, name, motors_count) {
     37  ostringstream dev_name;
     38  dev_name << "simu_bldc_" << dev_id;
     39  shmem =
     40      new SharedMem(this, dev_name.str().c_str(), motors_count * sizeof(float));
    4141
    42     GroupBox *groupbox=new GroupBox(layout->NewRow(),"simubldc");
    43     k=new DoubleSpinBox(groupbox->NewRow(),"k driver:",0,10000,1);
     42  GroupBox *groupbox = new GroupBox(layout->NewRow(), "simubldc");
     43  k = new DoubleSpinBox(groupbox->NewRow(), "k driver:", 0, 10000, 1);
    4444}
    4545
    46 SimuBldc::SimuBldc(const Object* parent,string name,uint8_t motors_count,uint32_t dev_id) :Bldc(parent,name,motors_count) {
    47     ostringstream dev_name;
    48     dev_name << "simu_bldc_" << dev_id;
    49     shmem=new SharedMem(this,dev_name.str().c_str(),motors_count*sizeof(float));
     46SimuBldc::SimuBldc(const Object *parent, string name, uint8_t motors_count,
     47                   uint32_t dev_id)
     48    : Bldc(parent, name, motors_count) {
     49  ostringstream dev_name;
     50  dev_name << "simu_bldc_" << dev_id;
     51  shmem =
     52      new SharedMem(this, dev_name.str().c_str(), motors_count * sizeof(float));
    5053
    51     //reset values
    52     float values[motors_count];
    53     for(int i=0;i<motors_count;i++) values[i]=0;
     54  // reset values
     55  float values[motors_count];
     56  for (int i = 0; i < motors_count; i++)
     57    values[i] = 0;
    5458
    55     shmem->Write((char*)&values,motors_count*sizeof(float));
     59  shmem->Write((char *)&values, motors_count * sizeof(float));
    5660}
    5761
    58 SimuBldc::~SimuBldc() {
     62SimuBldc::~SimuBldc() {}
     63
     64void SimuBldc::SetMotors(float *value) {
     65  float values[MotorsCount()];
     66
     67  for (int i = 0; i < MotorsCount(); i++)
     68    values[i] = k->Value() * value[i];
     69
     70  shmem->Write((char *)&values, MotorsCount() * sizeof(float));
     71
     72  // on prend une fois pour toute le mutex et on fait des accès directs
     73  output->GetMutex();
     74  for (int i = 0; i < MotorsCount(); i++)
     75    output->SetValueNoMutex(i, 0, values[i]);
     76  output->ReleaseMutex();
    5977}
    6078
    61 void SimuBldc::SetMotors(float* value) {
    62     float values[MotorsCount()];
     79void SimuBldc::GetSpeeds(float *value) const {
     80  float values[MotorsCount()];
     81  shmem->Read((char *)&values, MotorsCount() * sizeof(float));
    6382
    64     for(int i=0;i<MotorsCount();i++) values[i]=k->Value()*value[i];
    65 
    66     shmem->Write((char*)&values,MotorsCount()*sizeof(float));
    67 
    68     //on prend une fois pour toute le mutex et on fait des accès directs
    69     output->GetMutex();
    70     for(int i=0;i<MotorsCount();i++) output->SetValueNoMutex(i,0,values[i]);
    71     output->ReleaseMutex();
    72 }
    73 
    74 void SimuBldc::GetSpeeds(float* value) const {
    75     float values[MotorsCount()];
    76     shmem->Read((char*)&values,MotorsCount()*sizeof(float));
    77 
    78     for(int i=0;i<MotorsCount();i++) value[i]=values[i];
     83  for (int i = 0; i < MotorsCount(); i++)
     84    value[i] = values[i];
    7985}
    8086
Note: See TracChangeset for help on using the changeset viewer.