| 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 | #include "compile_info.h"
|
---|
| 24 |
|
---|
| 25 | //todo: put it on seprate file, but not possible with static lib?
|
---|
| 26 | static void constructor() __attribute__((constructor));
|
---|
| 27 |
|
---|
| 28 | void constructor() {
|
---|
| 29 | compile_info("FlairSensorActuator");
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | using std::string;
|
---|
| 33 | using std::ostringstream;
|
---|
| 34 | using namespace flair::core;
|
---|
| 35 | using namespace flair::gui;
|
---|
| 36 |
|
---|
| 37 | namespace flair {
|
---|
| 38 | namespace actuator {
|
---|
| 39 |
|
---|
| 40 | Bldc::Bldc(const IODevice *parent, Layout *layout, string name,
|
---|
| 41 | uint8_t motors_count)
|
---|
| 42 | : IODevice(parent, name) {
|
---|
| 43 | pimpl_ = new Bldc_impl(this, layout, name, motors_count);
|
---|
| 44 |
|
---|
| 45 | cvmatrix_descriptor *desc = new cvmatrix_descriptor(motors_count, 2);
|
---|
| 46 | for (int i = 0; i < motors_count; i++) {
|
---|
| 47 | ostringstream speed, current;
|
---|
| 48 | speed << "speed_" << i;
|
---|
| 49 | desc->SetElementName(i, 0, speed.str());
|
---|
| 50 |
|
---|
| 51 | current << "current_" << i;
|
---|
| 52 | desc->SetElementName(i, 1, current.str());
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | output = new cvmatrix(this, desc, floatType);
|
---|
| 56 | delete desc;
|
---|
| 57 | AddDataToLog(output);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | Bldc::Bldc(const Object *parent, string name, uint8_t motors_count)
|
---|
| 61 | : IODevice(parent, name) {
|
---|
| 62 | pimpl_ = new Bldc_impl(this, motors_count);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | Bldc::~Bldc() { delete pimpl_; }
|
---|
| 66 |
|
---|
| 67 | void Bldc::UpdateFrom(const io_data *data) { pimpl_->UpdateFrom(data); }
|
---|
| 68 |
|
---|
| 69 | void Bldc::LockUserInterface(void) const { pimpl_->LockUserInterface(); }
|
---|
| 70 |
|
---|
| 71 | void Bldc::UnlockUserInterface(void) const { pimpl_->UnlockUserInterface(); }
|
---|
| 72 |
|
---|
| 73 | Layout *Bldc::GetLayout(void) const { return (Layout *)pimpl_->layout; }
|
---|
| 74 |
|
---|
| 75 | void Bldc::UseDefaultPlot(TabWidget *tabwidget) {
|
---|
| 76 | pimpl_->UseDefaultPlot(tabwidget);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | uint8_t Bldc::MotorsCount(void) const { return pimpl_->motors_count; }
|
---|
| 80 |
|
---|
| 81 | cvmatrix *Bldc::Output(void) const { return output; }
|
---|
| 82 |
|
---|
| 83 | bool Bldc::AreEnabled(void) const { return pimpl_->are_enabled; }
|
---|
| 84 |
|
---|
| 85 | void Bldc::SetEnabled(bool status) {
|
---|
| 86 | if (pimpl_->are_enabled != status) {
|
---|
| 87 | pimpl_->are_enabled = status;
|
---|
| 88 | if (pimpl_->are_enabled) {
|
---|
| 89 | LockUserInterface();
|
---|
| 90 | } else {
|
---|
| 91 | UnlockUserInterface();
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void Bldc::SetPower(int motor_id, float value) {
|
---|
| 97 | // use output mutex to avoid making a new mutex
|
---|
| 98 | output->GetMutex();
|
---|
| 99 | pimpl_->power[motor_id] = value;
|
---|
| 100 | output->ReleaseMutex();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | } // end namespace sensor
|
---|
| 104 | } // end namespace flair
|
---|