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

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

sources reformatted with flair-format-dir script

File size: 2.4 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>
23
24using std::string;
25using std::ostringstream;
26using namespace flair::core;
27using namespace flair::gui;
28
[15]29namespace flair {
30namespace actuator {
[3]31
[15]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);
[3]36
[15]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());
[3]42
[15]43    current << "current_" << i;
44    desc->SetElementName(i, 1, current.str());
45  }
[3]46
[15]47  output = new cvmatrix(this, desc, floatType);
48  AddDataToLog(output);
[3]49}
50
[15]51Bldc::Bldc(const Object *parent, string name, uint8_t motors_count)
52    : IODevice(parent, name) {
53  pimpl_ = new Bldc_impl(this, motors_count);
[3]54}
55
[15]56Bldc::~Bldc() { delete pimpl_; }
[3]57
[15]58void Bldc::UpdateFrom(const io_data *data) { pimpl_->UpdateFrom(data); }
[3]59
[15]60void Bldc::LockUserInterface(void) const { pimpl_->LockUserInterface(); }
[3]61
[15]62void Bldc::UnlockUserInterface(void) const { pimpl_->UnlockUserInterface(); }
[3]63
[15]64Layout *Bldc::GetLayout(void) const { return (Layout *)pimpl_->layout; }
[3]65
[15]66void Bldc::UseDefaultPlot(TabWidget *tabwidget) {
67  pimpl_->UseDefaultPlot(tabwidget);
[3]68}
69
[15]70uint8_t Bldc::MotorsCount(void) const { return pimpl_->motors_count; }
[3]71
[15]72cvmatrix *Bldc::Output(void) const { return output; }
[3]73
[15]74bool Bldc::AreEnabled(void) const { return pimpl_->are_enabled; }
[3]75
76void Bldc::SetEnabled(bool status) {
[15]77  if (pimpl_->are_enabled != status) {
78    pimpl_->are_enabled = status;
79    if (pimpl_->are_enabled) {
80      LockUserInterface();
81    } else {
82      UnlockUserInterface();
[3]83    }
[15]84  }
[3]85}
86
[15]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();
[3]92}
93
94} // end namespace sensor
95} // end namespace flair
Note: See TracBrowser for help on using the repository browser.