ControllerUnitTest Class Reference

Public Member Functions

 ControllerUnitTest ()
 
Mdouble f1 (Mdouble x2)
 
Mdouble f2 (Mdouble x1, Mdouble x2)
 
Mdouble RungeKutta (Mdouble x1, Mdouble x2, Mdouble dt)
 
Mdouble SpringMassControl ()
 

Private Attributes

Mdouble x1 =0.0
 
Mdouble x2 =0.0
 
Mdouble m =4
 
Mdouble c =10
 
Mdouble k =100.0
 
Mdouble t =0.0
 
Mdouble dt =0.01
 
Mdouble xDesire =5
 
Mdouble F =0.0
 
Mdouble x1Error =0.0
 

Constructor & Destructor Documentation

◆ ControllerUnitTest()

ControllerUnitTest::ControllerUnitTest ( )
inline
22  {
23  }

Member Function Documentation

◆ f1()

Mdouble ControllerUnitTest::f1 ( Mdouble  x2)
inline
27  {
28  Mdouble x1dot=x2;
29  return x1dot;
30  }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble x2
Definition: ControllerUnitTest.cpp:12

References x2.

Referenced by RungeKutta().

◆ f2()

Mdouble ControllerUnitTest::f2 ( Mdouble  x1,
Mdouble  x2 
)
inline
32  {
33  Mdouble x2dot=1/m*(F-c*x2-k*x1);
34  return x2dot;
35  }
Mdouble m
Definition: ControllerUnitTest.cpp:13
Mdouble F
Definition: ControllerUnitTest.cpp:19
Mdouble c
Definition: ControllerUnitTest.cpp:14
Mdouble x1
Definition: ControllerUnitTest.cpp:11
Mdouble k
Definition: ControllerUnitTest.cpp:15

References c, F, k, m, x1, and x2.

Referenced by RungeKutta().

◆ RungeKutta()

Mdouble ControllerUnitTest::RungeKutta ( Mdouble  x1,
Mdouble  x2,
Mdouble  dt 
)
inline
37  {
38  PIController xx(0.1,0.05);
39  for (int i=0;i<200/dt;i++) {
40  Mdouble k11 = dt*f1(x2);
41  Mdouble k21 = dt*f2(x1,x2);
42  Mdouble k12 = dt*f1(x2+0.5*k21);
43  Mdouble k22 = dt*f2(x1+0.5*k11,x2+0.5*k21);
44  Mdouble k13 = dt*f1(x2+0.5*k22);
45  Mdouble k23 = dt*f2(x1+0.5*k12,x2+0.5*k22);
46  Mdouble k14 = dt*f1(x2+k23);
47  Mdouble k24 = dt*f2(x1+k13,x2+k23);
48  x1 = x1+(k11+2*k12+2*k13+k14)/6;
49  x2 = x2+(k21+2*k22+2*k23+k24)/6;
50  t =t+ dt;
51  x1Error=-(x1-xDesire);
52  F = xx.apply(x1Error,dt); // Controller Command
53  }
54  return x1Error;
55  }
Mdouble t
Definition: ControllerUnitTest.cpp:16
Mdouble xDesire
Definition: ControllerUnitTest.cpp:18
Mdouble dt
Definition: ControllerUnitTest.cpp:17
Mdouble x1Error
Definition: ControllerUnitTest.cpp:20
Mdouble f2(Mdouble x1, Mdouble x2)
Definition: ControllerUnitTest.cpp:32
Mdouble f1(Mdouble x2)
Definition: ControllerUnitTest.cpp:27
Definition: PIController.h:9
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References PIController::apply(), dt, F, f1(), f2(), constants::i, t, x1, x1Error, x2, and xDesire.

Referenced by SpringMassControl().

◆ SpringMassControl()

Mdouble ControllerUnitTest::SpringMassControl ( )
inline
57  {
58  Mdouble Err=RungeKutta(x1,x2,dt);
59  return Err;
60  }
Mdouble RungeKutta(Mdouble x1, Mdouble x2, Mdouble dt)
Definition: ControllerUnitTest.cpp:37

References dt, RungeKutta(), x1, and x2.

Referenced by main().

Member Data Documentation

◆ c

Mdouble ControllerUnitTest::c =10
private

Referenced by f2().

◆ dt

Mdouble ControllerUnitTest::dt =0.01
private

Referenced by RungeKutta(), and SpringMassControl().

◆ F

Mdouble ControllerUnitTest::F =0.0
private

Referenced by f2(), and RungeKutta().

◆ k

Mdouble ControllerUnitTest::k =100.0
private

Referenced by f2().

◆ m

Mdouble ControllerUnitTest::m =4
private

Referenced by f2().

◆ t

Mdouble ControllerUnitTest::t =0.0
private

Referenced by RungeKutta().

◆ x1

Mdouble ControllerUnitTest::x1 =0.0
private

Referenced by f2(), RungeKutta(), and SpringMassControl().

◆ x1Error

Mdouble ControllerUnitTest::x1Error =0.0
private

Referenced by RungeKutta().

◆ x2

Mdouble ControllerUnitTest::x2 =0.0
private

Referenced by f1(), f2(), RungeKutta(), and SpringMassControl().

◆ xDesire

Mdouble ControllerUnitTest::xDesire =5
private

Referenced by RungeKutta().


The documentation for this class was generated from the following file: