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

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

maj for armv5te

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