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 |
|
---|
24 | using std::string;
|
---|
25 | using std::ostringstream;
|
---|
26 | using namespace flair::core;
|
---|
27 | using namespace flair::gui;
|
---|
28 |
|
---|
29 | namespace flair {
|
---|
30 | namespace actuator {
|
---|
31 |
|
---|
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);
|
---|
36 |
|
---|
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());
|
---|
42 |
|
---|
43 | current << "current_" << i;
|
---|
44 | desc->SetElementName(i, 1, current.str());
|
---|
45 | }
|
---|
46 |
|
---|
47 | output = new cvmatrix(this, desc, floatType);
|
---|
48 | AddDataToLog(output);
|
---|
49 | }
|
---|
50 |
|
---|
51 | Bldc::Bldc(const Object *parent, string name, uint8_t motors_count)
|
---|
52 | : IODevice(parent, name) {
|
---|
53 | pimpl_ = new Bldc_impl(this, motors_count);
|
---|
54 | }
|
---|
55 |
|
---|
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);
|
---|
68 | }
|
---|
69 |
|
---|
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 | }
|
---|
85 | }
|
---|
86 |
|
---|
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();
|
---|
92 | }
|
---|
93 |
|
---|
94 | } // end namespace sensor
|
---|
95 | } // end namespace flair
|
---|