source: flair-src/branches/mavlink/lib/FlairSensorActuator/src/Bldc.cpp@ 79

Last change on this file since 79 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 2.4 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 {
30namespace actuator {
31
32Bldc::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
51Bldc::Bldc(const Object *parent, string name, uint8_t motors_count)
52 : IODevice(parent, name) {
53 pimpl_ = new Bldc_impl(this, motors_count);
54}
55
56Bldc::~Bldc() { delete pimpl_; }
57
58void Bldc::UpdateFrom(const io_data *data) { pimpl_->UpdateFrom(data); }
59
60void Bldc::LockUserInterface(void) const { pimpl_->LockUserInterface(); }
61
62void Bldc::UnlockUserInterface(void) const { pimpl_->UnlockUserInterface(); }
63
64Layout *Bldc::GetLayout(void) const { return (Layout *)pimpl_->layout; }
65
66void Bldc::UseDefaultPlot(TabWidget *tabwidget) {
67 pimpl_->UseDefaultPlot(tabwidget);
68}
69
70uint8_t Bldc::MotorsCount(void) const { return pimpl_->motors_count; }
71
72cvmatrix *Bldc::Output(void) const { return output; }
73
74bool Bldc::AreEnabled(void) const { return pimpl_->are_enabled; }
75
76void 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
87void 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
Note: See TracBrowser for help on using the repository browser.