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

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

maj for armv5te

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