source: flair-src/trunk/lib/FlairSensorActuator/src/Bldc.cpp@ 9

Last change on this file since 9 was 3, checked in by Sanahuja Guillaume, 9 years ago

sensoractuator

File size: 2.5 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2013/11/14
6// filename: Bldc.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Virtual class for brushless drivers
14//
15//
16/*********************************************************************/
17
18#include "Bldc.h"
19#include "Bldc_impl.h"
20#include <cvmatrix.h>
21#include <DoubleSpinBox.h>
22#include <sstream>
23
24using std::string;
25using std::ostringstream;
26using namespace flair::core;
27using namespace flair::gui;
28
29namespace flair { namespace actuator {
30
31Bldc::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);
33
34 cvmatrix_descriptor* desc=new cvmatrix_descriptor(motors_count,2);
35 for(int i=0;i<motors_count;i++) {
36 ostringstream speed,current;
37 speed << "speed_" << i;
38 desc->SetElementName(i,0,speed.str());
39
40 current << "current_" << i;
41 desc->SetElementName(i,1,current.str());
42 }
43
44 output=new cvmatrix(this,desc,floatType);
45 AddDataToLog(output);
46}
47
48Bldc::Bldc(const Object* parent,string name,uint8_t motors_count) : IODevice(parent,name) {
49 pimpl_=new Bldc_impl(this,motors_count);
50}
51
52Bldc::~Bldc() {
53 delete pimpl_;
54}
55
56void Bldc::UpdateFrom(const io_data *data) {
57 pimpl_->UpdateFrom(data);
58}
59
60void Bldc::LockUserInterface(void) const {
61 pimpl_->LockUserInterface();
62}
63
64void Bldc::UnlockUserInterface(void) const {
65 pimpl_->UnlockUserInterface();
66}
67
68Layout* Bldc::GetLayout(void) const {
69 return (Layout*)pimpl_->layout;
70}
71
72void Bldc::UseDefaultPlot(TabWidget* tabwidget) {
73 pimpl_->UseDefaultPlot(tabwidget);
74}
75
76uint8_t Bldc::MotorsCount(void) const {
77 return pimpl_->motors_count;
78}
79
80cvmatrix *Bldc::Output(void) const {
81 return output;
82}
83
84bool Bldc::AreEnabled(void) const {
85 return pimpl_->are_enabled;
86}
87
88void 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
99void 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();
104}
105
106} // end namespace sensor
107} // end namespace flair
Note: See TracBrowser for help on using the repository browser.