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

Last change on this file since 87 was 45, checked in by Sanahuja Guillaume, 8 years ago

added compile info

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