// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2020/&2/09 // filename: SimulatedUgvControls.cpp // // author: Guillaume Sanahuja // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: Class for a simulation ugv controls // // /*********************************************************************/ #ifdef CORE2_64 #include "SimulatedUgvControls.h" #include #include #include #include #include using std::string; using std::ostringstream; using namespace flair::core; namespace flair { namespace actuator { SimulatedUgvControls::SimulatedUgvControls(const IODevice *parent,string name, uint32_t modelId,uint32_t deviceId) : UgvControls(parent,name) { shmem = new SharedMem((Thread *)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; } SetIsReady(true); } SimulatedUgvControls::~SimulatedUgvControls() { if(buf!=NULL) free(buf); } string SimulatedUgvControls::ShMemName(uint32_t modelId,uint32_t deviceId) { ostringstream dev_name; dev_name << "simu" << modelId << "_ugvcontrols_" << deviceId; return dev_name.str().c_str(); } void SimulatedUgvControls::SetControls(float speed,float turn) { float *values=(float*)buf; buf[0]=speed; buf[1]=turn; Time time=GetTime(); memcpy(buf+2 * sizeof(float),&time,sizeof(Time)); shmem->Write(buf, 2 * sizeof(float)+sizeof(Time)); // on prend une fois pour toute le mutex et on fait des accès directs output->GetMutex(); for (int i = 0; i < 2; i++) { output->SetValueNoMutex(i, 0, buf[i]); } output->ReleaseMutex(); } } // end namespace sensor } // end namespace flair #endif