source: flair-src/trunk/lib/FlairSensorActuator/src/SimuCamera.cpp@ 283

Last change on this file since 283 was 271, checked in by Sanahuja Guillaume, 6 years ago

warn for all nan/inf torques/thrust

File size: 2.4 KB
Line 
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: 2014/03/06
6// filename: SimuCamera.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class for a simulation camera
14//
15//
16/*********************************************************************/
17#ifdef CORE2_64
18
19#include "SimuCamera.h"
20#include <FrameworkManager.h>
21#include <GroupBox.h>
22#include <SharedMem.h>
23#include <sstream>
24
25using std::string;
26using std::ostringstream;
27using namespace flair::core;
28using namespace flair::gui;
29
30namespace flair {
31namespace sensor {
32
33SimuCamera::SimuCamera(string name,
34 uint16_t width, uint16_t height, uint8_t channels,
35 uint32_t modelId,uint32_t deviceId, uint8_t priority)
36 : Thread(getFrameworkManager(), name, priority),
37 Camera(name, width, height, cvimage::Type::Format::BGR) {
38
39 buf_size = width * height * channels+sizeof(Time);
40
41 shmemReadBuf=(char*)malloc(buf_size);
42 output->img->imageData = shmemReadBuf;
43
44 ostringstream dev_name;
45 dev_name << "simu" << modelId << "_cam_" << deviceId;
46 shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer);
47
48 SetIsReady(true);
49}
50
51
52SimuCamera::~SimuCamera() {
53 SafeStop();
54 Join();
55 if(shmemReadBuf!=NULL) delete shmemReadBuf;
56}
57
58string SimuCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
59 ostringstream dev_name;
60 dev_name << "simu" << modelId << "_cam_" << deviceId;
61 return dev_name.str().c_str();
62}
63
64void SimuCamera::Run(void) {
65 Time time;
66
67// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
68 shmem->ReaderReady();
69
70 while (!ToBeStopped()) {
71// WaitPeriod();
72
73// if (data_rate->ValueChanged() == true) {
74// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
75// }
76
77 output->GetMutex();
78 //blocking read
79 if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par
80 // échange de pointeur sur
81 // double buffering
82
83 output->ReleaseMutex();
84 memcpy(&time, shmemReadBuf + buf_size - sizeof(Time), sizeof(Time));
85 output->SetDataTime(time);
86
87 ProcessUpdate(output);
88 } else {
89 output->ReleaseMutex();
90 //Thread::Warn("Read Timeout\n");
91 }
92 }
93}
94
95} // end namespace sensor
96} // end namespace flair
97
98#endif
Note: See TracBrowser for help on using the repository browser.