source: flair-src/trunk/lib/FlairSensorActuator/src/SimuBldc.cpp@ 151

Last change on this file since 151 was 15, checked in by Bayard Gildas, 8 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: 2014/02/07
6// filename: SimuBldc.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class for a simulation bldc
14//
15//
16/*********************************************************************/
17#include "SimuBldc.h"
18#include <FrameworkManager.h>
19#include <GridLayout.h>
20#include <DoubleSpinBox.h>
21#include <GroupBox.h>
22#include <SharedMem.h>
23#include <cvmatrix.h>
24#include <sstream>
25
26using std::string;
27using std::ostringstream;
28using namespace flair::core;
29using namespace flair::gui;
30
31namespace flair {
32namespace actuator {
33
34SimuBldc::SimuBldc(const IODevice *parent, Layout *layout, string name,
35 uint8_t motors_count, uint32_t dev_id)
36 : Bldc(parent, layout, name, motors_count) {
37 ostringstream dev_name;
38 dev_name << "simu_bldc_" << dev_id;
39 shmem =
40 new SharedMem(this, dev_name.str().c_str(), motors_count * sizeof(float));
41
42 GroupBox *groupbox = new GroupBox(layout->NewRow(), "simubldc");
43 k = new DoubleSpinBox(groupbox->NewRow(), "k driver:", 0, 10000, 1);
44}
45
46SimuBldc::SimuBldc(const Object *parent, string name, uint8_t motors_count,
47 uint32_t dev_id)
48 : Bldc(parent, name, motors_count) {
49 ostringstream dev_name;
50 dev_name << "simu_bldc_" << dev_id;
51 shmem =
52 new SharedMem(this, dev_name.str().c_str(), motors_count * sizeof(float));
53
54 // reset values
55 float values[motors_count];
56 for (int i = 0; i < motors_count; i++)
57 values[i] = 0;
58
59 shmem->Write((char *)&values, motors_count * sizeof(float));
60}
61
62SimuBldc::~SimuBldc() {}
63
64void SimuBldc::SetMotors(float *value) {
65 float values[MotorsCount()];
66
67 for (int i = 0; i < MotorsCount(); i++)
68 values[i] = k->Value() * value[i];
69
70 shmem->Write((char *)&values, MotorsCount() * sizeof(float));
71
72 // on prend une fois pour toute le mutex et on fait des accès directs
73 output->GetMutex();
74 for (int i = 0; i < MotorsCount(); i++)
75 output->SetValueNoMutex(i, 0, values[i]);
76 output->ReleaseMutex();
77}
78
79void SimuBldc::GetSpeeds(float *value) const {
80 float values[MotorsCount()];
81 shmem->Read((char *)&values, MotorsCount() * sizeof(float));
82
83 for (int i = 0; i < MotorsCount(); i++)
84 value[i] = values[i];
85}
86
87} // end namespace sensor
88} // end namespace flair
Note: See TracBrowser for help on using the repository browser.