// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2020/12/07 // filename: SimuUgvControls.cpp // // author: Guillaume Sanahuja // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: Class for a simulation ugv // // /*********************************************************************/ #include "SimuUgvControls.h" #include #include #include using std::string; using std::ostringstream; using namespace flair::core; namespace flair { namespace actuator { SimuUgvControls::SimuUgvControls(const Object *parent, string name, uint32_t modelId,uint32_t deviceId) : IODevice(parent, name) { shmem =new SharedMem(this, ShMemName(modelId, deviceId), 2 * sizeof(float)+sizeof(Time)); buf=(char*)malloc(2 * sizeof(float)+sizeof(Time)); if(buf==NULL) { Err("error creating buffer\n"); return; } // reset values float *values=(float*)buf; for (int i = 0; i < 2; i++) values[i] = 0; Time time=GetTime(); memcpy(buf+2 * sizeof(float),&time,sizeof(Time)); shmem->Write(buf, 2 * sizeof(float)+sizeof(Time)); SetIsReady(true); } SimuUgvControls::~SimuUgvControls() { if(buf!=NULL) free(buf); } string SimuUgvControls::ShMemName(uint32_t modelId,uint32_t deviceId) { ostringstream dev_name; dev_name << "simu" << modelId << "_ugvcontrols_" << deviceId; return dev_name.str().c_str(); } void SimuUgvControls::GetControls(float *speed,float *turn,Time* time) const { float *values=(float*)buf; shmem->Read(buf, 2 * sizeof(float)+sizeof(Time)); memcpy(time,buf+2 * sizeof(float),sizeof(Time)); *speed = values[0]; *turn = values[1]; } } // end namespace actuator } // end namespace flair