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

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

corrected simu/device id for sensors

File size: 2.5 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 modelId,uint32_t deviceId)
36 : Bldc(parent, layout, name, motors_count) {
37 shmem =
38 new SharedMem(this, ShMemName(modelId, deviceId), motors_count * sizeof(float));
39
40 GroupBox *groupbox = new GroupBox(layout->NewRow(), "simubldc");
41 k = new DoubleSpinBox(groupbox->NewRow(), "k driver:", 0, 10000, 1);
42
43 SetIsReady(true);
44}
45
46SimuBldc::SimuBldc(const Object *parent, string name, uint8_t motors_count,
47 uint32_t modelId,uint32_t deviceId)
48 : Bldc(parent, name, motors_count) {
49 shmem =
50 new SharedMem(this, ShMemName(modelId, deviceId), motors_count * sizeof(float));
51
52 // reset values
53 float values[motors_count];
54 for (int i = 0; i < motors_count; i++)
55 values[i] = 0;
56
57 shmem->Write((char *)&values, motors_count * sizeof(float));
58
59 SetIsReady(true);
60}
61
62SimuBldc::~SimuBldc() {}
63
64string SimuBldc::ShMemName(uint32_t modelId,uint32_t deviceId) {
65 ostringstream dev_name;
66 dev_name << "simu" << modelId << "_bldc_" << deviceId;
67 return dev_name.str().c_str();
68}
69
70void SimuBldc::SetMotors(float *value) {
71 float values[MotorsCount()];
72
73 for (int i = 0; i < MotorsCount(); i++)
74 values[i] = k->Value() * value[i];
75
76 shmem->Write((char *)&values, MotorsCount() * sizeof(float));
77
78 // on prend une fois pour toute le mutex et on fait des accès directs
79 output->GetMutex();
80 for (int i = 0; i < MotorsCount(); i++)
81 output->SetValueNoMutex(i, 0, values[i]);
82 output->ReleaseMutex();
83}
84
85void SimuBldc::GetSpeeds(float *value) const {
86 float values[MotorsCount()];
87 shmem->Read((char *)&values, MotorsCount() * sizeof(float));
88
89 for (int i = 0; i < MotorsCount(); i++)
90 value[i] = values[i];
91}
92
93} // end namespace sensor
94} // end namespace flair
Note: See TracBrowser for help on using the repository browser.