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

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

iadded isready to iodevice:
avoid problem of imu not ready in ardrone2

File size: 2.8 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
18#include "SimuCamera.h"
19#include <FrameworkManager.h>
20#include <GroupBox.h>
21#include <SharedMem.h>
22#include <sstream>
23
24using std::string;
25using std::ostringstream;
26using namespace flair::core;
27using namespace flair::gui;
28
29namespace flair {
30namespace sensor {
31
32//control part
33SimuCamera::SimuCamera(string name,
34 uint16_t width, uint16_t height, uint8_t channels,
35 uint32_t dev_id, 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_cam_" << dev_id;
46 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), buf_size, SharedMem::Type::producerConsumer);
47
48 SetIsReady(true);
49}
50
51//simulation part
52SimuCamera::SimuCamera(const IODevice *parent, string name, uint16_t width,
53 uint16_t height, uint8_t channels, uint32_t dev_id)
54 : Thread(parent, name, 0), Camera(parent,name) {
55
56 buf_size = width * height * channels+sizeof(Time);
57
58 ostringstream dev_name;
59 dev_name << "simu_cam_" << dev_id;
60 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
61 buf_size, SharedMem::Type::producerConsumer);
62 shmemReadBuf=NULL;
63
64 SetIsReady(true);
65}
66
67SimuCamera::~SimuCamera() {
68 SafeStop();
69 Join();
70 if(shmemReadBuf!=NULL) delete shmemReadBuf;
71}
72
73void SimuCamera::Run(void) {
74 Time time;
75// if (data_rate == NULL) {
76// Thread::Err("not applicable for simulation part.\n");
77// return;
78// }
79
80// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
81 shmem->ReaderReady();
82
83 while (!ToBeStopped()) {
84// WaitPeriod();
85
86// if (data_rate->ValueChanged() == true) {
87// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
88// }
89
90 output->GetMutex();
91 //blocking read
92 shmem->Read(shmemReadBuf, buf_size); // remplacer copie par
93 // échange de pointeur sur
94 // double buffering
95 output->ReleaseMutex();
96 memcpy(&time,shmemReadBuf+buf_size-sizeof(Time),sizeof(Time));
97 output->SetDataTime(time);
98
99 ProcessUpdate(output);
100 }
101}
102
103} // end namespace sensor
104} // end namespace flair
Note: See TracBrowser for help on using the repository browser.