1
/***************************************************************************
2
* Copyright (C) 2020 by Benoit ZERR *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
18
***************************************************************************/
20
* Modified 2020 by santiago González *
21
* santigoro@gmail.com *
28
#include "connector.h"
30
#include "itemlibrary.h"
33
static const char* Strain_properties[] = {
34
QT_TRANSLATE_NOOP("App::Property","Value Ohm")
37
Component *Strain::construct (QObject* parent, QString type, QString id)
39
return new Strain (parent, type, id);
42
LibraryItem* Strain::libraryItem()
44
return new LibraryItem(
45
tr( "Force Strain Gauge" ),
52
Strain::Strain (QObject* parent, QString type, QString id)
53
: VarResBase( parent, type, id )
56
Q_UNUSED( Strain_properties );
57
m_area = QRectF( -12,-20, 24, 24 );
61
m_dial->setMinimum(0);
62
m_dial->setMaximum(250);
63
setVal( 0 ); // start at 0 °C
68
void Strain::initialize()
70
//m_last_step = Simulator::self()->step();
71
//m_resist = sensorFunction (m_sense);
72
m_last_resist = m_resist;
73
m_new_resist = m_resist;
75
//setResist ( m_resist);
79
void Strain::updateStep()
81
if( !m_changed ) return;
82
/*m_step = Simulator::self()->step();
83
double t = (double) m_step/1e6;
84
double dt = t - m_t0_tau;
86
m_new_resist = sensorFunction (m_sense);
87
double dr = m_new_resist - m_last_resist;
88
m_resist = m_last_resist + dr * (1.0 -exp(-dt/m_tau));
91
setResist ( m_resist);*/
93
//qDebug() << "Strain::Strain" << m_res.res() << m_res.current()
94
// << m_ePinTst1->isConnected() << m_ePinTst2->isConnected() ;
95
//m_last_step = m_step;
97
double res = sensorFunction( m_value );
98
eResistor::setResSafe( res );
102
void Strain::senseChanged( int val ) // Called when dial is rotated
104
//qDebug() <<"Strain::senseChanged" << val;
105
//double sense = (double)(m_dial->value());
106
//sense = round(sense/(double)m_sense_step)*(double)m_sense_step;
107
//qDebug()<<"Strain::senseChanged dialValue sense"<<m_dial->value()<<sense;
109
//m_dialW.dial->setValue(m_sense);
110
//m_t0_tau = (double) (Simulator::self()->step())/1e6;
111
//m_last_resist = m_resist;
115
double Strain::sensorFunction( double sense )
118
m_k_long = 1+2.0*m_coef_poisson+m_cste_bridgman*(1-2*m_coef_poisson);
119
//qDebug() << "K = " << m_k_long;
120
m_k = m_k_long * (1 - m_coef_transverse);
121
m_section_body = m_h_body * m_w_body;
122
m_delta_r = m_r0*m_k*sense/(m_young_modulus*m_section_body);
123
m_delta_r_t = (m_alpha_r+m_k*(m_lambda_s - m_lambda_j)) * (m_temp - m_ref_temp) * m_r0;
124
r_sense = m_r0 + m_delta_r + m_delta_r_t;
128
void Strain::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget )
130
Component::paint( p, option, widget );
131
p->drawRect( -10,-20, 20, 24 );
132
p->fillRect(-8,-2, 4, 4, Qt::black );
133
p->fillRect( 8,-2,-4, 4, Qt::black );
135
QPen pen(Qt::black, 1.5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
138
const QPointF points[8] = {
148
p->drawPolyline( points, 8 );
151
#include "moc_strain.cpp"