[376] | 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: 2020/&2/09
|
---|
| 6 | // filename: SimulatedUgvControls.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Class for a simulation ugv controls
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 | #ifdef CORE2_64
|
---|
| 18 |
|
---|
| 19 | #include "SimulatedUgvControls.h"
|
---|
| 20 | #include <FrameworkManager.h>
|
---|
| 21 | #include <Matrix.h>
|
---|
| 22 | #include <SharedMem.h>
|
---|
| 23 | #include <sstream>
|
---|
| 24 | #include <string.h>
|
---|
| 25 |
|
---|
| 26 | using std::string;
|
---|
| 27 | using std::ostringstream;
|
---|
| 28 | using namespace flair::core;
|
---|
| 29 |
|
---|
| 30 | namespace flair {
|
---|
| 31 | namespace actuator {
|
---|
| 32 |
|
---|
[377] | 33 | SimulatedUgvControls::SimulatedUgvControls(string name, uint32_t modelId,uint32_t deviceId)
|
---|
| 34 | : UgvControls(name) {
|
---|
[376] | 35 |
|
---|
[377] | 36 | shmem = new SharedMem(this, ShMemName(modelId, deviceId),2 * sizeof(float)+sizeof(Time));
|
---|
[376] | 37 |
|
---|
| 38 | buf=(char*)malloc(2 * sizeof(float)+sizeof(Time));
|
---|
| 39 | if(buf==NULL) {
|
---|
| 40 | Err("error creating buffer\n");
|
---|
| 41 | return;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | SetIsReady(true);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | SimulatedUgvControls::~SimulatedUgvControls() {
|
---|
| 48 | if(buf!=NULL) free(buf);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | string SimulatedUgvControls::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 52 | ostringstream dev_name;
|
---|
| 53 | dev_name << "simu" << modelId << "_ugvcontrols_" << deviceId;
|
---|
| 54 | return dev_name.str().c_str();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | void SimulatedUgvControls::SetControls(float speed,float turn) {
|
---|
| 58 | float *values=(float*)buf;
|
---|
[377] | 59 | values[0]=speed;
|
---|
| 60 | values[1]=turn;
|
---|
[376] | 61 | Time time=GetTime();
|
---|
| 62 | memcpy(buf+2 * sizeof(float),&time,sizeof(Time));
|
---|
| 63 |
|
---|
| 64 | shmem->Write(buf, 2 * sizeof(float)+sizeof(Time));
|
---|
| 65 |
|
---|
| 66 | // on prend une fois pour toute le mutex et on fait des accès directs
|
---|
| 67 | output->GetMutex();
|
---|
| 68 | for (int i = 0; i < 2; i++) {
|
---|
[377] | 69 | output->SetValueNoMutex(i, 0, values[i]);
|
---|
[376] | 70 | }
|
---|
| 71 | output->ReleaseMutex();
|
---|
[435] | 72 |
|
---|
| 73 | output->SetDataTime(GetTime());
|
---|
| 74 | ProcessUpdate(output);
|
---|
[376] | 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | } // end namespace sensor
|
---|
| 79 | } // end namespace flair
|
---|
| 80 |
|
---|
| 81 | #endif |
---|