[375] | 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/12/07
|
---|
| 6 | // filename: SimuUgvControls.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
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 | #include "SimuUgvControls.h"
|
---|
| 18 | #include <SharedMem.h>
|
---|
| 19 | #include <sstream>
|
---|
| 20 | #include <string.h>
|
---|
| 21 |
|
---|
| 22 | using std::string;
|
---|
| 23 | using std::ostringstream;
|
---|
| 24 | using namespace flair::core;
|
---|
| 25 |
|
---|
| 26 | namespace flair {
|
---|
| 27 | namespace actuator {
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | SimuUgvControls::SimuUgvControls(const Object *parent, string name,
|
---|
| 31 | uint32_t modelId,uint32_t deviceId)
|
---|
| 32 | : IODevice(parent, name) {
|
---|
| 33 | shmem =new SharedMem(this, ShMemName(modelId, deviceId), 2 * sizeof(float)+sizeof(Time));
|
---|
| 34 |
|
---|
| 35 | buf=(char*)malloc(2 * sizeof(float)+sizeof(Time));
|
---|
| 36 | if(buf==NULL) {
|
---|
| 37 | Err("error creating buffer\n");
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | // reset values
|
---|
| 42 | float *values=(float*)buf;
|
---|
| 43 | for (int i = 0; i < 2; i++) values[i] = 0;
|
---|
| 44 | Time time=GetTime();
|
---|
| 45 | memcpy(buf+2 * sizeof(float),&time,sizeof(Time));
|
---|
| 46 |
|
---|
| 47 | shmem->Write(buf, 2 * sizeof(float)+sizeof(Time));
|
---|
| 48 |
|
---|
| 49 | SetIsReady(true);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | SimuUgvControls::~SimuUgvControls() {
|
---|
| 53 | if(buf!=NULL) free(buf);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | string SimuUgvControls::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 57 | ostringstream dev_name;
|
---|
| 58 | dev_name << "simu" << modelId << "_ugvcontrols_" << deviceId;
|
---|
| 59 | return dev_name.str().c_str();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | void SimuUgvControls::GetControls(float *speed,float *turn,Time* time) const {
|
---|
| 64 | float *values=(float*)buf;
|
---|
| 65 | shmem->Read(buf, 2 * sizeof(float)+sizeof(Time));
|
---|
| 66 | memcpy(time,buf+2 * sizeof(float),sizeof(Time));
|
---|
| 67 |
|
---|
| 68 | *speed = values[0];
|
---|
| 69 | *turn = values[1];
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | } // end namespace actuator
|
---|
| 73 | } // end namespace flair
|
---|