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

Last change on this file since 4 was 3, checked in by Sanahuja Guillaume, 6 years ago

sensoractuator

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