source: flair-src/trunk/lib/FlairSimulator/src/SimuUgvControls.cpp@ 453

Last change on this file since 453 was 375, checked in by Sanahuja Guillaume, 4 years ago

update ugv

  • Property svn:eol-style set to native
File size: 1.8 KB
RevLine 
[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
22using std::string;
23using std::ostringstream;
24using namespace flair::core;
25
26namespace flair {
27namespace actuator {
28
29
30SimuUgvControls::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
52SimuUgvControls::~SimuUgvControls() {
53 if(buf!=NULL) free(buf);
54}
55
56string 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
63void 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
Note: See TracBrowser for help on using the repository browser.