source: flair-src/trunk/lib/FlairSensorActuator/src/SimulatedBldc.cpp@ 318

Last change on this file since 318 was 286, checked in by Sanahuja Guillaume, 5 years ago

draw vrpn axis in simulator

File size: 2.2 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: 2014/02/07
[286]6// filename: SimulatedBldc.cpp
[3]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/*********************************************************************/
[268]17#ifdef CORE2_64
18
[286]19#include "SimulatedBldc.h"
[3]20#include <FrameworkManager.h>
21#include <GridLayout.h>
22#include <DoubleSpinBox.h>
23#include <GroupBox.h>
24#include <SharedMem.h>
[214]25#include <Matrix.h>
[3]26#include <sstream>
[214]27#include <string.h>
[3]28
29using std::string;
30using std::ostringstream;
31using namespace flair::core;
32using namespace flair::gui;
33
[15]34namespace flair {
35namespace actuator {
[3]36
[286]37SimulatedBldc::SimulatedBldc(const IODevice *parent, Layout *layout, string name,
[158]38 uint8_t motors_count, uint32_t modelId,uint32_t deviceId)
[15]39 : Bldc(parent, layout, name, motors_count) {
40 shmem =
[214]41 new SharedMem(this, ShMemName(modelId, deviceId), motors_count * sizeof(float)+sizeof(Time));
[3]42
[15]43 GroupBox *groupbox = new GroupBox(layout->NewRow(), "simubldc");
44 k = new DoubleSpinBox(groupbox->NewRow(), "k driver:", 0, 10000, 1);
[157]45
[214]46 buf=(char*)malloc(motors_count * sizeof(float)+sizeof(Time));
47 if(buf==NULL) {
48 Err("error creating buffer\n");
49 return;
50 }
[157]51 SetIsReady(true);
[3]52}
53
[286]54SimulatedBldc::~SimulatedBldc() {
[214]55 if(buf!=NULL) free(buf);
56}
[3]57
[286]58string SimulatedBldc::ShMemName(uint32_t modelId,uint32_t deviceId) {
[158]59 ostringstream dev_name;
60 dev_name << "simu" << modelId << "_bldc_" << deviceId;
61 return dev_name.str().c_str();
62}
63
[286]64void SimulatedBldc::SetMotors(float *value) {
[214]65 float *values=(float*)buf;
66 for (int i = 0; i < MotorsCount(); i++) values[i] = k->Value() * value[i];
67 Time time=GetTime();
68 memcpy(buf+MotorsCount() * sizeof(float),&time,sizeof(Time));
[3]69
[214]70 shmem->Write(buf, MotorsCount() * sizeof(float)+sizeof(Time));
[3]71
[15]72 // on prend une fois pour toute le mutex et on fait des accès directs
73 output->GetMutex();
[214]74 for (int i = 0; i < MotorsCount(); i++) {
[15]75 output->SetValueNoMutex(i, 0, values[i]);
[214]76 }
[15]77 output->ReleaseMutex();
[3]78}
79
80} // end namespace sensor
81} // end namespace flair
[268]82
83#endif
Note: See TracBrowser for help on using the repository browser.