test

Committer:
o2132613
Date:
Wed Mar 11 09:06:24 2020 +0000
Revision:
13:7a12ba8a93d4
Parent:
11:acbbd742df47
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MazeTaka 0:eb20667a5a27 1 #include "mbed.h"
MazeTaka 0:eb20667a5a27 2 #include "EC.h"
MazeTaka 0:eb20667a5a27 3
MazeTaka 0:eb20667a5a27 4
MazeTaka 0:eb20667a5a27 5 Ec::Ec(int res,int multi):
MazeTaka 0:eb20667a5a27 6 count_(0),pre_count_(0),resolution_(res),multiplication_(multi)
MazeTaka 0:eb20667a5a27 7 {
MazeTaka 0:eb20667a5a27 8 timer_.start();
MazeTaka 0:eb20667a5a27 9 }
MazeTaka 0:eb20667a5a27 10
MazeTaka 8:17aff8f21d19 11 int Ec::getCount()const
MazeTaka 0:eb20667a5a27 12 {
MazeTaka 0:eb20667a5a27 13 return count_;
MazeTaka 0:eb20667a5a27 14 }
MazeTaka 0:eb20667a5a27 15
MazeTaka 11:acbbd742df47 16 double Ec::getRad()const
MazeTaka 10:ad0f13db7b92 17 {
MazeTaka 10:ad0f13db7b92 18 return count_*2.0f*M_PI/(multiplication_*resolution_);
MazeTaka 10:ad0f13db7b92 19 }
MazeTaka 10:ad0f13db7b92 20
MazeTaka 0:eb20667a5a27 21 void Ec::calOmega()
MazeTaka 0:eb20667a5a27 22 {
MazeTaka 0:eb20667a5a27 23 double t=timer_.read();
MazeTaka 0:eb20667a5a27 24 omega_=(count_-pre_count_)*2.0f*M_PI/(multiplication_*resolution_*(t-ptw_));
MazeTaka 0:eb20667a5a27 25 pre_count_=count_;
MazeTaka 0:eb20667a5a27 26 ptw_=t;
MazeTaka 0:eb20667a5a27 27 }
MazeTaka 0:eb20667a5a27 28
MazeTaka 8:17aff8f21d19 29 double Ec::getOmega()const
MazeTaka 0:eb20667a5a27 30 {
MazeTaka 0:eb20667a5a27 31 return omega_;
MazeTaka 0:eb20667a5a27 32 }
MazeTaka 10:ad0f13db7b92 33 void Ec::setResolution(int res)
MazeTaka 10:ad0f13db7b92 34 {
MazeTaka 0:eb20667a5a27 35 resolution_=res;
MazeTaka 0:eb20667a5a27 36 }
MazeTaka 0:eb20667a5a27 37
MazeTaka 0:eb20667a5a27 38 /*reset関数の定義*/
MazeTaka 0:eb20667a5a27 39 /*エンコーダを初期状態に戻すことができる*/
MazeTaka 0:eb20667a5a27 40 void Ec::reset()
MazeTaka 0:eb20667a5a27 41 {
MazeTaka 0:eb20667a5a27 42 count_=0;
MazeTaka 0:eb20667a5a27 43 pre_count_=0,omega_=0;
MazeTaka 0:eb20667a5a27 44 ptw_=0;
MazeTaka 1:b7e957c01761 45 timer_.stop();
MazeTaka 1:b7e957c01761 46 timer_.reset();
MazeTaka 1:b7e957c01761 47 timer_.start();
MazeTaka 0:eb20667a5a27 48 }
MazeTaka 0:eb20667a5a27 49
MazeTaka 0:eb20667a5a27 50
MazeTaka 0:eb20667a5a27 51 ////////////////////////////////////////////////////1逓倍//////////////////////////////////////////////////////////////////
MazeTaka 0:eb20667a5a27 52 Ec1multi::Ec1multi(PinName signalA,PinName signalB,int res) : Ec(res,1),signalA_(signalA),signalB_(signalB)
MazeTaka 0:eb20667a5a27 53 {
o2132613 13:7a12ba8a93d4 54 signalA_.rise(this,&Ec1multi::upA);
MazeTaka 0:eb20667a5a27 55 }
MazeTaka 0:eb20667a5a27 56
MazeTaka 0:eb20667a5a27 57 //ピン変化割り込み関数の定義
MazeTaka 0:eb20667a5a27 58 void Ec1multi::upA()
MazeTaka 0:eb20667a5a27 59 {
MazeTaka 0:eb20667a5a27 60 if(signalB_.read())count_++;
MazeTaka 0:eb20667a5a27 61 else count_--;
MazeTaka 0:eb20667a5a27 62 }
MazeTaka 0:eb20667a5a27 63 ////////////////////////////////////////////////////2逓倍//////////////////////////////////////////////////////////////////
MazeTaka 0:eb20667a5a27 64 Ec2multi::Ec2multi(PinName signalA,PinName signalB,int res) : Ec(res,2),signalA_(signalA),signalB_(signalB)
MazeTaka 0:eb20667a5a27 65 {
o2132613 13:7a12ba8a93d4 66 signalA_.rise(this,&Ec2multi::upA);
o2132613 13:7a12ba8a93d4 67 signalA_.fall(this,&Ec2multi::downA);
MazeTaka 0:eb20667a5a27 68 }
MazeTaka 0:eb20667a5a27 69
MazeTaka 0:eb20667a5a27 70 //ピン変化割り込み関数の定義
MazeTaka 0:eb20667a5a27 71 void Ec2multi::upA()
MazeTaka 0:eb20667a5a27 72 {
MazeTaka 0:eb20667a5a27 73 if(signalB_.read())count_++;
MazeTaka 0:eb20667a5a27 74 else count_--;
MazeTaka 0:eb20667a5a27 75 }
MazeTaka 0:eb20667a5a27 76 void Ec2multi::downA()
MazeTaka 0:eb20667a5a27 77 {
MazeTaka 0:eb20667a5a27 78 if(signalB_.read())count_--;
MazeTaka 0:eb20667a5a27 79 else count_++;
MazeTaka 0:eb20667a5a27 80 }
MazeTaka 0:eb20667a5a27 81
MazeTaka 0:eb20667a5a27 82 ////////////////////////////////////////////////////4逓倍//////////////////////////////////////////////////////////////////
MazeTaka 0:eb20667a5a27 83 Ec4multi::Ec4multi(PinName signalA,PinName signalB,int res) : Ec(res,4),signalA_(signalA),signalB_(signalB),pa_(0),pb_(0)
MazeTaka 0:eb20667a5a27 84 {
o2132613 13:7a12ba8a93d4 85 signalA_.rise(this,&Ec4multi::upA);
o2132613 13:7a12ba8a93d4 86 signalA_.fall(this,&Ec4multi::downA);
o2132613 13:7a12ba8a93d4 87 signalB_.rise(this,&Ec4multi::upB);
o2132613 13:7a12ba8a93d4 88 signalB_.fall(this,&Ec4multi::downB);
MazeTaka 0:eb20667a5a27 89 }
MazeTaka 0:eb20667a5a27 90 void Ec4multi::upA()
MazeTaka 0:eb20667a5a27 91 {
MazeTaka 0:eb20667a5a27 92 pa_=1;
MazeTaka 0:eb20667a5a27 93 if(pb_==1)count_++;
MazeTaka 0:eb20667a5a27 94 else count_--;
MazeTaka 0:eb20667a5a27 95 }
MazeTaka 0:eb20667a5a27 96 void Ec4multi::downA()
MazeTaka 0:eb20667a5a27 97 {
MazeTaka 0:eb20667a5a27 98 pa_=0;
MazeTaka 0:eb20667a5a27 99 if(pb_==1)count_--;
MazeTaka 0:eb20667a5a27 100 else count_++;
MazeTaka 0:eb20667a5a27 101 }
MazeTaka 0:eb20667a5a27 102 void Ec4multi::upB()
MazeTaka 0:eb20667a5a27 103 {
MazeTaka 0:eb20667a5a27 104 pb_=1;
MazeTaka 0:eb20667a5a27 105 if(pa_==1)count_--;
MazeTaka 0:eb20667a5a27 106 else count_++;
MazeTaka 0:eb20667a5a27 107 }
MazeTaka 0:eb20667a5a27 108 void Ec4multi::downB()
MazeTaka 0:eb20667a5a27 109 {
MazeTaka 0:eb20667a5a27 110 pb_=0;
MazeTaka 0:eb20667a5a27 111 if(pa_==1)count_++;
MazeTaka 0:eb20667a5a27 112 else count_--;
MazeTaka 0:eb20667a5a27 113 }