Changeset 15 in flair-src for trunk/lib/FlairSensorActuator/src/Bldc.cpp
- Timestamp:
- 04/08/16 15:40:57 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSensorActuator/src/Bldc.cpp
r3 r15 27 27 using namespace flair::gui; 28 28 29 namespace flair { namespace actuator { 29 namespace flair { 30 namespace actuator { 30 31 31 Bldc::Bldc(const IODevice* parent,Layout* layout,string name,uint8_t motors_count) : IODevice(parent,name) { 32 pimpl_=new Bldc_impl(this,layout,name,motors_count); 32 Bldc::Bldc(const IODevice *parent, Layout *layout, string name, 33 uint8_t motors_count) 34 : IODevice(parent, name) { 35 pimpl_ = new Bldc_impl(this, layout, name, motors_count); 33 36 34 cvmatrix_descriptor* desc=new cvmatrix_descriptor(motors_count,2);35 for(int i=0;i<motors_count;i++) {36 ostringstream speed,current;37 38 desc->SetElementName(i,0,speed.str());37 cvmatrix_descriptor *desc = new cvmatrix_descriptor(motors_count, 2); 38 for (int i = 0; i < motors_count; i++) { 39 ostringstream speed, current; 40 speed << "speed_" << i; 41 desc->SetElementName(i, 0, speed.str()); 39 42 40 41 desc->SetElementName(i,1,current.str());42 43 current << "current_" << i; 44 desc->SetElementName(i, 1, current.str()); 45 } 43 46 44 output=new cvmatrix(this,desc,floatType);45 47 output = new cvmatrix(this, desc, floatType); 48 AddDataToLog(output); 46 49 } 47 50 48 Bldc::Bldc(const Object* parent,string name,uint8_t motors_count) : IODevice(parent,name) { 49 pimpl_=new Bldc_impl(this,motors_count); 51 Bldc::Bldc(const Object *parent, string name, uint8_t motors_count) 52 : IODevice(parent, name) { 53 pimpl_ = new Bldc_impl(this, motors_count); 50 54 } 51 55 52 Bldc::~Bldc() { 53 delete pimpl_; 56 Bldc::~Bldc() { delete pimpl_; } 57 58 void Bldc::UpdateFrom(const io_data *data) { pimpl_->UpdateFrom(data); } 59 60 void Bldc::LockUserInterface(void) const { pimpl_->LockUserInterface(); } 61 62 void Bldc::UnlockUserInterface(void) const { pimpl_->UnlockUserInterface(); } 63 64 Layout *Bldc::GetLayout(void) const { return (Layout *)pimpl_->layout; } 65 66 void Bldc::UseDefaultPlot(TabWidget *tabwidget) { 67 pimpl_->UseDefaultPlot(tabwidget); 54 68 } 55 69 56 void Bldc::UpdateFrom(const io_data *data) { 57 pimpl_->UpdateFrom(data); 70 uint8_t Bldc::MotorsCount(void) const { return pimpl_->motors_count; } 71 72 cvmatrix *Bldc::Output(void) const { return output; } 73 74 bool Bldc::AreEnabled(void) const { return pimpl_->are_enabled; } 75 76 void Bldc::SetEnabled(bool status) { 77 if (pimpl_->are_enabled != status) { 78 pimpl_->are_enabled = status; 79 if (pimpl_->are_enabled) { 80 LockUserInterface(); 81 } else { 82 UnlockUserInterface(); 83 } 84 } 58 85 } 59 86 60 void Bldc::LockUserInterface(void) const { 61 pimpl_->LockUserInterface(); 62 } 63 64 void Bldc::UnlockUserInterface(void) const { 65 pimpl_->UnlockUserInterface(); 66 } 67 68 Layout* Bldc::GetLayout(void) const { 69 return (Layout*)pimpl_->layout; 70 } 71 72 void Bldc::UseDefaultPlot(TabWidget* tabwidget) { 73 pimpl_->UseDefaultPlot(tabwidget); 74 } 75 76 uint8_t Bldc::MotorsCount(void) const { 77 return pimpl_->motors_count; 78 } 79 80 cvmatrix *Bldc::Output(void) const { 81 return output; 82 } 83 84 bool Bldc::AreEnabled(void) const { 85 return pimpl_->are_enabled; 86 } 87 88 void Bldc::SetEnabled(bool status) { 89 if(pimpl_->are_enabled!=status) { 90 pimpl_->are_enabled=status; 91 if(pimpl_->are_enabled) { 92 LockUserInterface(); 93 } else { 94 UnlockUserInterface(); 95 } 96 } 97 } 98 99 void Bldc::SetPower(int motor_id,float value) { 100 //use output mutex to avoid making a new mutex 101 output->GetMutex(); 102 pimpl_->power[motor_id]=value; 103 output->ReleaseMutex(); 87 void Bldc::SetPower(int motor_id, float value) { 88 // use output mutex to avoid making a new mutex 89 output->GetMutex(); 90 pimpl_->power[motor_id] = value; 91 output->ReleaseMutex(); 104 92 } 105 93
Note:
See TracChangeset
for help on using the changeset viewer.