close Warning: Can't use blame annotator:
svn blame failed on trunk/lib/FlairFilter/src/PidThrust_impl.cpp: 200029 - Couldn't perform atomic initialization

source: flair-src/trunk/lib/FlairFilter/src/PidThrust_impl.cpp@ 7

Last change on this file since 7 was 7, checked in by Sanahuja Guillaume, 8 years ago

filter and meta

File size: 3.5 KB
RevLine 
1// created: 2014/11/07
2// filename: PidThrust_impl.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: Class defining a PID
10//
11//
12/*********************************************************************/
13#include "PidThrust_impl.h"
14#include "PidThrust.h"
15#include <cvmatrix.h>
16#include <Layout.h>
17#include <GroupBox.h>
18#include <DoubleSpinBox.h>
19#include <DataPlot1D.h>
20
21using std::string;
22using namespace flair::core;
23using namespace flair::gui;
24using namespace flair::filter;
25
26PidThrust_impl::PidThrust_impl(PidThrust* self,const LayoutPosition* position,string name) {
27 i=0;
28 offset_g=0;
29 first_update=true;
30 this->self=self;
31
32 //init matrix
33 self->input=new cvmatrix(self,2,1,floatType,name);
34
35 cvmatrix_descriptor* desc=new cvmatrix_descriptor(5,1);
36 desc->SetElementName(0,0,"p");
37 desc->SetElementName(1,0,"i");
38 desc->SetElementName(2,0,"d");
39 desc->SetElementName(3,0,"p+i+d");
40 desc->SetElementName(4,0,"p+i+d+offset");
41 state=new cvmatrix(self,desc,floatType,name);
42
43 GroupBox* reglages_groupbox=new GroupBox(position,name);
44 T=new DoubleSpinBox(reglages_groupbox->NewRow(),"period, 0 for auto"," s",0,1,0.01);
45 kp=new DoubleSpinBox(reglages_groupbox->NewRow(),"kp:",0,90000000,0.01);
46 ki=new DoubleSpinBox(reglages_groupbox->NewRow(),"ki:",0,90000000,0.01);
47 sati=new DoubleSpinBox(reglages_groupbox->LastRowLastCol(),"sat i:",0,1,0.01);
48 kd=new DoubleSpinBox(reglages_groupbox->NewRow(),"kd:",0,90000000,0.01);
49 offset=new DoubleSpinBox(reglages_groupbox->LastRowLastCol(),"offset g:",0,1,0.01);
50 sat=new DoubleSpinBox(reglages_groupbox->NewRow(),"sat:",0,1,0.1);
51 pas_offset=new DoubleSpinBox(reglages_groupbox->LastRowLastCol(),"offset step:",0,1,.0001,4);
52}
53
54PidThrust_impl::~PidThrust_impl(void) {
55}
56
57void PidThrust_impl::UseDefaultPlot(const LayoutPosition* position)
58{
59 DataPlot1D *plot=new DataPlot1D(position,self->ObjectName(),-1,1);
60 plot->AddCurve(state->Element(0));
61 plot->AddCurve(state->Element(1),DataPlot::Green);
62 plot->AddCurve(state->Element(2),DataPlot::Blue);
63 plot->AddCurve(state->Element(3),DataPlot::Black);
64 plot->AddCurve(state->Element(4),DataPlot::Yellow);
65}
66
67void PidThrust_impl::UpdateFrom(const io_data *data)
68{
69 float p,d,total;
70 float delta_t;
71 cvmatrix *input=(cvmatrix*)data;
72
73 if(T->Value()==0)
74 {
75 delta_t=(float)(data->DataTime()-previous_time)/1000000000.;
76 }
77 else
78 {
79 delta_t=T->Value();
80 }
81 if(first_update==true)
82 {
83 delta_t=0;
84 first_update=false;
85 }
86
87 input->GetMutex();
88 p=kp->Value()*input->ValueNoMutex(0,0);
89 i+=ki->Value()*input->ValueNoMutex(0,0)*delta_t;
90 if(i>sati->Value()) i=sati->Value();
91 if(i<-sati->Value()) i=-sati->Value();
92 d=kd->Value()*input->ValueNoMutex(1,0);
93 input->ReleaseMutex();
94
95 total=p+i+d;
96 if(total>sat->Value()) total=sat->Value();
97 if(total<-sat->Value()) total=-sat->Value();
98
99 state->GetMutex();
100 state->SetValueNoMutex(0,0,p);
101 state->SetValueNoMutex(1,0,i);
102 state->SetValueNoMutex(2,0,d);
103 state->SetValueNoMutex(3,0,total);
104 state->SetValueNoMutex(4,0,total-offset_g*offset_g);
105 state->ReleaseMutex();
106
107 //-offset_g, car on met -u_z dans le multiplex
108 //a revoir!
109 self->output->SetValue(0,0,total-offset_g*offset_g);
110 self->output->SetDataTime(data->DataTime());
111
112 previous_time=data->DataTime();
113}
Note: See TracBrowser for help on using the repository browser.