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

Last change on this file since 157 was 157, checked in by Sanahuja Guillaume, 7 years ago

iadded isready to iodevice:
avoid problem of imu not ready in ardrone2

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